Ubuntu technical problems and solutions reference, a modern cookbook.
I know there are a lot of people who are adding their drives in /etc/fstab. I personally don’t like that approach, because in Nautilus I will see 2 copies of the same drive. One mounted and the other unmounted and when it gets pressed I got an error saying that the drive is already mounted.
I prefer a solution where the drive gets mounted exactly as Nautilus does it, when the drive is mounted by simply pressing the unmounted drive.
First we need to find out where each drive is located, so that we know where each drive is located on the disk. Using the following command, we get the desired outcome:
ls /dev/disk/by-label -lah
The output look something like this:
lrwxrwxrwx 1 root root 10 2011-11-13 14:58 Storage -> ../../sda6
Assuming we need to auto mount the drive called Storage, we create it’s mounting point:
sudo mkdir /media/Storage
Now, a script needs to be created which mounts the drive:
vi ~/mountscript.sh .... #!/bin/bash sudo mount /dev/sda6 /media/Storage
Need to make the script executable and then test it
sudo chmod +x mountscript.sh ./mountscript.sh
You will notice that the script requires us to introduce the password. That’s not good when we are going to add this script to be run at start-up. So we need to exclude the 2 commands we are using (mount and the script we’ve just created) from sudo to ask us for the password.
Add this line at the end replacing your user with the name of your own user:
your user ALL=(ALL) NOPASSWD: ~/mountscript.sh, /bin/mount
Now both commands, mountscript.sh and mount are excluded from being prompted a password.