60

Is there a way to access removable media (e.g. thumb drives or SD cards) from within Bash on Windows?

Bash on Windows uses DriveFs to mount fixed drives in the /mnt folder, but it doesn't automatically mount removable media. And it doesn't look like it puts them in /dev either:

Aaron@MYPC:/$ ls /dev
block  fd  kmsg  lxss  null  ptmx  pts  random  shm  stderr  stdin  stdout  tty  tty0  tty1  urandom  zero

Is there a way to mount removable drives? Is there a way to access the underlying block device?

7
  • 5
    See this wpdev.uservoice.com/forums/….
    – CodeIt
    Aug 5, 2016 at 3:17
  • type mount and see if that gives you clues. If using cygwin bash, the path is /cygdrive/. Oct 19, 2016 at 16:58
  • Nope: Aaron@MYPC:~$ mount rootfs on / type rootfs (rw,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204320k,mode=755) [etc] Oct 19, 2016 at 17:26
  • 3
    Possible duplicate of Windows 10 Ubuntu Bash Shell: How Do I Mount Other Windows Drives?
    – DavidPostill
    Dec 4, 2016 at 16:22
  • Similar, although this question specifically mentions removable media and that one refers to fixed media. The highest rated answer on that post is only partially applicable to this question. Dec 5, 2016 at 17:04

6 Answers 6

73

Good news, it is now possible to mount USB media (including formatted as FAT) and network shares with drvfs on Windows 10:

Mount removable media: (e.g. D:)

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

To safely unmount

$ sudo umount /mnt/d

You can also mount network shares without smbfs:

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

You need at least Build 16176 so you might have to opt-in to the Windows Insider programm and then update Windows. Source: https://blogs.msdn.microsoft.com/wsl/2017/04/18/file-system-improvements-to-the-windows-subsystem-for-linux/

11
  • 5
    Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
    – DavidPostill
    May 16, 2017 at 15:52
  • 10
    Dear David. Feel free to raise the flag for duplication yourself. This answer is tailored to the question and you are more than welcome to make suggestions for improvement.
    – user643011
    May 16, 2017 at 19:37
  • 2
    Dear "user", I upvoted your comment here assuming that what you said was, well, true... Now I realize I was wrong, but can't seem to undo my comment upvote, so I have to ask explicitly: how exactly is this "tailored to the question", while still being the exact "bitwise" copy of your other answer?
    – Sz.
    Aug 8, 2018 at 18:50
  • 1
    Hey Sz! Because it's true? It answers exactly: Is there a way to access removable media from within Bash on Windows. If you have a better answer then feel free to answer the question better or suggest an edit to this one. Thanks!
    – user643011
    Aug 10, 2018 at 14:54
  • wrong fs type, bad option, bad superblock on G:, missing codepage or helper program, or other error -- also, please read this comment; don't answer duplicates.
    – Nic
    Mar 17, 2019 at 23:55
10

Is there a way to access removable media from within Bash on Windows?

Update:

Apparently it is now possible starting from Windows 10 Build 16176.

See https://superuser.com/a/1209701/337631.


No.

At the moment there are limitations on what drives are mounted:

In order for a drive to show up under /mnt/ it must meet the following criteria:

  1. The drive must be a fixed drive
  2. The drive must be formatted to NTFS.

This has been raised as an issue: Drives other than C: are not mounted in /mnt #1079. It is still marked as "Open".

To facilitate interoperability with Windows, WSL uses the DrvFs file system. WSL automatically mounts all fixed drives with supported file systems under /mnt, such as /mnt/c, /mnt/d, etc. Currently, only NTFS and ReFS volumes are supported.

Source WSL File System Support


Further Reading

1
2

To add on to the existing answers: if you install an ext driver for windows (e.g. Ext2Fsd) you can mount and ext flesystem like you would an NTFS filesystem. This can be useful if you want to mount Raspberry Pi SDCards.

2

I am finally able to configure WSL2 to automount my SDcard as non-root user and preserve owner:group and rwx permissions on SDCard. My SDcard is NTFS in format.

Step1. enable automount. Create /etc/wsl.conf with this content

$cat /etc/wsl.conf
[automount]
enable = true
options = "defaults,user"
mountFsTab = true

Step2: create mnt/d where we want to mount our drive

mkdir /mnt/d

Step3: Enable fstab entry for SDCard to be mounted at /mtn/d. In my case, D: drive (on surface pro 7)

$ cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 1
D:      /mnt/d  drvfs   defaults,user,metadata,exec  0       0

Note:

  1. there are two lines, first one was already there. I added the second line.
  2. options user is requires, else it mounts as root user. and option metadata is required, else it wont be able preserve user, group etc permissions.
  3. exec is needed, else you may not be able to execute files in mounted file system. (I was not able to execute file in windows 11)

Step 4: restart wsl

#exit bash or linux, go to dos/windows prompt
wsl --shutdown
wsl # or bash 
1
  • This is now the best solution since it's more up-to-date, and the mount is persistent Oct 30, 2021 at 21:28
0

If the device is not in /dev it's likely that your setup isn't even detecting the drive.

The command lsblk should list all connected block devices (drives). If it doesn't appear in this list your best bet is to try plugging in the device before starting bash.

I don't see from your question any mention of what method of using bash on windows you've found, but for most it shouldn't be too hard to restart bash.

If lsblk does show you your drive then find the path it lists and type mount <path shown by lsblk> <path you want the drive to be mounted to>

2
0

Mounting block devices in WSL was NOT possible before, but as of recently (Sept 2020), it is possible when you install preview 20211 (and possibly included in the mainstream Oct 2020 update).

command to mount: wsl --mount <DiskPath>

where you get the <DiskPath> via powershell command line: wmic diskdrive list brief

see here for details: https://devblogs.microsoft.com/commandline/access-linux-filesystems-in-windows-and-wsl-2/

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.