In theory (I haven't tried it yet), ifIf you are using Systemd, you couldcan also create a .mount
with the proper dependency in placefile to workaround the issue.
Option 2: A bind mount in /mnt/wsl
Older version of Option 1, left here for posterity. Note that this will work even if the second distribution isn't running yet. Option 1 requires that the distro be running in advance for it to be available in /mnt/wsl
.
Adapted from this GitHub comment, you should be able to do:
mkdir /mnt/wsl/otherinstance
wsl.exe -d otherinstance -u root mount --bind / /mnt/wsl/otherinstance/
Honestly, this one scares me a little bit, because the "otherinstance" shuts down soon after the command is run (unless it was already running elsewhere). However, the mount seems stable, probably because (as later comments in that GitHub issue mention) all of the "drives" are available from the WSL2/Hyper-V subsystem anyway; they aren't necessarily dependent on the instance itself.
Regardless, it would be easy to allay my (probably unfounded) fears by simply running the "otherinstance" manually and performing the See mount --bind
from that instance itself@SteveMeierhofer's answer for details.
Option 32: Use wsl.exe
's stdin/stdout
(Bonus #1: This methodsmethod works on WSL1 as well)
(Bonus #2: It requires no advance configuration)
(Bonus #3: It will work even if the second distribution isn't running yet. Option 1 requires that the distro be running in advance for it to be available in /mnt/wsl
.)
Option 43: ssh
Note that setting up ssh
on WSL instances isn't all that straightforward, but it's probably easier if you are only accessibleaccessing it via localhost. At the least, you'll need a separate port number for each instance. I recommend reserving 22 for the Windows host itself (potentially using the Windows OpenSSH Server).
Option 4: A bind mount in /mnt/wsl
Also note that there's no conceptOlder version of anOption 1, left here for posterity.
Adapted from init
script that runs at startup in WSLthis GitHub comment, nor any Systemd equivalentyou should be able to do:
mkdir /mnt/wsl/otherinstance
wsl.exe -d otherinstance -u root mount --bind / /mnt/wsl/otherinstance/
Honestly, this one scares me a little bit, because the "otherinstance" shuts down soon after the command is run (unless it was already running elsewhere). So you'll need However, the mount seems stable, probably because (as later comments in that GitHub issue mention) all of the "drives" are available from the WSL2/Hyper-V subsystem anyway; they aren't necessarily dependent on the instance itself.
Regardless, it would be easy to startallay my (probably unfounded) fears by simply running the "otherinstance" manually and performing the sshmount --bind
server for eachfrom that instance manually, or find some other methoditself.