May 05

Mounting Removable Drives At Boot In eeeXubuntu

Tag: linuxSymon Rottem @ 10:53 pm

Now that was more interesting.

Today I managed to solve the question I asked in my last post, namely how does one set up a removable USB drive to automatically mount at boot. I was trawling around and not getting anywhere when I left you last.

My next course of action was to impose upon a colleague who has more Linux experience than I do and he pointed me to setting up mount commands to execute during start up and, more importantly gave me a quick overview of how the startup process works in Linux. He’s got himself an Eee PC too, so he’s been around the block, but he uses his as it was meant to be used – as a portable unit.

Anyway, based on his advice I found this page which provides an excellent overview of the startup process and scripting in Linux and that page gave me the idea of using the /etc/rc.local file to execute my mount commands.

Before that, however, I decided to clean up my /etc/fstab to use the UUID of the drive to make things a little more reliable. To do that I needed to find out what the UUID actually was…fortunately in the Ubuntu Linux disks can be found under /dev/disk/by-label which shows the label of the disk (useful for identifying a drive for a human being) and /dev/disk/by-uuid (which is better for computers to identify a disk).

By executing…

 ls -la /dev/disk/by-label

…I get the list of disk labels and the corresponding device it’s mounted as for the moment:

total 0
drwxr-xr-x 2 root root 100 2008-05-05 23:13 .
drwxr-xr-x 6 root root 120 2008-05-05 22:58 ..
lrwxrwxrwx 1 root root  10 2008-05-05 22:58 Big\x20Disk -> ../../sdb1
lrwxrwxrwx 1 root root  10 2008-05-05 23:05 Media\x20Disk -> ../../sdd1
lrwxrwxrwx 1 root root  10 2008-05-05 23:13 PORTABLE -> ../../sde1

And then by executing…

ls -la /dev/disk/by-uuid

I can see the UUIDs of the disks and the same corresponding device.

total 0
drwxr-xr-x 2 root root 140 2008-05-05 23:13 .
drwxr-xr-x 6 root root 120 2008-05-05 22:58 ..
lrwxrwxrwx 1 root root  10 2008-05-05 19:31 22dc6988-36c5-4e98-976b-321aa3f04cba -> ../../sda1
lrwxrwxrwx 1 root root  10 2008-05-05 22:58 2C300B22300AF31E -> ../../sdb1
lrwxrwxrwx 1 root root  10 2008-05-05 23:13 584C2EE74C2EBF9C -> ../../sde1
lrwxrwxrwx 1 root root  10 2008-05-05 19:31 d32d39d4-cbac-41ba-b9c5-b08b95ef5286 -> ../../sda5
lrwxrwxrwx 1 root root  10 2008-05-05 23:05 EC00D02C00D0000E -> ../../sdd1

So, since I now know that the disk with the label PORTABLE is corresponds to device sde1 and that sde1 also corresponds to the UUID EC00D02C00D0000E…I think you get the idea.

Now I want to mount each of these drives under a single folder so I can expose that folder as a Windows share to access all of these disks from across the network, so first I’ll create a new folder on my root filesystem – /storage. Next I’ll create a subfolder for each of the disks I want to mount; I’m going to base the names on the labels of the disks:

sudo mkdir /storage
sudo mkdir /storage/big
sudo mkdir /storage/media
sudo mkdir /storage/portable

Next, by adding each of these to the /etc/fstab file I can configure the system with some information about how these filesystems should be accessed and mounted. Executing…

sudo nano /etc/fstab

…opens the fstab file for editing (I’d recommend making a backup first to be safe) and then I can add the new lines for the new mountpoints at the end of the file:

# USB disk mounts
/dev/disk/by-uuid/584C2EE74C2EBF9C /storage/portable ntfs nls=utf8,umask=0222 0 0
/dev/disk/by-uuid/2C300B22300AF31E /storage/big ntfs nls=utf8,umask=0222 0 0
/dev/disk/by-uuid/EC00D02C00D0000E /storage/media ntfs nls=utf8,umask=0222 0 0

Each of these lines is made up of the device path (using the UUID version we determined earlier), followed by the folder to mount it to and some additional information about the filesystem which I won’t go into right now; you can do some research of your own if you need to know!

Once the file has been saved you can test the mounts by executing…

sudo mount -a

…which will mount the filesystems using the fstab file. At this point if I get a directory listing for /storage/portable I can now see the contents of the USB disk! Woohoo!

So, on to the final step – getting the drives to mount during the boot process. I did this using the /etc/rc.local file. In a default Ubuntu installation this file does nothing but it’s a good point for adding some final steps of your own during the boot process.

The file ends with an exit 0, so before that line I added my mount commands to mount each of my drives:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

mount /dev/disk/by-uuid/584C2EE74C2EBF9C /storage/portable
mount /dev/disk/by-uuid/2C300B22300AF31E /storage/big
mount /dev/disk/by-uuid/EC00D02C00D0000E /storage/media
exit 0

After that’s saved, reboot and voila! Auto mounted removable disks!

Related Posts