CentOS / RHEL : How to mount filesystems using UUID

The device can be identified by a full path to a block device (for example, /dev/sda3) , a universally unique identifier (UUID; for example, UUID=3bf2d836-be7d-4e69-a1ff-4ffd2661edcf) , or a volume label (for example, LABEL=home). 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.

Note : UUIDs and labels are not required if a filesystem resides on an LVM logical volume, as in default RHEL installations.

1. Determine the UUID of a Particular Device.

# blkid /dev/sdb1
/dev/sdb1: UUID="3bf2d836-be7d-4e69-a1ff-4ffd2661edcf" TYPE="ext4"

2. Edit the /etc/fstab file and change the device path with the UUID of the file system, for example:

# vi /etc/fstab
UUID=3bf2d836-be7d-4e69-a1ff-4ffd2661edcf    /home                   ext4    defaults        1 2

3. During the next reboot of the computer, the filesystem will be mounted using the UUID.

Conclusion

It is not safe to use block device node names like /dev/sda1 and /dev/vdb2 to refer to filesystems in /etc/fstab. Instead, use filesystem UUIDs (universally unique identifiers) or labels. Either of these allow for identifying a filesystem without resorting to ephemeral block device names.

Related Post