Automatically mounting drives with UUIDs

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
7b932326-717b-4ba6-bef2-fedfbafcabe6
$ sudo vol_id --uuid /dev/sdb1
94efd7bd-8498-46f3-ab6d-cb706c413567

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.

Advertisements

One Response to Automatically mounting drives with UUIDs

  1. […] disk UUIDs By andrewmemory After setting up mounting by UUID as described here, I realized I had a […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: