Always use a block device label or its UUID in fstab

If there are still references to device nodes for block devices, as they are set by the kernel, for example /dev/hda, in /etc/fstab, you should seriously consider replacing them with the volume’s label or its UUID. Even if you use an LVM setup, the /boot partition shouldn’t be referenced by its device node.

My server boots from a 32MB Compact Flash card, attached to CF-to-IDE converter. The card contains only the boot manager (GRUB) in its Master Boot Record (MBR). The system’s main hard disk is attached to a PCI ATA 133 controller. This particular setup is necessary because the old motherboard cannot boot directly from hard disks connected to the PCI-based IDE controller. Until Fedora 9, the CF card was recognized as hdb/sdb and the hard disk on the PCI controller as hda/sda. Today, I upgraded the server to Fedora 10. The CF card is now recognised as /dev/sda. You can imagine my surprise when I rebooted the machine after having upgraded the system only to realize that it actually tried to find the /boot partition on the CF card instead of the main hard disk.

To be able to correct things I had to boot using a Fedora 9 kernel in order to make any changes to the files and get rid of this issue. What was needed was to stop using device names in fstab, but use UUIDs instead. To get the UUID for a particular block device, for example /dev/sda1, I ran as root:

# blkid /dev/sda1
/dev/sda1: LABEL="/boot" UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext3"

Now replace the device node name in /etc/fstab to read:

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx    /boot    ext3    defaults    1 2

Of course, I could have used the label of that partition, but I guess UUIDs are more unique and therefore preferred.

Always use a block device label or its UUID in fstab by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2009 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of the G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.