Skip to content

Instantly share code, notes, and snippets.

@rhaglennydd
Last active June 9, 2023 19:00
Show Gist options
  • Save rhaglennydd/f3c97355585cf02da228e4b7b5404bdb to your computer and use it in GitHub Desktop.
Save rhaglennydd/f3c97355585cf02da228e4b7b5404bdb to your computer and use it in GitHub Desktop.
WSL script for mounting drives

Use this script to mount drives in WSL. Example: ezmount.sh f to mount the F: drive.

Thanks to https://askubuntu.com/a/1422805/778411 for specifying how to make the WSL user the default owner of files.

#!/usr/bin/env bash
DRIVE_LETTER="$1"
if [[ ! "$DRIVE_LETTER" ]]; then
echo Please enter a drive letter.
exit 1
fi
mount_path="/mnt/${DRIVE_LETTER,,}"
if [[ ! -d "$mount_path" ]]; then
sudo mkdir "$mount_path"
if [[ "$?" ]]; then
echo Something went wrong in trying to create the directory "$mount_path".
exit 1
fi
fi
sudo mount -t drvfs "${DRIVE_LETTER^^}:" "$mount_path" -o "uid=$(id -u $USER),gid=$(id -g $USER),metadata"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment