Mounting a windows share in Windows Subsystem for Linux

34,970

Solution 1

Assuming the host Windows OS can access a file share at "\\servername\sharename", try this command in bash. You will need to be root:

mkdir /mnt/mountedshare
mount -t drvfs '\\servername\sharename' /mnt/mountedshare

The single quotes are important!

Worked for me with a SharePoint Online UNC path. The permissions are screwy though. I can navigate through the folders and see the filenames, but I can't read files. So need to figure out the permissions thing. Let me know if you get anywhere with that.

Solution 2

Actually if your windows share is already mapped to a drive in the Windows host, it can be even simpler. Let's suppose you already mounted the share on Z:. In that case the following will work:

sudo mkdir /mnt/z
sudo mount -t drvfs 'Z:' /mnt/z

Solution 3

While you have an a mount created to the windows host through /mnt/c already created for you in WSL, if you want to mount a share from another machine, then you will need to create the mount point, e.g.

sudo mkdir -p /mnt/somename

Then you will need to mount the remotely shared smb:// filesystem at that mount point using mount.cifs, e.g.

sudo mount.cifs //server/sharename /mnt/somename

Optionally, you will want to include options following /mnt/somename such as

-o username=yourname,uid=YOURUID,noperm,password=yourpassforremoteshare

If it is an older WinXP share you are attempting to mount, then you will need to enable NTLMv1 authentication by including the sec=ntlm or sec=ntlm1. See mount.cifs for further use of the sec= option.

Solution 4

In WSL (I'm using Ubuntu) it looks like that when you install the cifs-utils it doesn't create the module file that cifs needs when mounting. Type: "modinfo cifs" and you will see. Anyway, the work-around is to map a drive letter in Windows and then mount to that, as mentioned above. Thanks gabuzo.

Maybe its that cifs-utils is looking in the wrong place for the module file. Or MS intentionally disabled it. They don't want WSL to be too useful.

Solution 5

Mounting an SMB server share should be straightforward, I tested this on Windows build 1909 and WSL 2.0 Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64). You use mount just as usual:

sudo mount -t drvfs '\\server\share' /your/mount/folder

Nothing too hard, the source path of the mount is the regular UNC pathname. The important bits are the file system type ("drive filesystem"?) and the fact that you need to enclose the server path in single quotes (on the command line). As usual, your mount folder must also exist.

On this WSL issue I found good options (-o) that seem to work very well with creating, reading and writing files without sudo as well as reading correct modification/creation dates:

metadata,rw,noatime,uid=1000,gid=1000,umask=22,fmask=11

Because I like to have this server mounted always, I put the mount instruction into /etc/fstab to have it auto-mounted by WSL:

\\server\share /your/mount/folder drvfs metadata,rw,noatime,uid=1000,gid=1000,umask=22,fmask=11 0 0

(you can reload fstab with sudo mount -a)

Note that I have logged into the server on Windows itself and made it remember the user and password. @David C. Rankin's answer has some info on how to specify username and password if you need to do it separately.

Share:
34,970

Related videos on Youtube

David Hoffman
Author by

David Hoffman

I’m a scientist and engineer with a proven track record of hardware and software development whose research has been featured on the cover of Science magazine. I trained as a physical chemist and spectroscopist as a Berkeley graduate student before diving into imaging and biology as a post-doc in Nobel Laureate Eric Betzig’s group. While I enjoy digging into the nuts and bolts of instrumentation, theory and code, I always see my work in the context of the big picture and strive to do the most useful thing most efficiently. I’m goal focused, data driven and led by curiosity.

Updated on July 09, 2022

Comments

  • David Hoffman
    David Hoffman almost 2 years

    I'd like to mount a windows server from within WSL (Windows Subsystem for Linux). On Ubuntu (with unity interface) I can just type

    gvfs-mount smb://domain\;user@server/share
    

    and everything mounts just fine.

    If I try this in WSL then I get the following error:

    Error mounting location: volume doesn't implement mount
    
    • Raman Sailopal
      Raman Sailopal almost 7 years
      Use the mount command with fs type cifs
    • David Hoffman
      David Hoffman almost 7 years
      Sure, is there an easy way to move it or do I just copy and paste it over there?
  • chris
    chris about 6 years
    Hmm. I get mount: unknown filesystem type 'drvfs'.
  • chris
    chris about 6 years
    Turns out (I guess) this is due to an old Windows build. github.com/Microsoft/WSL/issues/1975
  • kirk
    kirk over 5 years
    BTW, could you fix the permissions in the meantime (I observe the same issue)?
  • LaVache
    LaVache about 5 years
    @kirk No sorry, I didn't find a solution to the permissions issues that I saw. I pretty much gave up on trying to use it like this unfortunately, this was over a year ago though. If you do end up finding a solution, please share. I'm sure it will help many others.
  • Kenny83
    Kenny83 over 4 years
    I knew that mount -t drvfs '<drive letter>:' /mnt/mountpoint was the way to do this for a normal disk partition, but never imagined that simply using a UNC path in place of the drive letter would automagically work as well! Many thanks and +1! :D
  • AdamE
    AdamE almost 4 years
    I don't know about the rest of you, but the only option to connect to SMB share from WSL is to use the drive letter syntax (as answered by gabuzo below). If I use the unc drive syntax in single quotes '\\uncsharename\z', I get this error (i'm using WSL2 from Windows 10 v2004 Ubuntu 16 LTS) mount: /mnt/z: wrong fs type, bad option, bad superblock on \\uncsharename\z, missing codepage or helper program, or other error.<3>init: (8787) ERROR: UtilCreateProcessAndWait:489: /bin/mount failed with status 0x2000No error information
  • AdamE
    AdamE over 3 years
    I have since updated to WSL 2 and Ubuntu 18.04 and I tried this again. Until now, I've been using drive letter option but didn't like that I always had to map the drive before using wsl to mount the share. The following seems to work for me now and does not require single quotes (if I use forward slashes instead of backslashes): mount -t drvfs //server/sharedfolder /mnt/sharedfolder -o username=someusername,password=somepassword
  • Nicolas
    Nicolas over 3 years
    This is the solution that worked for me! Thanks
  • Foritus
    Foritus almost 3 years
    CIFS mounts work fine in Debian in WSL, so I'm going to assume it is an Ubuntu-specific problem.
  • sfscs
    sfscs over 2 years
    I had to double up the backslashses to get it to work: mount -t drvfs '\\\\servername\\sharename' /mnt/mountedshare