Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Accessing Ubuntu WSL files from Kali WSL and vice versa

Writer Olivia Zamora

I have 2 wsl distros running on my pc, Ubuntu and Kali Linux. I have some programs installed and some files on my kali linux system that I want to access or edit through the Ubuntu distro. How can I do it? Are the files located somewhere in the file system that I can access through Ubuntu?

Thank You! Any help is appreciated.

6

2 Answers

It's a bit odd:

Accessing WSL files from Windows is easy and built-in to WSL -- Just use the \\wsl$\<distro> drive share.

Accessing Windows files from WSL is also easy -- Just use the /mnt/<drive_letter> mount points.

Accessing files in one WSL instance from another isn't "built in", but can be accomplished through the use of bind mounts in each distro to the shared /mnt/wsl tmpfs mount.

Just execute the following command in both Ubuntu and Kali:

sudo sh -c "echo \"/ /mnt/wsl/instances/$WSL_DISTRO_NAME none defaults,bind,X-mount.mkdir 0 0\" >> /etc/fstab"

Then exit each, issue a wsl --shutdown from PowerShell or CMD (a --terminate of each would suffice as well), and restart.

You'll find the files for each now in their respective /mnt/wsl/instances/<distroname> bind mount.

This works by creating an /etc/fstab entry that creates a bind mount using the distribution name in /mnt/wsl/instances/$WSL_DISTRO_NAME when the instance is started. the X-mount.mkdir allows mount to create the parent directories needed if they don't exist, similar to mkdir -p.

The /mnt/wsl directory is a tmpfs that is automatically:

  • Created by WSL when it first starts

  • Available to all WSL2 distributions

  • Note that this does not work for WSL1 distributions

  • Also note that this method requires both distributions to be running. For some methods that don't require the second distro to be running, see my older methods in this Super User answer. Options 2 and 3 will both work even if the second distro isn't running.

5

Adding to @NotTheDr01d's answer, I need to take into consideration that a different automount root might be defined in /etc/wsl.conf. In my case, I set it to /, so /mnt/c is actually /c, and /mnt/wsl is /wsl.

To make the method @NotTheDr01d's mentions compatible with any custom automount point, you can use the following:

# determine mountpoint
MNT_WSL=$(awk '/\/wsl tmpfs/{print $2}' /proc/mounts)
# config fstab
grep "${MNT_WSL}/${WSL_DISTRO_NAME}" /etc/fstab || echo "/ ${MNT_WSL}/${WSL_DISTRO_NAME} none defaults,bind,X-mount.mkdir 0 0" | sudo tee -a /etc/fstab
# mount for current instance
sudo mount ${MNT_WSL}/${WSL_DISTRO_NAME}
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy