-
Ubuntu WSL2 must be already installed in C: system drive and user should be able to call windows binaries like
wsl.exefrom bash. -
We will install Alpine WSL2 distro in an external partition/disk:
-
Download Alpine.zip from here: https://github.com/yuk7/AlpineWSL/releases/
-
Extract the files in an external partition/disk. (for example D:\Alpine)
-
Make sure WSL2 is enabled by default (
wsl.exe --set-default-version 2) -
Inside the Alpine folder run
Alpine.exeto install the Distro. Anext4.vhdxfile will be created in that same folder. -
Run
Alpine.exeagain. -
Now from the Alpine terminal we will create same user as Ubuntu. This will create the
/home/onomafolder.adduser onoma
-
-
On Ubuntu edit the
~/.profilefile and add:
# mount external /home folder from Alpine distro
if [ ! -d /mnt/wsl/Alpine ]; then
mkdir /mnt/wsl/Alpine
wsl.exe -d Alpine -u root mount --bind /home/onoma /mnt/wsl/Alpine/
fi
-
We will close the VM with:
wsl.exe --shutdown -
Next time Ubuntu distro is launched it will automount the
/home/onomafolder from Alpine distro to/mnt/wsl/Alpinein Ubuntu with all the benefits and speed of ext4 mounted folders.
WSL2 runs a single lightweight VM that supports multiple distros running on the same Linux kernel.
Every time a distro is launched, its vhdx file is attached automatically to the VM as a /dev/sdc device.
Thanks to the nature of WSL interop we can launch another distro and inmediately close it from inside bash.
The folder /mnt/wsl is an undocumented WSL2 feature which is a tmpfs special folder used by applications as Docker for Desktop.
Everything mounted in that folder will also appear in every running distro under /mnt/wsl/. Just make sure you have file permissions to
access that directory. In my case I'm using user "onoma" on both Ubuntu and Alpine.


I see. I think you are mixing both methods and you can't do that. The other method doesn't create a real vhdx but just a file formatted in ext4. The problem with that method is that the file has a fixed size and you won't be able to use more space than that.
The method of this thread uses a small external distro (Alpine is just 64Mb in size) with its real vhdx file. That vhdx file is a dynamic vdisk that can grow until 256Gb in size. Right now is not possible to attach directly a vhdx file to WSL2 so this is the method used by professional solutions as Docker.
The mount directory needs to be a directory inside
/mnt/wslsince it's a special tmpfs mount. Every mount point you create there will disappear after shutting down the WSL2 VM. That's why the script lines in step 3 create a directory (if it wasn't created before) inside/mnt/wslbefore mounting the Alpine vhdx at launch.If you want to try this method, first you should shutdown the WSL2 VM with
wsl.exe --shutdown.If you exactly follow the steps of this thread with the same directory names it should work. Then you only need to cd to
/mnt/wsl/Alpine/and clone the SVN repositories there.