microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.34k stars 814 forks source link

The mounted Disk disappear everytime I restart WSL2. Is this featrue or bug? #8301

Closed zouherenjie closed 2 years ago

zouherenjie commented 2 years ago

Version

10.0.22000.613

WSL Version

Kernel Version

Linux version 5.10.102.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Mar 2 00:30:59 UTC 2022

Distro Version

Ubuntu 20.04

Other Software

No response

Repro Steps

I mount my disk as follows, and it worked well as long as I don't restart WSL2. Did I do something wrong?

  1. mount the disk barely in powershell wsl --mount --bare
  2. build a new partition with ext4 filesystem in WSL2 mkfs.ext4 /dev/sdf
  3. mount /dev/sdf /app

Expected Behavior

The disk should be mounted as same as I

Actual Behavior

Everytime I restart WSL2, I cannot find my disk in WSL2 with cmds like lsblk blkid fdisk -l dmesg.txt

Diagnostic Logs

No response

elsaco commented 2 years ago

@zouherenjie those are temporary mounts, won't survive reboots, indeed. Make your mount permanent by adding the partition(s) to /etc/fstab. Here's a link with more information: https://devblogs.microsoft.com/commandline/automatically-configuring-wsl/

RobertSpir commented 2 years ago

it's a feature, I'm using bat file to launch wsl instance in windows terminal with mounted vhd disk, the advantage of this approach is that I can run wsl with different mounted disks

wt.exe -p "Name_of_wsl_profile_in_windows_terminal"
wsl --mount ...
zouherenjie commented 2 years ago

@elsaco @RobertSpir Does this mean I still have to mount the disk to WSL2 manually before I start WSL2?

But may vary each time like /dev/sde or /dev/sdf when I use Docker Desktop. It's hard to control the boot priority. Any solutions?

RobertSpir commented 2 years ago

maybe use timeout /t 10 command in-between the launch and mount commands to wait, so the extra disk will be mounted later