UUIDs, Linux devices, and fstab

The Dilemma

I upgraded one of my Ubuntu servers from Hardy Heron (version 8.04 LTS) to Intrepid Ibex (version 8.10). After I rebooted my machine after upgrading my distribution, I noticed that apparently, 8.10 (or at least the kernel used by it initially, 2.6.27-7-generic) fully masks my attached Segate IDE and SATA drives as SCSI drives. My old fstab entries which used IDE raw device names such as /dev/hda1 were no longer relevant. As such, my /home directory had my non-/home SATA hard drive partition mounted on it, for example. I realized ( I don’t know why just now) that using raw device names (e.g. /dev/hda or even /dev/sda) for my mounted drives was a pain in the neck, not only because Ubuntu or the Linux kernel may change sooner rather than later on how to scan, load, mount storage devices. Rather, what is more appropriate is to use the UUIDs of my devices.

Do You UUID?

UUID or universally unique identifier is used around a lot in the tech/computer world these days, e.g. in MAC addresses. It’s basically a 128-bit number or 2128 or approximately 3.4 × 1038, which is a very large number. To put it in perspective, if you would produce oner UUID for every second of every hour of every day, for 365 days a year, you would still need approximately 1 × 1031 years, that’s a 1 with 30 zeros behind it. Now that’s a long time :D. So for now UUIDs are pretty unique, wouldn’t you agree?

Anyway, to get your hard drive’s UUID (whether it’s IDE or SCSI), use either the /dev directory

$ ls -l /dev/disk/by-uuid

to see your devices’ UUIDs. Mine gives

$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 46483822-17f9-408b-a3e2-aad688f8380d -> ../../sdd2
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 47AB-8F94 -> ../../sdd1
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 4c05ec57-4171-42c3-b932-f721edc45f15 -> ../../sdd3
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 533bef31-8157-4097-895b-e20217fb90a5 -> ../../sda1
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 5e4cab82-808e-43ec-99a6-bb1a6d7f4efd -> ../../sdc3
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 668cbb68-36a7-4454-bd50-7056f1658a2a -> ../../sdb2
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 71e7e7df-cff4-42ae-a0ec-dddcc6a4dacb -> ../../sdb1
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 b9c011df-1882-4d4c-b215-00ddd7b9bfe0 -> ../../sda3
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 BBF7-94B5 -> ../../sdc1
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 c33271e6-5c7a-406d-a87f-84d9b2d0c196 -> ../../sdc2
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 c3ec0a22-04e8-4735-b6c8-b20e95c2b5a3 -> ../../sda5
lrwxrwxrwx 1 root root 10 2008-11-06 20:28 fdd0b195-0313-4af7-bbbe-9eb1bed89a64 -> ../../sda2

Since I have 4 hard drives and several partitions on those hard drives on my server. The other way to get UUIDs is to use the blkid tool:

$ blkid /dev/sda1
/dev/sda1: UUID=”533bef31-8157-4097-895b-e20217fb90a5″ TYPE=”ext3″

UUIDs come in handy when you want to mount certain plug-and-play or hot-swappable disks onto your machine, and you want to customize the response of your Linux box via /etc/fstab. As for me, UUIDs are very important so I don’t have to depend on raw device names anymore. Instead, I just use my devices’ UUIDs so even if I disconnect and connect them again (assuming I don’t format my hard drives/partitions or intentionally change the assigned UUID Ubuntu assigned to them), I basically get the flexibility that I need.

My previous /etc/fstab looked like this:

UUID=fdd0b195-0313-4af7-bbbe-9eb1bed89a64 /home           ext3    defaults        0       2
# /dev/hda3
UUID=b9c011df-1882-4d4c-b215-00ddd7b9bfe0 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec 0       0
/dev/hda5       /media/hda5     ext3    defaults        0       2
/dev/sda1       /media/sda1     ntfs-3g uid=1000,umask=007      0       2
/dev/sda2       /media/sda2     ext3    defaults        0       2
/dev/sdc1       /media/sdc1     vfat    uid=1000,umask=007      0       1
/dev/sdc2       /media/sdc2     ext3    defaults        0       2
/dev/sdc3       /media/sdc3     reiserfs        defaults        0       2
/dev/sdb3       /media/sdb3     ext3    defaults        0       2
/dev/sdb1       /media/sdb1     vfat    uid=1000,umask=007      0       1

Now it looks like this (exactly the same hard drive/partition set up):

UUID=fdd0b195-0313-4af7-bbbe-9eb1bed89a64 /home           ext3    defaults,relatime        0       2
# /dev/hda3
UUID=b9c011df-1882-4d4c-b215-00ddd7b9bfe0 none            swap    sw              0       0
#/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec 0       0
UUID=c3ec0a22-04e8-4735-b6c8-b20e95c2b5a3       /media/hda5     ext3    defaults,relatime       0       2
UUID=71e7e7df-cff4-42ae-a0ec-dddcc6a4dacb       /media/sda1     ext3    defaults,relatime       0       2
UUID=71e7e7df-cff4-42ae-a0ec-dddcc6a4dacb       /media/sda2     ext3    defaults,relatime       0       2
UUID=47AB-8F94  /media/sdc1     vfat    defaults        0       2
UUID=46483822-17f9-408b-a3e2-aad688f8380d       /media/sdc2     ext3    defaults,relatime       0       2
UUID=4c05ec57-4171-42c3-b932-f721edc45f15       /media/sdc3     reiserfs        defaults        0       2
UUID=5e4cab82-808e-43ec-99a6-bb1a6d7f4efd       /media/sdb3     ext3    defaults,relatime       0       2
UUID=BBF7-94B5  /media/sdb1     vfat    uid=1000,umask=007      0       1

Now isn’t that prettier? 😀

I just removed the old raw device names and replaced them with the appropriate UUID (e.g. /dev/hda5 is equal to UUID=c3ec0a22-04e8-4735-b6c8-b20e95c2b5a3 ) , and I didn’t have to change the directory where they should be mounted (my /dev/hda5 is mounted at /media/hda5), saving me a lot of time and effort, since I don’t have to update a lot of things dependent on the directory/path where my hard drives are mounted.

Further Reading

* More info on UUIDs and on administration

* The Linux Documentation Project on Linux devices (IDE/SCSI)


Advertisements

Tags: , , , , , , ,

3 Responses to “UUIDs, Linux devices, and fstab”

  1. Onkel Skrue Says:

    Is is possible to use UUID on a external USB disk. I have one that change the name from time to time so my alias rsync command don’t work.

  2. f241vc15 Says:

    Hi Onkel,
    Yes it is very much possible to use a USB drive’s UUID so you can customize your machine’s response (via fstab for example) when you plug it in. You can use UUIDs like you said, even if you rename the volume name of your disk ever so often. With UUIDs, you won’t have to worry about that anymore.

  3. The Captain’s Log » Blog Archives » Linux fstab and UUIDs Says:

    […] to f241vc15 for pointing me in the right direction. Archived in uuid, fstab, mount, linux | Trackback | […]

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: