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?

6 Answers6

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/

user643011
  • 2,618
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

DavidPostill
  • 162,382
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 
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>

timotree
  • 1,148
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/

Nepaluz
  • 129