How to share data between different WSL instancesΒΆ
https://stackoverflow.com/questions/65815011/moving-files-between-different-wsl2-instances
- Create shared directory which is not included in any WSL instances
This will create /mnt/wsl/share directory shared across all WSL instances. You can share data via this shared directory.
WARNING: the shared directory's filesystem lives in memory and thus a wsl.exe --shutdown would wipe them from existence.
However, it is still impossible to directly copy/paste data between WSL instances.
- Create shared directory included in a WSL instance
You can make existing directory in WSL instance shared across other WSL instances by using bind mount.
For example, you have two WSL instances, Ubuntu-A and Ubuntu-B.
- Open
~/.profilein Ubuntu-A and add below code.
# bind mount shared directory
if [ ! -d /mnt/wsl/share-a ]; then
mkdir /mnt/wsl/share-a
wsl.exe -d Ubuntu-A -u root mount --bind / /mnt/wsl/share-a/
fi
- Open
~/.profilein Ubuntu-B and add below code.
# bind mount shared directory
if [ ! -d /mnt/wsl/share-b ]; then
mkdir /mnt/wsl/share-b
wsl.exe -d Ubuntu-B -u root mount --bind / /mnt/wsl/share-b/
fi
This will automatically mount the root directory (/) of Ubuntu-A to /mnt/wsl/shared-a/ and do the same thing for Ubuntu-B when you launch WSL.