2

I want to chroot into my Kali Linux WSL from my Ubuntu WSL. I'm running WSL2. In Windows, I mapped my Kali Linux WSL installation (\\wsl$\kali-linux) to the drive K:. In Ubuntu WSL, I mounted the K: drive to /mnt/k bu running sudo mount -t drvfs K: /mnt/k. It was mounted successfully, but I can't chroot into /mnt/k. It seems that there is a problem with symbolic links. When I try to run chroot /mnt/k, I get the following error:

chroot: failed to run command ‘/bin/bash’: Function not implemented

I get a similar error with ls when I run ls /mnt/k:

ls: cannot read symbolic link '/mnt/k/bin': Function not implemented
ls: cannot read symbolic link '/mnt/k/lib': Function not implemented
ls: cannot read symbolic link '/mnt/k/lib32': Function not implemented
ls: cannot read symbolic link '/mnt/k/lib64': Function not implemented
ls: cannot read symbolic link '/mnt/k/libx32': Function not implemented
ls: cannot read symbolic link '/mnt/k/sbin': Function not implemented

I can't cd into any of the symbolic link directories in /mnt/k either. How can I achieve chrooting into my Kali Linux WSL install?

0

1 Answer 1

0

What's not working

Let's start with summarizing what you are attempting:

  1. Take a Kali ext4 filesystem
  2. Share that via the 9p protocol (WSL2 does this for you automatically)
  3. Connect to it from Windows (again, WSL2 does this for you automatically)
  4. Map a Windows drive letter to that network drive
  5. Mount that drive in Ubuntu via 9p/drvfs
  6. chroot into that mount point

The main problem occurs early in the process, at step #3 (perhaps even #2). At this point, since Windows doesn't understand Linux symlinks, as you've noticed, these are just turned into files.

Attempting to then turn around and mount this drive back into another WSL instances doesn't turn these back into links.

How to get it running

At least one method is to use the /mnt/wsl cross-distro mount point.

From Kali:

sudo mount --bind / /mnt/wsl/kali -o "X-mount.mkdir"

If you'd like for the mount to be done automatically each time you restart Kali, then:

sudo sh -c "grep '/mnt/wsl/kali' /proc/mounts >> /etc/fstab"

Then vi /etc/fstab and add the option X-mount.mkdir to the mount.

From Ubuntu:

chroot /mnt/wsl/kali
mount -t proc proc /proc

Note that there are a few WSL things that won't "work" without additional effort inside the chroot:

  • The Windows Path will not automatically be appended to the Linux PATH (solvable via some env magic and other techniques)
  • Windows drives will not automatically be mounted at, for example, /mnt/c, etc. (solvable via /etc/fstab from within Ubuntu to mount the drives into the Kali fs).
  • Even if the drive is mounted, running a Windows .exe won't work (solvable by bind mounting the Interop socket location from Ubuntu to the Kali fs)
  • On Windows 11, WSLg will not work (Solvable by bind mounting the WSLg/X11 socket from Ubuntu to Kali)

See another one of my answer's on Ask Ubuntu which cover a couple of these solutions (Interop and WSLg). I've actually solved the problem with mounting Windows drives as well, but I haven't had a chance to update the info there yet.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .