DEV Community

Ryan Palo
Ryan Palo

Posted on

Mounting Network Drives into Windows Subsystem Linux

This was initiated by my last article where I was counting directories on the command line.

At the end of the article, I wanted to show how it was done on the Linux CLI too, but I quickly ran into the problem that our server wasn't mounted into the Windows Subsystem Linux (WSL) file system. As it turns out, it's easier than I initially thought it would be!

Microsoft uses a new type of file system called DrvFs behind the scenes to allow the Linux subsystem to talk to native Windows directories. So you end up mounting a network drive just like you would mount any other media normally.

Let's say you've got a server on your network usually accessible as \\stroopwafel. To mount it into your WSL, you can do the following (I'm using Ubuntu, but it should be similar for the other distros):

sudo mkdir /mnt/stroopwafel
sudo mount -t drvfs '\\stroopwafel' /mnt/stroopwafel
Enter fullscreen mode Exit fullscreen mode

Note: I used single quotes to avoid awkwardness around the backslashes in the network drive name.

If you have mapped the network drive to a drive letter on your Windows system already--let's say \\stroopwafel is mapped to S:\--or if you've just got a removable drive that isn't mounted yet but has a letter on your Windows system, the syntax changes a little:

sudo mkdir /mnt/stroopwafel
sudo mount -t drvfs S: /mnt/stroopwafel
Enter fullscreen mode Exit fullscreen mode

If you ever want to unmount it:

sudo umount /mnt/stroopwafel
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

marvinxu profile image

➜ ~ sudo mount -t drvfs Z: /mnt/z
<3>WSL (3449) ERROR: MountWithRetry:307: mount(drvfs, /mnt/z, 9p, 0x00000000, cache=mmap,msize=262144,trans=virtio,aname=drvfs;path=Z:;symlinkroot=/mnt/) failed: Invalid argument

Can you help?