Until now, I’ve always mounted drives by accessing their devices. However, I ran into a situation where this wouldn’t work. Luckily, Ubuntu has the ablility to access drives by UUID – which solved my problem.
I have a drive that holds networked data, which I mount on Ubuntu 8.04 Server as /data/. I also back that drive up to a drive which is normally read-only as /databackup/.
Both of these drives are SATA – meaning they could be unplugged at any time. If both are unplugged, whichever drive gets plugged in first becomes /dev/sda1 – and the other becomes /dev/sdb1. This means I can’t rely on mounting /dev/sda1 on /data and /dev/sdb1 on /databackup.
To get around this, I mounted the drives using UUID in /etc/fstab. First, I had to figure out what the UUIDs of the drives were. To start with, I killed Samba and unmounted both – I knew /dev/sda1 was /data and /dev/sdb1 was /databackup. Then I obtained the UUIDs of both drives:
$ sudo vol_id --uuid /dev/sda1
$ sudo vol_id --uuid /dev/sdb1
Next, I replaced the device mounts (/dev/sda1 and /dev/sdb1) in /etc/fstab with:
UUID=7b932326-717b-4ba6-bef2-fedfbafcabe6 /data ext3...
UUID=94efd7bd-8498-46f3-ab6d-cb706c413567 /databackup ext3...
Under Ubuntu 9.10, it appears that vol_id has merged into blkid – so now you would use:
$ sudo blkid /dev/sda1
/dev/sda1: UUID="f30ba2a3-9da6-48b1-8ab5-75952ef26cc4" TYPE="ext3"
to determine the UUID, and then update /etc/fstab as you’d do for 8.04.