The device node name of a disk (/dev/sda, /dev/hda, /dev/vda, etc.) may change in some situations. For example, after switching cables around or upgrading certain packages, sda & sdc could swap places. This causes problems when /etc/fstab references filesystems by the disk names. Instead, we can use filesystem labels to refer them in /etc/fstab file. This allows us for identifying a filesystem without resorting to ephemeral block device names.
Check the current Label of the filesystem
1. To find out the label of the filesystem, you can use the “blkid” command as showb below.
# blkid /dev/sda1 /dev/sda1: LABEL="/boot" UUID="c9fdb384-19ed-4b94-b29e-23f0f566e970" TYPE="ext4"
2. You can also determine which filesystem in /etc/fstab file are referenced by their LABELs instead of actual device names. For example:
# cat /etc/fstab LABEL="/boot" /boot ext4 defaults 1 2 UUID="80a27dc2-c309-4cc8-9ceb-3bb1a055cf3d" /data ext4 defaults 0 2
3. Additionally, you can also verify the kernel args line in /etc/grub.conf for any use of non-LVM device node names.
# grep kernel /etc/grub.conf kernel /vmlinuz-2.6.18-308.el5 ro root=/dev/vda2
Changing the Filesystem Labels Online
The e2label command can be used to set/change labels on ext2, ext3, and ext4 filesystems. The syntax to use the command is simple:
# e2label Usage: e2label device [newlabel]
For example, to change the lable of the partition /dev/sda1 to /boot, use the below command:
# e2label /dev/sda1 /boot
When modifying existing labels, make sure to update any references to the old labels in /etc/fstab and /etc/grub.conf and modify them accordingly.
# grep LABEL /etc/grub.conf kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/
# grep LABEL /etc/fstab LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2
A note about swap devices
To add/change labels to swap partitions, they must be turned off with “swapoff [DEVICE]” and remade with “mkswap -L [LABEL] [DEVICE]” before being turned back on with “swapon [DEVICE]”. Swap UUIDs are only possible in RHEL6 and above. See the mkswap man page for more details.
# man mkswap