4

I used subst R: . for a faster way to access a folder.

Is it possible to mount the R: "drive" to WSL? When I try running sudo mkdir /mnt/r then sudo mount -t ntfs R: /mnt/r, I am met with this error:

ntfs-3g: Failed to access volume 'R:': No such file or directory

ntfs-3g 2017.3.23AR.3 integrated FUSE 28 - Third Generation NTFS Driver

Configuration type 7, XATTRS are on, POSIX ACLS are on
Copyright (C) 2005-2007 Yura Pakhuchiy
Copyright (C) 2006-2009 Szabolcs Szakacsits
Copyright (C) 2007-2017 Jean-Pierre Andre
Copyright (C) 2009 Erik Larsson 

Usage:    ntfs-3g [-o option[,...]] <device|image_file> <mount_point>

Options:  ro (read-only mount), windows_names, uid=, gid=,
umask=, fmask=, dmask=, streams_interface=.
Please see the details in the manual (type: man ntfs-3g).

Example: ntfs-3g /dev/sda1 /mnt/windows

News, support and information:  http://tuxera.com 

Thanks in advance!

Asked the same question on StackOverflow but realized that wasn't the right place to do so... 😅

3
  • 1
    Related: superuser.com/a/1261563/990044 – Freddy Jan 16 at 6:27
  • 2
    @Freddy Not really related, as this question is about subst mappings, which are not "real" drives (not even network drives, it seems) and cannot be "mounted". The closest thing to subst is a mount --bind, which isn't even mentioned in that question/answer. – NotTheDr01ds Jan 16 at 6:50
  • 3
    And by the way, @Justin-Chang, kudos for finding a good use for that nearly 40-year old subst command. It's been literally decades since I've seen it. I had to look it up to be sure, but as I thought, it came about as a DOS 3.1 command before Windows was even a gleam in Gates' eye. – NotTheDr01ds Jan 16 at 7:22
3

While WSL doesn't have automatic or even direct access to the subst drives, there are ways to map them. There are several routes to go here, depending on your exact workflow.

The main things to remember are:

  • In Linux, sudo mount --bind . /mnt/r is roughly equivalent to subst R: .. If you're okay with just having the Linux equivalent, and you don't need to access the same drive letter under Windows, then this may be all you need. You could even create a subst function in bash that would work pretty closely to that of Windows.

  • That said, bind is probably overkill here. You most likely just want a symlink, like ln -s /mnt/c/Users/username ~/r. This doesn't require root as long as you have permissions to the target location.

  • For mappings that you have created in Windows with subst, you can retrieve the substituted paths in Linux by calling out to PowerShell, like: powershell.exe -c subst

  • You can filter that down to just the R: mapping using grep and sed: powershell.exe -c "subst" | grep "^R" | sed "s/^R:\\\\: => //" (in case there are multiple drives/directories substituted, find just the R: drive, then remove everything before the directory path).

  • PowerShell returns an extra newline ("\r"), so you have to strip that with something like tr -d "\r".

  • You can convert a Windows path to the Linux/WSL equivalent with the wslpath command.

Put it all together, and you get the script that can turn your R: into /mnt/r (or ~/r if that's more convenient):

rpath=$(powershell.exe -c "subst" | grep "^R" | sed "s/^R:\\\\: => //" | tr -d "\r")
sudo mount --bind $(wslpath "${rpath}") /mnt/r/

Or the equivalent with the ln instead.

Of course, you'll want to assign it to a function so it's easier to repeat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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