How to mount an USB disk to a fix drive in Linux subsystem for Windows?
I'm working on Windows-10, where I have installed Linux subsystem for Windows (more exactly a Ubuntu).
I have mapped my USB drive on the D:-drive and Windows believes this to be a general disk:
Windows commandline prompt>wmic logicaldisk list (relevant excerpt)
Access Availability BlockSize Caption Compressed ConfigManagerErrorCode ConfigManagerUserConfig Description DeviceID DriveType ErrorCleared ErrorDescription ErrorMethodology FileSystem FreeSpace InstallDate LastErrorCode MaximumComponentLength MediaType Name NumberOfBlocks PNPDeviceID PowerManagementCapabilities PowerManagementSupported ProviderName Purpose QuotasDisabled QuotasIncomplete QuotasRebuilding Size Status StatusInfo SupportsDiskQuotas SupportsFileBasedCompression VolumeName VolumeSerialNumber
0 C: FALSE Local Fixed Disk C: 3 NTFS 144074813440 255 12 C: 1023013810176 FALSE TRUE OSDisk B622B231
0 D: FALSE Local Fixed Disk D: 3 NTFS 996483739648 255 12 D: 1000168484864 FALSE TRUE Elements 6CD465F5
On my Windows PC, I have two extra directories:
C:\Users\...\AppData\...\CanonicalGroupLimited.UbuntuonWindows_...\...\rootfs\mnt\c
C:\Users\...\AppData\...\CanonicalGroupLimited.UbuntuonWindows_...\...\rootfs\mnt\d
On my Linux subsystem, /etc/mtab
finishes as follows:
Linux Prompt>tail -n 2 /etc/mtab
C:\134 /mnt/c drvfs rw,noatime,uid=1000,gid=1000,case=off 0 0
D:\134 /mnt/d drvfs rw,noatime,uid=1000,gid=1000,case=off 0 0
Yet, the result of df -hk
does not show any /mnt/d
:
Linux Prompt>df -hk
df: /mnt/d: Invalid argument
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 999036924 858339700 140697224 86% /
...
C:\ 999036924 858339700 140697224 86% /mnt/c
On the internet, I found this command, but it does not give a solution:
Linux prompt>mount -t drvfs D: /mnt/d
And the result of mount
is quite weird:
Linux prompt> sudo mount
rootfs on / type wslfs (rw,noatime)
...
C:\ on /mnt/c type drvfs (rw,noatime,uid=1000,gid=1000,case=off)
D:\ on /mnt/d type drvfs (rw,noatime,uid=1000,gid=1000,case=off)
Yet, /mnt/d
does not work: the directory exists, but it's unusable.
Anybody knows what to do?
Thanks in advance
First off, just pretend that anything you find under %AppData%
just doesn't exist. It's dangerous and its use can cause corruption in WSL (Microsoft Link). I know you probably just came across it by searching in Windows. Just walk away ... slowly. :-)
Short answer possible solution:
Try creating a new mount location:
sudo mkdir /media/d
sudo mount -t drvfs D: /media/d
Or possibly:
wsl --shutdown
- Reattach the USB drive
- Start the WSL instance
More detail:
Here's what I think is happening. WSL reads the Windows attached drives when it is started, and auto-mounts this drive list in each instance (via /init
) when the instance is started.
If the drive is disconnected after WSL starts, then the subsystem doesn't know about that. A disconnect and reconnect of the drive (or another drive) will end up in a similar situation to what you are seeing -- A /mnt/d
(or other drive letter) that doesn't work.
As proposed above, a new mount location (/media
is nice, since it's normally where you would mount removable drives) or a wsl --shutdown
and restart resolves the issue for me.