Configure systems to mount file systems at boot by universally unique ID (UUID) or label

5. Configure Local Storage

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


In Linux, when you create a storage device (like a hard drive, SSD, or logical volume), you often need the system to automatically mount it every time it boots. This is done by configuring mount points in the /etc/fstab file. However, disks and partitions can sometimes change their device names (like /dev/sda1, /dev/sdb1), especially if new drives are added. To avoid problems, Linux allows mounting by UUID (Universally Unique Identifier) or by label, which are stable identifiers that don’t change even if the device name does.

Let’s break this down step by step.


1. Understanding the Key Terms

  1. Mounting:
    • Linking a storage device to a folder in Linux so you can access files.
    • Example: Mounting /dev/sdb1 to /data allows you to use /data to access the disk.
  2. UUID (Universally Unique Identifier):
    • A unique 128-bit identifier assigned to a filesystem when it is created.
    • Example: UUID=3f1b2e8c-7a3f-4c5d-82a0-1c2e3d4f5g6h
    • Always stays the same for that filesystem, even if device names change.
  3. Label:
    • A human-readable name you can assign to a filesystem.
    • Example: LABEL=BackupDrive
    • Easier to remember than UUID, but also stable across reboots.

2. Why Use UUID or Label Instead of Device Names

Device names like /dev/sda1 can change if:

  • You add new drives.
  • Hardware order changes.
  • You reboot with a different storage configuration.

Using UUIDs or labels ensures that the correct filesystem always mounts, regardless of device naming changes. This is critical in production systems to prevent mounting the wrong disk.


3. Viewing UUIDs and Labels

Linux provides commands to check UUIDs and labels:

  • Using blkid: sudo blkid Output example: /dev/sda1: UUID=”3f1b2e8c-7a3f-4c5d-82a0-1c2e3d4f5g6h” TYPE=”ext4″ LABEL=”DataDrive”
    /dev/sdb1: UUID=”9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d” TYPE=”xfs” LABEL=”BackupDrive”
  • Using lsblk -f: lsblk -f Shows a tree of storage devices with filesystem type, UUID, and labels.

4. Mounting by UUID or Label in /etc/fstab

The /etc/fstab file tells Linux what filesystems to mount at boot. Each line has this format:

<device>  <mount_point>  <filesystem_type>  <options>  <dump>  <pass>
  • Device: can be /dev/sda1, UUID=<uuid>, or LABEL=<label>.
  • Mount point: directory where the filesystem will be accessible.
  • Filesystem type: like ext4, xfs, or vfat.
  • Options: mount options, e.g., defaults, noatime.
  • Dump & Pass: backup and fsck options, usually 0 2.

Example using UUID:

UUID=3f1b2e8c-7a3f-4c5d-82a0-1c2e3d4f5g6h  /data  ext4  defaults  0  2

Example using Label:

LABEL=BackupDrive  /backup  xfs  defaults  0  2

5. Steps to Configure Automatic Mounting

  1. Create a filesystem (if not already done): sudo mkfs.ext4 /dev/sdb1
  2. Check the UUID or label: sudo blkid /dev/sdb1 Or assign a label while formatting: sudo mkfs.ext4 -L BackupDrive /dev/sdb1
  3. Create a mount point: sudo mkdir /backup
  4. Edit /etc/fstab using UUID or label: sudo nano /etc/fstab Add the line: UUID=3f1b2e8c-7a3f-4c5d-82a0-1c2e3d4f5g6h /backup ext4 defaults 0 2 Or: LABEL=BackupDrive /backup ext4 defaults 0 2
  5. Test the configuration without rebooting: sudo mount -a This mounts all filesystems from /etc/fstab. If there are errors, Linux will display them.

6. Mount Options Overview

  • defaults: uses default mount options (read/write, auto-mount, etc.)
  • ro: mount read-only
  • noatime: don’t update access times (improves performance)
  • nosuid: ignore set-user-ID or set-group-ID bits
  • nodev: ignore device files

7. Exam Tips

  • You should know how to:
    • View UUIDs and labels with blkid or lsblk -f.
    • Assign labels to filesystems using -L option with mkfs.
    • Edit /etc/fstab to mount filesystems by UUID or label.
    • Test /etc/fstab using mount -a.
  • Understand why UUID/label is safer than device names for boot-time mounts.

8. Quick Reference Commands

TaskCommand
View UUIDs & labelssudo blkid or lsblk -f
Create filesystemsudo mkfs.ext4 /dev/sdb1
Assign labelsudo mkfs.ext4 -L BackupDrive /dev/sdb1
Create mount pointsudo mkdir /backup
Edit fstabsudo nano /etc/fstab
Test fstabsudo mount -a

βœ… Summary

Using UUIDs or labels in /etc/fstab ensures that Linux always mounts the correct filesystem, even if device names change. This is crucial for stable systems and is an essential skill for the DevNet Associate exam. The steps involve finding the UUID or label, creating a mount point, editing /etc/fstab, and testing.

This covers everything you need to know for this exam section.

Buy Me a Coffee