Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.


RHCSA - Configure Local Storage: Configure Systems to Mount File Systems at Boot by Universally Unique ID (UUID) or Label

In this lesson we will go through how to automatically mount file systems at boot time and how this can be achieved using UUIDs and labels.

Lesson Setup

To actively participate in the exercises, make sure to attach an additional empty disk to your system. While the exercises assume that the additional disk is 1G in size, feel free to use whatever disk size is available to you.

Do not use a disk with data on as following the exercises will mean that data will be deleted.

Once the disk is attached, you should be able to see it by running the lsblk command, which in this example shows as the sdb device:

After rebooting, the disk may not retain the same device name, making it essential to always run lsblk to verify that you are working with the correct disk.

$ lsblk

NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda              8:0    0   20G  0 disk 
├─sda1           8:1    0  600M  0 part /boot/efi
├─sda2           8:2    0    1G  0 part /boot
└─sda3           8:3    0   17G  0 part 
  ├─os_vg-root 253:0    0   15G  0 lvm  /
  └─os_vg-swap 253:1    0    2G  0 lvm  [SWAP]
sdb              8:16   0    1G  0 disk

You will now need to create a logical volumes using the /dev/sdb device so that you can practice mounting, adding labels, viewing labels and viewing UUIDs.

Wipe the /dev/sdb disk clean if it has been used in previous lesson:

sudo wipefs --all /dev/sdb*
sudo sed -i '/\/dev\/sdb/d' /etc/lvm/devices/system.devices

Create volume group boot_vg using disk /dev/sdb:

sudo vgcreate boot_vg /dev/sdb
Physical volume "/dev/sdb" successfully created.
Volume group "boot_vg" successfully created

Confirm the volume group exists:

sudo vgs
VG      #PV #LV #SN Attr   VSize    VFree
boot_vg   1   0   0 wz--n- 1020.00m 1020.00m

Create a logical volume of size 100MB called label_lv within volume group boot_vg:

sudo lvcreate -L 100MB -n label_lv boot_vg 
Logical volume "label_lv" created.

Confirm the logical volume was created using lvs:

sudo lvs

The output shows the volume group of the logical volume and the size of the logical volume:

LV       VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
label_lv boot_vg -wi-a----- 100.00m

Create a second logical volume of size 200MB called uuid_lv within volume group boot_vg:

sudo lvcreate -L 200MB -n uuid_lv boot_vg 
Logical volume "uuid_lv" created.

Confirm the logical volume was created using lvs:

sudo lvs

The output shows there are now two logical volumes present:

LV       VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
label_lv boot_vg -wi-a----- 100.00m
uuid_lv  boot_vg -wi-a----- 200.00m

Add filesystem to logical volumes:

sudo mkfs -t ext4 /dev/mapper/boot_vg-label_lv
sudo mkfs -t xfs /dev/mapper/boot_vg-uuid_lv

Identify Device UUIDs & Labels / Set Device Labels

UUID (Universally Unique Identifier) and labels are used to uniquely identify and name storage devices. UUID is typically a 128-bit number assigned to devices during creation, ensuring global uniqueness and consistency across systems. It remains constant even if devices are moved or connections changed. On the other hand, labels are human-readable names given to devices, providing a more user-friendly way to identify them. While UUIDs ensure unique identification, labels simplify device referencing and management for users, making both valuable in different scenarios.

To identify a devices UUID and Label (if present), you use the blkid command.

Identify the UUID of the logical volumes label_lv & uuid_lv:

sudo blkid /dev/mapper/boot_vg-label_lv /dev/mapper/boot_vg-uuid_lv

The output will look similar to:

/dev/mapper/boot_vg-label_lv: UUID="6d5beca5-0902-432e-8f36-c78320aa3c7d" TYPE="ext4"
/dev/mapper/boot_vg-uuid_lv: UUID="6dddbb43-1b27-4ed9-aed7-6ac293023087" TYPE="xfs"

Notice how there is no label present by default.

To set a Label on the logical volumes you use a different command depending on the file system type. The e2label command is used to label ext2, ext3 & ext4 file systems, whilst the xfs_admin -L command is used to label an xfs file system.

Set & view label for ext4 logical volume label_lv:

Set the label as label_one:

sudo e2label /dev/mapper/boot_vg-label_lv label_one

Confirm the label is now present for the device:

sudo blkid /dev/mapper/boot_vg-label_lv
/dev/mapper/boot_vg-label_lv: LABEL="label_one" UUID="6d5beca5-0902-432e-8f36-c78320aa3c7d" TYPE="ext4"

Set & view label for xfs logical volume uuid_lv:

Set the label as label_two:

sudo xfs_admin -L label_two /dev/mapper/boot_vg-uuid_lv

Command should output similar to:

writing all SBs
new label = "label_two"

Confirm the label is now present for the device:

