Note: this is an older post transferred across here.
If you are are a regular user of the cross-distro mounts feature in WSL 2, you may have noticed that after updating to Windows Insider build 19018, the root filesystems of distros for which you have enabled the feature (with crossDistro = true in your /etc/wsl.conf) are no longer automatically mounted. /mnt/wsl just sits empty.
Surprise and terror!
Or not, because this is not a bug; it’s a change to the way the feature works. (See issue 4654 .) To summarize, the /mnt/wsl filesystem is now a shared space, mounts within which will be automatically shared between all distros.
So if you depended upon the old behavior, and want that back quick and easy, here’s how. Create the following shell script as share-distro-fs in your /usr/local/bin, chown it root:root, and make it suid:
#! /bin/bash
# If mount point directory does not exist, create it.
if [ ! -d "/mnt/wsl/$WSL_DISTRO_NAME" ]; then
mkdir "/mnt/wsl/$WSL_DISTRO_NAME"
fi
# If mount point directory is not mounted upon, bind mount fs.
if ! mountpoint -q -- "/mnt/wsl/$WSL_DISTRO_NAME"; then
mount --bind / "/mnt/wsl/$WSL_DISTRO_NAME"
fi
Now you can call that from your startup script when you log in, and there you go, instant cross-distro mount. As you can see, it checks to make sure that it doesn’t remount already the fs if it’s already mounted, so you can go right ahead and add it to your .profile, etc., without worry.
For those of us, the few, the proud, the genie/systemd users, you can instead add this systemd unit as share-distro-fs.service in /etc/systemd/system, then systemctl daemon-reload, systemctl enable share-distro-fs and systemctl start share-distro-fs, and have the fs automatically be shared when the system comes up, rather than when your shell starts.
[Unit]
Description=Cross-distro sharing of this distro filesystem
[Service]
Type=oneshot
ExecStart=/usr/local/bin/share-distro-fs
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
Hope this proves useful to those of you doing cross-distro things!