Mount Removable Drives in WSL2

by Bryan on 9/3/2020 at 9:12 AM in Notes To Myself

Windows Subsystem for Linux doesn’t automatically mount removable drives, which has long been a source of frustration for me. I want to leave a note to myself with my findings. If this helps anyone else, even better!

There are two approaches I’ve used:

  1. Bash script to mount removable drive
  2. Utilize /etc/fstab to mount removable drive

Bash Script Approach

Using a bash script is a straightforward way to mount drives. My script is very simple, first checking if the directory I’m going to use with the mount exists, and if not, create it, and then mount the drive (I’m a bash newb, so please feel free to suggest improvements):

readonly DPath='/mnt/d'

if [ -d $DPath ]; then
        echo "$DPath already exists"
        sudo mkdir /mnt/d
sudo mount -t drvfs D:\ /mnt/d

Utilize /etc/fstab

I recently stumbled upon this option, in which WSL processes /etc/fstab at instance start. This is basically set it and forget it. Here’s what I added to my /etc/fstab: D:\ /mnt/d drvfs

Useful Links