sudo blkid /dev/mapper/boot_vg-uuid_lv
/dev/mapper/boot_vg-uuid_lv: LABEL="label_two" UUID="6dddbb43-1b27-4ed9-aed7-6ac293023087" TYPE="xfs"

Mount File Systems at Boot by UUID & Label

Mount Points

For a device, partition or logical volume to be mounted, you need to create a mount point. This is just an empty directory that you create, typically under the /mnt directory.

Create mount points for label_lv & uuid_lv logical volumes to be mounted on:

sudo mkdir -p /mnt/{label,uuid}

/etc/fstab File

The /etc/fstab file defines file systems and their associated mount points. It ensures automatic mounting of devices during system startup (boot), allowing consistent and reliable access to data. Each entry in /etc/fstab specifies the device, mount point directory, filesystem type, and mount options.

The below table lists the fields found in the /etc/fstab file:

Field Description
Device The block device or filesystem to be mounted.
Mount Point The directory where the filesystem will be mounted.
Filesystem Type The type of filesystem (e.g., ext4, xfs, ntfs, nfs, etc.).
Mount Options Options specifying how the filesystem should be mounted.
Dump Used by the dump utility to determine if the filesystem needs to be backed up.
Pass Used by the fsck utility to determine the order of filesystem checks during boot.

Each line in the /etc/fstab file contains these fields, separated by spaces or tabs, defining a different filesystem entry.

The below exercise will get you adding entries into the /etc/fstab:

Add an entry into /etc/fstab using the label in the device field:

Determine label for logical volume label_lv:

sudo blkid /dev/mapper/boot_vg-label_lv

Label shows as label_one:

/dev/mapper/boot_vg-label_lv: LABEL="label_one" UUID="6d5beca5-0902-432e-8f36-c78320aa3c7d" TYPE="ext4"

Add an entry into /etc/fstab to mount logical volume label_lv using its label:

echo "LABEL=label_one /mnt/label ext4 defaults 0 0" | sudo tee -a /etc/fstab

Update systemd units generated from the /etc/fstab file:

sudo systemctl daemon-reload

Verify the added /etc/fstab is ok:

sudo findmnt --verify /dev/mapper/boot_vg-label_lv

It should show no errors:

Success, no errors or warnings detected

Add an entry into /etc/fstab using the UUID in the device field:

Determine UUID for logical volume uuid_lv:

sudo blkid /dev/mapper/boot_vg-uuid_lv

UUID shows as 6dddbb43-1b27-4ed9-aed7-6ac293023087:

/dev/mapper/boot_vg-uuid_lv: LABEL="label_two" UUID="6dddbb43-1b27-4ed9-aed7-6ac293023087" TYPE="xfs"

Add an entry into /etc/fstab to mount logical volume uuid_lv using its UUID:

echo "UUID="6dddbb43-1b27-4ed9-aed7-6ac293023087" /mnt/uuid xfs defaults 0 0" | sudo tee -a /etc/fstab

Update systemd units generated from the /etc/fstab file:

sudo systemctl daemon-reload

Verify the added /etc/fstab is ok:

sudo findmnt --verify /dev/mapper/boot_vg-uuid_lv

It should show no errors:

Success, no errors or warnings detected

Verify Mounts Work at Boot

You will want to ensure that after rebooting the system that your devices have mounted automatically.

In the previous exercises you used the findmnt --verify command. If this returned errors, ensure they are resolved before rebooting as you may cause boot failures otherwise:

Reboot the system then verify devices are mounted:

Reboot system:

sudo reboot

Following the reboot, use the df command to see if the logical volumes are mounted:

df -h /dev/mapper/boot*

Output should be similar to:

Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/boot_vg-label_lv   89M   14K   82M   1% /mnt/label
/dev/mapper/boot_vg-uuid_lv   195M   12M  184M   6% /mnt/uuid

Lesson Tidy Up

Ensure you unmount the partitions, remove entries from /etc/fstab and clean the disk.

Wipe the /dev/sdb disk clean if it has been used in previous lesson:

Unmount logical volumes:

sudo umount -v /mnt/{uuid,label}
umount: /mnt/label unmounted
umount: /mnt/uuid unmounted

Remove entries from /etc/fstab

sudo sed -i.$(date +%Y%m%d%H%M) '/\/mnt\/uuid/d;/\/mnt\/label/d' /etc/fstab

Remove logical volumes and volume groups:

sudo vgremove -y boot_vg
Logical volume "label_lv" successfully removed.
Logical volume "uuid_lv" successfully removed.
Volume group "boot_vg" successfully removed

Remove physical volume:

sudo pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped.

Remove entry from system.devices file:

sudo sed -i '/\/dev\/sdb/d' /etc/lvm/devices/system.devices

Wipe all remaining data from disk:

sudo wipefs --all /dev/sdb
sudo dd if=/dev/zero of=/dev/sdb bs=1M
dd: error writing '/dev/sdb': No space left on device
1025+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.502 s, 715 MB/s

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.