2010-12-18

Mount removable drives from command line

This is too simple, but it took me a while to find this type of solution, so I want to post it here to keep track of it, next time I need it:

I have an Ubuntu (10.x) with a couple of users. Some need to use the GUI (Gnome or XFCE) to work, including accessing removable media. Other users need (or rather, wish) to use the CLI to access removable media. This means /etc/fstab may not have specific entries for removable media (say, /dev/sdg1) with the "user" option, because this would block Nautilus (Gnome) or Thunar (XFCE) from automatically mounting the removable media for the GUI users.

So I just found that there exists a mount wrapper called pmount. (to install in an Ubuntu system, simply sudo apt-get install pmount). The CLI user now has a few aliases in his .csh file to easily mount and umount several types of removable media:

alias flash 'pmount /dev/sdf1 photo_sd' (for SD cards)
alias cflash 'pmount /dev/sdc1 photo_cf' (for Compact Flash cards)
alias pen 'pmount /dev/sdg pen' (for flashdrives)
alias pen1 'pmount /dev/sdg1 pen1' (for the 1st partition in a flashdrive)

All of the above create mount points ( /media/photo_sd, /media/photo_cf, etc...).
To unmount each of them, I've set up aliases too:

alias flash-u 'pumount photo_sd'
alias cflash-u 'pumount photo_cf'
alias pen-u 'pumount pen'
alias pen1-u 'pumount pen1'