简体   繁体   中英

Mounting a windows share in Windows Subsystem for Linux

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

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.

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

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, eg

sudo mkdir -p /mnt/somename

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM