36

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 WLS?

21

[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.

  • Agreed, this is a showstopper for me too - I just installed msys2 for this. – Ela782 Apr 7 '17 at 17:55
  • 3
    Details: blogs.msdn.microsoft.com/wsl/2017/04/18/… – bleater May 3 '17 at 0:34
  • the order of your arguments to mklink is wrong - it should be linkname target, not target linkname – masterxilo Dec 5 '18 at 22:10
  • Yes, masterxilo, you are correct -- I had the mklink command wrong here. Fixed. When I actually tried it, I did it right, and it didn't work vis-a-vis WSL. It's a moot point now, since WSL now can mount network shares. But thanks for the correction. Even if almost nobody is looking at this answer, I hate to leave a mistake like that. – Joseph Thvedt Jan 30 at 21:48
60

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.

  • 1
    totally worked for my "bash for windows 10"! Thank you so much! – Ying Zhang Jan 26 '18 at 0:55
  • 1
    The correct answer should be changed to this one as it directly answers the question. – Tomek Jan 31 '18 at 2:43
  • You need "Windows Insider build" to get DrvFs. -1 (not actually down voting) – FractalSpace Feb 27 '18 at 21:39
  • 3
    I don't have windows insider build and it's working for me – gman Feb 28 '18 at 1:14
  • That is completely awesome. – Erik Mar 24 '18 at 2:41
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
0

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.