crotchety
adj - subject to whims, crankiness, or ill temper

I use Gentoo Linux both at home and at work. Every so often I hit some snag and I'd like to detail the fix here both for my benefit and to possibly help anyone else having a similar issue.

Friday, January 25, 2008

The mystical UUID

Every filesystem (partition?) should have a uuid. On modern Linux systems you can see them with the following command:
# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2008-01-25 19:44 c2ceffb9-90be-4564-a946-9d37de7725ba -> ../../hdg2
UUIDs, while a bit cumbersome to look at, are extremely nice because you can use them in a lot of places instead of a normal device name (such as /dev/hdg2 in the above example).

Tonight I moved the 2 hard drives I had plugged into the onboard IDE controller of my motherboard into a Promise Ultra100 card. Because of this, the kernel renamed the partitions from /dev/hda and /dev/hdc to /dev/hde/ and /dev/hdg. Upon booting the system I saw the following:
swapon: cannot canonicalize /dev/hda2: No such file or directory
swapon: cannot stat /dev/hda2: No such file or directory
swapon: cannot canonicalize /dev/hdc2: No such file or directory
swapon: cannot stat /dev/hdc2: No such file or directory
UUIDs will help this to never happen again.

Here are the relevant lines from my old /etc/fstab:
/dev/hda2   none    swap    sw,pri=1    0 0
/dev/hdc2 none swap sw,pri=1 0 0
And the new lines:
UUID=fe6bffd9-5b6b-4db9-8929-cf1575a72d67   none    swap    sw,pri=1    0 0
UUID=e2992cf5-bc3a-4b3a-a920-d9dfbe7a5a9a none swap sw,pri=1 0 0
As I said, it doesn't look as pretty, but look what happens with the old /etc/fstab:
#swapon -a
# cat /proc/swaps
Filename Type Size Used Priority
and the new:
# swapon -a
erma ~ # cat /proc/swaps
Filename Type Size Used Priority
/dev/hde2 partition 1004052 0 1
/dev/hdg2 partition 1004052 0 1
If you haven't figured it out by now, by specifying partitions by UUID, you remove the dependency on where they are physically plugged into the motherboard and any kernel naming conventions. I recently had my SATA drives move around a bit after a BIOS update, so UUIDs would help out there as well.

As it happens I had some trouble finding the (correct) UUID of one of my swap partitions but that's the topic of my next post.

No comments: