Open laggarcia opened 2 years ago
I have a much more simple test case now that hits the same issue. Just create a directory inside your user profile directory in Windows and put the following on your /etc/fstab
:
# cat /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults 0 0
C:\ /mnt/c drvfs noatime,uid=1000,gid=1000,metadata 0 0
/mnt/c/Users/lagga/linux-home-dir /home/laggarcia none bind 0 0
When WSL instance starts, your homedir will not be bind mounted. You will have to run mount -a
to mount it properly.
use the windows store version of WSL
Having the ability to keep your home directory as a separate VHD would be really useful for the often many times I need to trash and recreate my development environment distro. It also has the added benefit of being able to be used by multiple distros.
The main issue is that there is no support in WSL 2 for automounting a VHD on distro startup. We have wsl --mount --vhd
now but that does not get around the issues described above.
Version
Microsoft Windows [Version 10.0.22000.527]
WSL Version
Kernel Version
5.10.60.1
Distro Version
Ubuntu 20.04
Other Software
N/A
Repro Steps
I would like to mount my homedir inside WSL from a separate virtual disk. Hence, I performed the following steps:
I used Hyper-V manager to create a new vhdx file at
C:\Users\<username>\home.vdhx
.In an Administrator PowerShell which started with the working directory in my user profile directory (i.e.
C:\Users\<username>
), I mounted the new vhdx file as a drive:Mount-VHD -Path .\home.vhdx
After doing that, the vhdx file will appear as a physical driver:
wsl --mount \\.\PHYSICALDRIVE1 --bare
Start my WSL distribution.
In Linux, a new device will appear:
The vhdx file is mapped to
sdc
./dev/sdc
:mkfs.btrfs -L home /dev/sdc
I verified that I can properly mount
/dev/sdc
. I also created a btrfs subvolume for my homedir called laggarcia.Used
blkid
to find/dev/sdc
UUID.Added a line to mount the UUID on my homedir in Linux in
/etc/fstab
:Verified that
mount -a
properly mount my homedir.Shutdown WSL with
wsl --shutdown
.Mounted the vhdx physical drive in WSL again (repeat step 3).
Start WSL instance.
When the prompt appears, I am not seeing the files inside my vhdx file. I have no errors in
dmesg
. As a matter of fact, it states that it correctly identified/dev/sdc
.However, if I run
mount -a
just after starting the WSL instance, my homedir will become the one inside the vhdx file.Expected Behavior
I would expect that the homedir from the vhdx file should be correctly automount during WSL instance boot.
Actual Behavior
Homedir is not correctly automounted.
Diagnostic Logs