A short howto for Linux volume labels

You may have noticed from time to time as Linux evolves and device drivers change, the device nodes used to access your hard disks may sometimes change. Besides updating the root device on the kernel command line in your bootloader configuration, you also have to go through your /etc/fstab and make all the appropriate changes. That is assuming you still have a working kernel around…

Easier thing to do is refer to the volumes not by device node, but by LABEL or UUID. Every filesystem is assigned a UUID when it is created, and you can manually assign a human-readable LABEL by using the filesystem tuning tools. Once you have assigned a LABEL and/or UUID, then anywhere you would refer to a /dev/hdXX or /dev/sdXX device, use UUID=… or LABEL=… instead, where … is the actual UUID or LABEL that is assigned.

To set labels for a few filesystems:

ReiserFS: reiserfstune -l <label> /dev/XXXX
EXT2/3: tune2fs -L <label> /dev/XXXX
Swap: mkswap -L <label> /dev/XXXX

To retrieve labels and UUIDs for a few filesystems:

ReiserFS: reiserfstune /dev/XXXX (must be unmounted)
EXT2/3: tune2fs -l /dev/XXXX ("Filesystem volume name", "Filesystem UUID")
Swap: No way to retrieve, just relabel it with mkswap -L

After rebooting you will be able to see the volume labels in /proc/partitions.

Note: Only v1 (“new style”) swap devices can be labeled.

Error behavior

In ext2/ext3, you can also set the error behavior in the superblock so that when a filesystem error is encountered (due to corruption, CPU/memory failure or disk failure), the filesystem will be automatically remounted read-only or the kernel panicked. The default is to continue on errors. This is usually set in the fstab (errors=remount-ro or errors=panic), but it may be more convenient to have the default behavior set in the superblock. Simply issue tune2fs -e remount-ro /dev/hda1 for all your ext2/ext3 filesystems, and you will no longer have to have the verbosity in your /etc/fstab too…

Leave a Reply