159

I have a samba drive which is mounted on my local windows computer.

I have a /mnt/c drive in WLS (Windows 10 Bash), but no /mnt/z.

Is there a way to access it somehow? Can I remount it in WSL?

1

9 Answers 9

42

[Update -- apparently this feature is available in build 16176. I haven't tried it yet.]

No, though there may be some trick I haven't discovered. Windows Subsystem for Linux does not mount network drives. A Microsoft employee says here (in a comment):

We only “mount” fixed drives at this time. USB/removable/network drives are not handled at this time. This capability is on our backlog, but it’s not on the cards anytime soon.

So don't hold your breath.

I attempted to work around it by using a symbolic link, like this:

c:> mklink /d c:\some\directory \\some_server\some_share

The link works just fine in "normal" Windows (cmd.exe, PowerShell, file explorer, etc.), but is invisible to WSL:

$ ls -ld /mnt/c/some/directory
/mnt/c/some/directory not found

For my own use, this limitation is a show-stopper. I have things on network drives that I'm not willing to move. There are alternatives; I'm using Cygwin.

3
332

from the link bleater posted

Mounting DrvFs

In order to mount a Windows drive using DrvFs, you can use the regular Linux mount command. For example, to mount a removable drive D: as /mnt/d directory, run the following commands:

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

Now, you will be able to access the files of your D: drive under /mnt/d. When you wish to unmount the drive, for example so you can safely remove it, run the following command:

$ sudo umount /mnt/d

Mounting network locations

When you wish to mount a network location, you can of course create a mapped network drive in Windows and mount that as indicated above. However, it's also possible to mount them directly using a UNC path:

$ sudo mkdir /mnt/share
$ sudo mount -t drvfs '\\server\share' /mnt/share

Note the single quotes around the UNC path; these are necessary to prevent the need to escape the backslashes. If you don't surround the UNC path with single quotes, you need to escape the backslashes by doubling them (e.g. \\\\server\\share).

WSL does not have any way to specify which credentials to use to connect to a network share. If you need to use different credentials to connect to the server, specify them in Windows by navigating to the share in File Explorer, using the Windows Credential Manager, or the net use command. The net use command can be invoked from inside WSL (using net.exe use) via interop. Type net.exe help use for more information on how to use this command.

6
  • 7
    This mounts the share, but everything is owned by root, and some files are unreadable (even with sudo, and even if the permissions inside WSL are 777). I can read the files from windows file explorer. Adding any mount options (-o) gives me "wrong fs type, bad option, bad superblock" error.
    – Jay K
    Nov 13, 2018 at 17:46
  • 5
    Does not work after applying Windows 2020 May update Jul 2, 2020 at 7:45
  • 6
    @user1602 Do you get ls: reading directory '.': Invalid argument? I do. Sucks.
    – Clonkex
    Sep 11, 2020 at 4:31
  • 3
    This only mounts the drive until logoff, I think. I used this guide to persistently mount a network drive to WSL: public-health.uiowa.edu/it/support/kb48568
    – mbomb007
    Nov 19, 2020 at 20:19
  • 1
    This also mounts cd-roms and dvd-roms. Sweet. Jan 4, 2021 at 19:09
21

WSL2 supports CIFS (SMB) protocol. You may need to specify your network server version when mounting. E.g. on Ubuntu:

$ sudo apt install cifs-utils
$ sudo mount -t cifs -o user=joe,pass=shmo,vers=1.0 //server/share /mnt/share
2
  • If the password is not specified, it will be prompted by mount. This avoids risking the password being recorded in the shell history. Mar 2 at 19:52
  • A drive mounted in this fashion appears to be read-only. Mar 2 at 19:55
19

I just ran across this issue recently where I have a Mac host running a vmware fusion with windows 10 installed as a guest OS. I installed WSL (ubuntu) in the windows 10. I am sharing a folder on my Mac (~/Public) with all my fusion guest O/S, and it works seemlessly with any linux/bsd guest OSes. On Windows 10, the network drive for the shared folder is \vmware-host\Shared Folder\Public\ and is accessible from the windows 10, and is also mounted on Z: drive as well.

The problem is when you are using bash in WSL. The suggested method is to (adjust actual drive letter and folder names as needed)

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

or, more directly

sudo mount -t drvfs '\\vmware-host\Shared Folder\Public' /mnt/z

The mount command is successful, but in fact the mount "failed". You can't see the content of the folder /mnt/z. The mount works well with other network drives AS LONG AS the filesystem is a windows (NTFS, FAT32, etc) filesystem. Since the file system I'm trying to use is apple file system (apfs), the drvfs cannot use it. It will likewise fail if the underlying filesystem you are trying to mount is linux (ext2, ext3, ...) or network nfs/samba type. This drvfs will only understand windows native drvie format.

Its funny how you can use none-windows filesystem drives in windows, but in wsl/linux, you can only see windows filesystem drives....

So, the short answer is

sudo mount -t drvfs { \\network\drive\folder | X:\folder } /mnt/folder

as long as the network drive is using native windows filesystem (ntfs, fat*).

1
  • this worked for me with a smb mount too
    – bebbo
    May 10, 2021 at 8:22
4

see https://github.com/Microsoft/WSL/issues/2999#issuecomment-455835951

Here is a way to mount GFS in WSL based on Getting `sshfs` working on WSL or finding an alternative The trick is to use https://www.nsoftware.com/sftp/netdrive/ to ssh to GFS from Windows and convert it to a filesystem that can be mounted under WSL.

  1. Install OpenSSH Server under Win10 Win10 Settings -> Apps -> Manage optional features -> Add feature -> OpenSSH Server restart if necessary open Services -> OpenSSH -> Properties -> Startup Type -> Automatic (delayed)

  2. Install and run SFTPNetDrive, right click on icon in hidden icons -> Main window (or maybe already open) -> Profile -> new profile ( server: localhost, user: * pwd:* Drive Letter: F (or another) Advanced -> ( Protocol -> uncheck compression; Specified folder: G:\ ) )

  3. in Bash (wsl): sudo mkdir /mnt/f; sudo mount -t drvfs F: /mnt/f

I'm not sure how stable it is, but I was able to open files in WSL.

3

I used this method after failing with some others.

https://www.public-health.uiowa.edu/it/support/kb48568/

All instructions below from that source.

Ensure the folder exists for the mount target (e.g. /mnt/m)

Open /etc/fstab and add a line such as the following:

M: /mnt/m drvfs defaults 0 0

Reload the fstab file with sudo mount -a

2
  • This worked for me to mount a Windows network drive (U:) in WSL2. I'll put exactly the commands I did from WSL2 command line (Pengwin/Debian).. sudo mkdir /mnt/u. sudo vi /etc/fstab. After editing, fstab is exactly this # UNCONFIGURED FSTAB FOR BASE SYSTEM U: /mnt/u drvfs defaults 0 0. Reload the fstab with sudo mount -a, but the MAIN THING IS THAT on reboot, `cd /mnt/u' takes me to the mounted Windows network drive. Mar 6 at 10:15
  • ps. it is mounted as RW, and I can use it in the WSL2 command line and utilities.. Mar 6 at 10:17
0

There are (at least) two ways to use Bash in Windows:

  1. The Bash that comes with WLS (when installing Linux on Windows 10 from Windows Store or other sources)
  2. Git-Bash on Windows

Git-Bash has access to network folders (install git-bash > go to the network folder > right-click > "Git Bash Here" > run pwd to see the path).

If you have to use the WLS version of bash, then you can call Git-Bash from WLS bash as follows:

WLS_Bash_Shell:$ /mnt/c/Program\ Files/Git/bin/bash.exe ScriptThatUsesNetworkFolders.sh
2
  • 1
    WSL non-windows net drives don't work, this git-bash answer is the only answer that did. Question shouldn't be negative, please vote up. Dec 11, 2019 at 21:09
  • The answer looks like it's trying to tell how to use bash, before saying why. Maybe it should be rewritten. Anyway, it's now 2021, and network drives can be mounted. (Also, my Git bash just crashed when I tried the "Git Bash Here" trick, so I'm not sure it even works.)
    – Tom Hundt
    Feb 9, 2021 at 20:21
0

To mount a networked (SMB/CIFS) drive, with permissions such that everything is not owned by root:

sudo apt install cifs-utils
sudo mkdir /mnt/f
sudo mount -t cifs -o user=REMOTE_USER,pass=REMOTE_PASS,$( \
    echo uid=$(id -u),gid=$(id -g) )                       \
    //REMOTE_SERVER/SHARE_NAME /mnt/f 
0

It should be mentioned that if you want to to auto-mount an UNC path during startup via /etc/fstab, you need to escape backslashes with an additional backslash:

sudo mkdir /mnt/remoteshare
sudo echo '\\\\RemoteMachine\\RemoteShare /mnt/remoteshare drvfs 0 0' >> /etc/fstab
sudo mount -a

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .