Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # winmount - A script to mount/unmount Windows drives on WSL other than C:
- #
- # Usage: winmount <Windows Drive letter> (e.g. winmount d)
- # -Note: input is not case sensitive
- #
- # G+ Post: https://plus.google.com/+JessiBaughman/posts/W8ZhpJ36Hap
- # Created by: Jessi A. Baughman
- # Last Modified: 2018-04-04
- thisScript=$(basename $0)
- if [[ $# -eq 1 ]];then
- # Convert input to respective upper/lower case values
- x=$1
- windrive=${x^^}
- wsldrive=${x,,}
- if [[ $wsldrive == 'c' ]]; then # Prevent problems with /mnt/c
- echo;echo "ERROR: Cannot modify C: mount"
- echo;exit
- fi
- # Check if drive is already mounted in WSL
- e=`mount | grep -c /mnt/$wsldrive`
- if [[ $e -gt 0 ]]; then # Is mounted
- echo;echo "Drive $windrive: is already mounted."
- echo -n "Unmount $windrive: drive [y/N]? "
- unmount='N'
- read unmount
- if [[ ${unmount,,} == 'y' || ${unmount^^} == 'Y' ]]; then
- sudo umount /mnt/$wsldrive
- echo;echo "Drive $windrive: unmounted."
- else
- echo;echo "Drive $windrive: left mounted."
- fi
- else # Drive is not mounted
- if [[ ! -d /mnt/$wsldrive ]]; then # Directory needs created
- sudo mkdir /mnt/$wsldrive
- fi
- # Mount drive
- echo;e=0
- sudo mount -t drvfs $windrive: /mnt/$wsldrive || e=1
- if [[ $e -gt 0 ]];then
- echo "Failed to mount $windrive:";echo; exit
- else
- echo "Drive $windrive: mounted to /mnt/$wsldrive"
- fi
- fi
- else
- echo;echo "Usage: $thisScript <Windows Drive Letter to Mount>"
- echo " e.g.: $thisScript d"
- fi
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement