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
- Mounting:
- Linking a storage device to a folder in Linux so you can access files.
- Example: Mounting
/dev/sdb1to/dataallows you to use/datato access the disk.
- 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.
- 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>, orLABEL=<label>. - Mount point: directory where the filesystem will be accessible.
- Filesystem type: like
ext4,xfs, orvfat. - 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
- Create a filesystem (if not already done): sudo mkfs.ext4 /dev/sdb1
- Check the UUID or label: sudo blkid /dev/sdb1 Or assign a label while formatting: sudo mkfs.ext4 -L BackupDrive /dev/sdb1
- Create a mount point: sudo mkdir /backup
- Edit
/etc/fstabusing 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 - 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-onlynoatime: donβt update access times (improves performance)nosuid: ignore set-user-ID or set-group-ID bitsnodev: ignore device files
7. Exam Tips
- You should know how to:
- View UUIDs and labels with
blkidorlsblk -f. - Assign labels to filesystems using
-Loption withmkfs. - Edit
/etc/fstabto mount filesystems by UUID or label. - Test
/etc/fstabusingmount -a.
- View UUIDs and labels with
- Understand why UUID/label is safer than device names for boot-time mounts.
8. Quick Reference Commands
| Task | Command |
|---|---|
| View UUIDs & labels | sudo blkid or lsblk -f |
| Create filesystem | sudo mkfs.ext4 /dev/sdb1 |
| Assign label | sudo mkfs.ext4 -L BackupDrive /dev/sdb1 |
| Create mount point | sudo mkdir /backup |
| Edit fstab | sudo nano /etc/fstab |
| Test fstab | sudo 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.
