Windows Subsystem for Linux (WSL) and Windows File Systems

This blog post explains how you can access different types of file systems from Windows Subsystem for Linux (WSL). This is a repost of

In Windows Subsystem for Linux shells, you can access the Windows C:\ drive as /mnt/c, and you can use the wslpath command to convert between Windows and Linux path formats. If you use another drive letter for removable media or a network share, you might expect that drive letter to appear under /mnt, but this does not happen automatically.

Console demonstrating commands for working with Windows file systems

To access removable media and network shares from WSL, you can create a directory under /mnt and mount the resource there.

To mount the removable media in the Windows D:\ drive as the /mnt/d directory in WSL:

sudo mkdir /mnt/d
sudo mount -t drvfs d: /mnt/d

This takes some time. If you eject the media or reboot, the mount point will persist, but may raise permission denied. Therefore, when you have finished, you may want to unmount the media and remove the subdirectory:

sudo umount /mnt/d
sudo rmdir /mnt/d

I found umounting and remounting within a single session to be a bit flakey and seemed to make the \wsl$ mount point in Windows unreliable.

The process is similar for a network share, although you may want the directory to persist. I use the following command to create the /mnt/z directory to mount the equivalent of my Z:\ drive connecting to the share named “shared” on the machine named M5 (where M5 is probably either a Star Trek TOS reference or a BMW model/option reference, depending on your context):

sudo mkdir /mnt/z
sudo mount -t drvfs '\M5\shared' /mnt/z

This takes some time. I use a Microsoft account on both devices, and WSL seems to have used those credentials without prompting me. If I have not accessed the share from Windows, then I get an error:

mount: /mnt/z: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program.
<3>init: (61) ERROR: UtilCreateProcessAndWait:489: /bin/mount failed with status 0x2000
<3>init: (61) ERROR: MountPlan9:478: mount cache=mmap,rw,trans=fd,rfdno=3,wfdno=3,msize=65536,aname=drvfs;path=UNC\M5\shared;symlinkroot=/mnt/ failed 2
No such file or directory

I access the share from Windows and then run the mount command again and it works. If I pull the network cable from the server, the /mnt/z directory appears to be empty.

The process to unmount a network share is basically equivalent to that for removable media:

sudo umount /mnt/z
sudo rmdir /mnt/z

It may be worth mentioning that the WSL file system shows up under \wsl on Windows. For me, /mnt in WSL is \wsl$\Ubuntu-20.04\mnt in Windows and WSL user home directories (/home/*) are under \wsl$\Ubuntu-20.04\home on Windows.

If you know of any additional information or resources about accessing Windows file systems from WSL, please comment on this article.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: