I am in a position where I need to access a drive from WSL. Unfortunately, I need to format it with a specific filesystem (ext4) on WSL since windows doesn't support that filesystem. As a result, I need to be able to have a device file to reference when formatting the disk on WSL. While I can mount a drive to a folder using sudo mount -t drvfs e: /mnt/edrive, I cannot seem to find any information about how to create a device file for a drive mounted in Windows. Is there any way that I can create a device file in WSL that references a drive mounted in Windows?
3 Answers
If I understand you correctly, it sounds like you are looking for a new feature that is coming in WSL, but is currently only available in Windows Insider/Preview. Don't let the fact that the command is named --mount confuse the issue (although it certainly is confusing). At least the way I read the doc (I'm not using Preview), this can create a block device in WSL from a raw, unformatted drive connected in Windows.
- 28,025
The simplest way is to attach your device, e.g. a USB-disk which appears as E:, to your Windows system and reboot.
Then restart wsl2 (WindowsTerm->Debian or whatever) and you will now see a new /mnt/e magically created for you :-)
Then use the command sudo mount -t drvfs E: /mnt/e you show above to mount that disk as a normal unix mountpoint.
- 2,159
- 101
Had a similar issue with an external HD disk with ext4 format:
I did:
Connect HD and on powershell attach with wsl:
PS C:\Users\Diaz> wmic diskdrive list brief
Caption DeviceID Model Partitions Size
SAMSUNG MZVLB512HBJQ-000L7 \\.\PHYSICALDRIVE0 SAMSUNG MZVLB512HBJQ-000L7 3 512105932800
BUFFALO HD-PCTU3 USB Device \\.\PHYSICALDRIVE1 BUFFALO HD-PCTU3 USB Device 0 1000202273280
PS C:\Users\Diaz> wsl --mount \.\PHYSICALDRIVE1
The disk was attached but failed to mount: No such device.
For more details, run 'dmesg' inside WSL2.
To detach the disk, run 'wsl.exe --unmount \.\PHYSICALDRIVE1'.
PS C:\Users\Diaz>
Then on a running WSL (mine is Ubuntu):
/mnt » lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 469.3M 1 loop /mnt/wsl/docker-desktop/cli-tools
loop1 7:1 0 152M 1 loop
loop2 7:2 0 419.3M 1 loop
sda 8:0 0 388.6M 1 disk
sdb 8:16 0 4G 0 disk [SWAP]
sdc 8:32 0 1T 0 disk /snap
/mnt/wslg/distro
/
sdd 8:48 0 1T 0 disk /mnt/wsl/docker-desktop/docker-desktop-user-distro
sde 8:64 0 931.5G 0 disk
sdf 8:80 0 1T 0 disk
sdg 8:96 0 1T 0 disk
/mnt »
I'd like to mount sde then:
~ » cd /mnt
/mnt » sudo mkdir buffalo
And mount it:
/mnt » sudo mount /dev/sde /mnt/buffalo
/mnt » cd /mnt/buffalo
/mnt/buffalo » ls -lrt
total 64
drwxrwxrwx 1 root root 4096 Jan 4 2018 32gb
drwxrwxrwx 1 root root 4096 May 22 2020 pics
drwxrwxrwx 1 root root 57344 Jan 21 2021 maveric
/mnt/buffalo »