Linux disk labels

For a long time I have known that it was bad to "hardwire" device specifications such as /dev/sda3 in the fstab file and elsewhere. But I figured that disk labels were too much of a hassle, so I did it anyway.

Just recently, I finally (after many years!) got bit by this. On one system I have a flakey USB flash card reader. Usually it works, and gets configured as /dev/sda (and sdb, sdc, sdd). This causes my SATA hard drive to be configured as /dev/sde. But, when the USB reader flakes out, the SATA drive becomes /dev/sda and my system won't boot. And after I hand edit the /etc/fstab file (and delete /etc/mtab), then the USB reader starts working, and again I can't boot.

Of course, it might be reasonable to eliminate or replace the USB card reader. However, I decided it was a time to learn how to use disk labels, and here is what I found out (it was not all that hard).

There are two things you can use, either a label or a UUID. I decided to use the UUID, because my disk partitions already have them, and it is just a matter of finding out what they are and putting this info into the /etc/fstab file. You find out like this:

blkid /dev/sda7
In column 1 of the fstab, you replace the /dev/sda7 with the UUID=xxxxxxxxxxx and there you go.

If you do want to use labels, these will only work for ext3 or ext4 partitions and are handled by the e2label utility as follows:

e2label /dev/sda7
e2label -L ROOT /dev/sda7
The first command above displays the current label, the second command sets a label. My disks already were labeled (with labels like "/" and "/boot"), but I decided to not set new labels, and also not to use these at all. What convinced me was that I had non-linux partitions and the UUID would serve for those, while the LABEL would not. Also, it always makes me nervous to fiddle with filesystem control information on a system with important data. If you use labels, you use lines like LABEL=/boot in the fstab file. Also you may want to use labels or UUID strings in the grub.conf file.
Have any comments? Questions? Drop me a line!

Adventures in Computing / tom@mmto.org