Dup Goto 📝

MountRemovableDrives

PT2/windows/wsl 04-02 04:31:09
To Pop
44 lines, 290 words, 1712 chars Thursday 2026-04-02 04:31:09

If you plug in a USB drive (that Windows can read), it doesn't automatically appear in /mnt.

Drvfs

If Windows already sees the drive in File Explorer, you can mount it in WSL using drvfs.

sudo mkdir /mnt/e
sudo mount -t drvfs E: /mnt/e

which one can turn into a simple function such as

wm() {
  local D="$1"
  local DU="${D^}" # make uppercase in case we need to
  local DL="${D,}"
  local M="/d/${DL}"
  if [[ $D =~ ^[a-zA-Z]$ ]]; then
    # check if already mounted
    if [[ -d "$M" ]] && mountpoint "$M" >&/dev/null; then
      echo "$M already mounted";
      return
    fi;

    sudo mkdir -p /d/${DL} || { echo "Failed to ensure /d/${DL} exists"; return 1; }
    sudo mount -t drvfs ${DU}: "$M" || { echo "Failed to mount ${DU}: on $M"; return 1; }
    echo "Mounted ${DU}: on $M"
  fi
}

I tend to use /d/e for mounting drives to save a couple of keystrokes. I symlink /media/user to /m on my systems (I am the only regular user), put local mounts in /d/, such as /d/c, generally enumerating most internal drives (e.g. 4 in an HP Microserver) as /d/a, /d/b, and so on, kind of a throwback to Windows drive letters (which many Linux diehards will consider an abject abomination worthy of eternal damnation). Then sshfs mounts on my LAN go in /n/machine where again for keyboard convenience I use shorthands such as /d/ha for halfling.

USBIPD-WIN

There is a way to grant low-level access to a USB drive, so that the Linux filesystem driver is used, not the Windows one. For most use cases (i.e. a USB drive formatted with FAT, Exfat, or NTFS) this is overkill at best. For this see here.