LFCS 81 🐧 UUID-Based Mounting
A UUID is a 128-bit identifier stored in a filesystem’s metadata, assigned when the filesystem is created. It identifies the filesystem itself, not the device slot it occupies. The /etc/fstab man page states the recommendation directly: UUID= or LABEL= should be used instead of a device name, because device names are “often a coincidence of hardware detection order, and can change when other disks are added or removed” . A system that mounts by /dev/sdb1 may mount the wrong disk after a reboot; a system that mounts by UUID mounts the same filesystem every time.
This chapter covers the UUID-based mounting workflow. It begins with the distinction between the filesystem UUID and the partition UUID, then explains how to find the UUID with blkid and lsblk. It addresses the /etc/fstab entry format, the nofail option that prevents a missing disk from blocking boot, and the verification steps that catch errors before a reboot. The final sections cover the cases where UUID mounting is the wrong choice and the commands that change or regenerate a UUID.
Key point: The UUID belongs to the filesystem, not the partition. Reformatting a partition creates a new UUID, and the old fstab entry will fail to mount.
Why UUID mounting exists
The device name instability problem. The kernel assigns device names like /dev/sda and /dev/sdb based on discovery order. Adding a disk, changing a controller, or moving a disk to a different port can shift the assignment. An fstab entry that points to /dev/sdb1 may point to a different disk on the next boot, and the system may mount the wrong filesystem at the wrong mount point .
The UUID persistence. The UUID is written into the filesystem’s superblock when mkfs runs. It follows the filesystem regardless of which device node the kernel assigns. The only way the UUID changes is if the filesystem is reformatted or the UUID is explicitly modified with a tool like tune2fs or xfs_admin .
The PARTUUID distinction. A partition table (GPT) also stores a partition UUID, called PARTUUID. This identifier belongs to the partition entry, not the filesystem. Reformatting the partition preserves the PARTUUID but creates a new filesystem UUID. If an fstab entry uses PARTUUID= and the partition is reformatted with a different filesystem, the entry may mount the wrong filesystem or fail. The filesystem UUID (UUID=) is the more precise identifier for mounting a filesystem .
The boot safety requirement. A disk that is not present at boot, such as a detached cloud volume or a removable drive, will cause mount -a to fail. Without the nofail option, the failure can drop the system into emergency mode. The nofail option tells the boot process to continue even if the mount fails, which is essential for any non-critical filesystem .
a. Finding the UUID
The two standard tools are blkid and lsblk. blkid queries the block device metadata and prints the UUID, label, and filesystem type for each device. It requires root privileges for a complete listing .
# Show UUID, label, and type for all block devices.
sudo blkid
# Show only the UUID value for a specific device.
sudo blkid -s UUID -o value /dev/sdb1
# Example output:
# /dev/sdb1: UUID="c3d4e5f6-a7b8-9012-cdef-123456789012" TYPE="ext4" LABEL="data"
lsblk presents the same information in a tree view that shows the partition hierarchy. The -f flag includes filesystem information, and -o selects specific columns .
# Tree view with UUID and mount point.
lsblk -f
# Example output:
# NAME FSTYPE LABEL UUID MOUNTPOINT
# sdb ext4 3d7a3861-da22-484e-bbf4-b09375894b4f
# └─sdb1 ext4 data f1645951-134f-4677-b5f4-c65c71f8f86d /mnt/data
The /dev/disk/by-uuid/ directory contains symlinks named by UUID that point to the actual device nodes. This is a useful cross-check when verifying that an fstab entry matches an existing device .
# List the UUID symlinks.
ls -l /dev/disk/by-uuid/
b. The fstab entry and the nofail option
An fstab entry has six fields: the device identifier, the mount point, the filesystem type, the mount options, the dump flag, and the fsck pass number . The UUID form places UUID= in the first field.
# A standard UUID-based entry.
# Fields: device, mount point, type, options, dump, pass.
UUID=c3d4e5f6-a7b8-9012-cdef-123456789012 /mnt/data ext4 defaults,nofail 0 2
The nofail option is the difference between a missing disk and an unbootable system. Without it, a device that is not present at boot causes mount -a to fail, and the boot process may stop. With it, the mount is skipped and the boot continues . The option should be applied to any filesystem that is not required for the system to function. It should not be applied to the root filesystem.
For cloud instances and removable media, the nofail option is effectively mandatory. A detached volume or an unplugged drive should not prevent the system from starting.
c. Verification and the UUID change case
The verification step is mount -a, which reads fstab and attempts every mount that is not already active. If the entry is syntactically correct and the UUID matches an existing filesystem, the mount succeeds. If the UUID is wrong or the mount point does not exist, the command reports an error .
# Test all fstab entries.
sudo mount -a
# Confirm the mount.
findmnt /mnt/data
df -hT /mnt/data
A UUID changes when the filesystem is reformatted. If /dev/sdb1 is reformatted with mkfs.ext4, the new filesystem receives a new UUID, and the old fstab entry will fail to mount. The fix is to re-run blkid and update the entry . The UUID can also be changed deliberately with tune2fs -U for ext filesystems or xfs_admin -U for XFS, which is useful for cloning or restoring a filesystem that should keep its identity .
The PARTUUID alternative exists for cases where the filesystem UUID is not available, such as when the partition is used as a container for LVM or encryption. In those cases, the filesystem UUID is on the logical volume, not the partition, and PARTUUID or the LVM device path is the correct identifier .
Complete Example Session
# ============================================
# PART 1: IDENTIFY THE DEVICE
# ============================================
# List block devices and find the target partition.
lsblk -f
# ============================================
# PART 2: GET THE UUID
# ============================================
# Read the UUID from the filesystem metadata.
sudo blkid /dev/sdb1
# Example: UUID="f1645951-134f-4677-b5f4-c65c71f8f86d" TYPE="ext4"
# ============================================
# PART 3: CREATE THE MOUNT POINT
# ============================================
# The directory must exist before mounting.
sudo mkdir -p /mnt/data
# ============================================
# PART 4: BACK UP FSTAB
# ============================================
# Always back up before editing.
sudo cp /etc/fstab /etc/fstab.bak
# ============================================
# PART 5: ADD THE ENTRY
# ============================================
# UUID, mount point, type, options, dump, pass.
# Edit /etc/fstab and add:
# UUID=f1645951-134f-4677-b5f4-c65c71f8f86d /mnt/data ext4 defaults,nofail 0 2
# ============================================
# PART 6: TEST WITHOUT REBOOT
# ============================================
# mount -a reads fstab and mounts what is not mounted.
sudo mount -a
# ============================================
# PART 7: VERIFY
# ============================================
# Confirm the mount and the source.
findmnt /mnt/data
df -hT /mnt/data
# ============================================
# PART 8: THE FAILURE CASE
# ============================================
# If the UUID is wrong or the disk is missing:
# mount: /mnt/data: can't find UUID=...
# With nofail, the boot continues and the mount is skipped.
# ============================================
# PART 9: THE REFORMAT CASE
# ============================================
# Reformatting creates a new UUID. The old entry fails.
# Re-run blkid and update the fstab entry.
# ============================================
# PART 10: THE FULL PICTURE
# ============================================
# UUID identifies the filesystem, not the device slot.
# nofail prevents a missing disk from blocking boot.
# mount -a is the test that matters.
echo "UUID mount workflow complete."
The ten parts walk through the full workflow: identify, get the UUID, create the mount point, back up, add the entry, test with mount -a, verify, and handle the failure cases. The sequence is the same for any filesystem type; only the blkid output and the fstab type field change.
Quick Reference
UUID Commands
| Command | Purpose |
|---|---|
sudo blkid | Show UUIDs for all block devices |
sudo blkid /dev/sdb1 | Show UUID for one device |
sudo blkid -s UUID -o value /dev/sdb1 | Print only the UUID value |
lsblk -f | Tree view with UUID and mount point |
ls -l /dev/disk/by-uuid/ | UUID symlinks to device nodes |
fstab Fields
| Field | Example | Meaning |
|---|---|---|
| Device | UUID=... | Filesystem identifier |
| Mount point | /mnt/data | Directory to attach |
| Type | ext4 | Filesystem type |
| Options | defaults,nofail | Mount options |
| Dump | 0 | Backup flag (obsolete) |
| Pass | 2 | fsck order |
UUID vs PARTUUID
| Identifier | Belongs To | Survives Reformat | fstab Prefix |
|---|---|---|---|
| UUID | Filesystem | No (new UUID) | UUID= |
| PARTUUID | Partition table | Yes | PARTUUID= |
| LABEL | Filesystem | Yes (if set) | LABEL= |
Verification
| Step | Command | Expected |
|---|---|---|
| Test fstab | sudo mount -a | No errors |
| Confirm mount | findmnt /mnt/data | Shows device and options |
| Confirm source | df -hT /mnt/data | Correct UUID/device |
Best Practices
✅ Do This:
# Use UUID, not device name, in fstab.
UUID=xxxx /mnt/data ext4 defaults,nofail 0 2 # ✅
# Add nofail to non-critical mounts.
UUID=xxxx /mnt/data ext4 defaults,nofail 0 2 # ✅
# Test with mount -a before rebooting.
sudo mount -a # ✅
# Back up fstab before editing.
sudo cp /etc/fstab /etc/fstab.bak # ✅
❌ Don’t Do This:
# Don't use device names in fstab.
/dev/sdb1 /mnt/data ext4 defaults 0 2 # may change on reboot # ❌
# Don't add nofail to the root filesystem.
UUID=xxxx / ext4 defaults,nofail 0 1 # root must fail if absent # ❌
# Don't use an old UUID after reformatting.
UUID=old-uuid /mnt/data ext4 defaults 0 2 # mount fails # ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| “can’t find UUID” at boot | Wrong UUID or reformatted filesystem | Re-run blkid and update the entry |
| System drops to emergency mode | Missing device without nofail | Add nofail |
| Wrong filesystem mounted | Device name changed | Switch to UUID= |
| Mount point does not exist | Directory not created | mkdir -p before mount -a |
| UUID changes after clone | Filesystem was recreated | Set the UUID with tune2fs -U or xfs_admin -U |
Real-World Examples
1. Get UUID
sudo blkid /dev/sdb1
2. UUID fstab Entry
UUID=xxxx /mnt/data ext4 defaults,nofail 0 2
3. Test fstab
sudo mount -a
4. Verify Mount
findmnt /mnt/data
5. List All UUIDs
lsblk -f
6. UUID Symlinks
ls -l /dev/disk/by-uuid/
7. PARTUUID Entry
PARTUUID=xxxx /mnt/data ext4 defaults 0 2
8. Change ext4 UUID
sudo tune2fs -U $(uuidgen) /dev/sdb1
9. Change XFS UUID
sudo xfs_admin -U $(uuidgen) /dev/sdb1
10. Backup fstab
sudo cp /etc/fstab /etc/fstab.bak
Visual
Device Name vs UUID
┌─────────────────────────────────────────────────────────┐
│ BOOT 1 │
│ sda = disk0, sdb = disk1 → /dev/sdb1 = disk1 │
│ │
│ BOOT 2 (disk order changed) │
│ sda = disk1, sdb = disk0 → /dev/sdb1 = disk0 │
│ │
│ fstab: /dev/sdb1 /mnt/data → mounts the WRONG disk. │
│ │
│ ───────────────────────────────────────────────────── │
│ │
│ UUID follows the filesystem, not the slot. │
│ fstab: UUID=abcd-1234 /mnt/data → always disk1. │
└─────────────────────────────────────────────────────────┘
The fstab Fields
┌─────────────────────────────────────────────────────────┐
│ UUID=abcd-1234 /mnt/data ext4 defaults,nofail 0 2│
│ │ │ │ │ │ ││
│ │ │ │ │ │ └─ pass
│ │ │ │ │ └──── dump
│ │ │ │ └─────────────────── opts
│ │ │ └─────────────────────────── type
│ │ └──────────────────────────────────── mnt
│ └──────────────────────────────────────────────────── device
└─────────────────────────────────────────────────────────┘
The nofail Difference
┌─────────────────────────────────────────────────────────┐
│ WITHOUT nofail │
│ Disk missing at boot → mount fails → emergency mode │
│ │
│ WITH nofail │
│ Disk missing at boot → mount skipped → boot continues │
└─────────────────────────────────────────────────────────┘
UUID vs PARTUUID
┌─────────────────────────────────────────────────────────┐
│ PARTITION TABLE (GPT) │
│ ┌───────────────────────────────────────────────────┐ │
│ │ Partition entry │ │
│ │ PARTUUID = 4cd1448a-01 ← survives reformat │ │
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ FILESYSTEM (ext4) │ │ │
│ │ │ UUID = abcd-1234 ← changes on reformat │ │ │
│ │ └─────────────────────────────────────────────┘ │ │
│ └───────────────────────────────────────────────────┘ │
│ │
│ UUID= identifies the filesystem. │
│ PARTUUID= identifies the partition. │
└─────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| UUID | 128-bit filesystem identifier |
| Stored in | Filesystem metadata (superblock) |
| Find with | blkid, lsblk -f |
| fstab prefix | UUID= |
| fstab fields | device, mount point, type, options, dump, pass |
| Boot safety | nofail |
| Verification | mount -a, findmnt |
| UUID change | Reformat or tune2fs -U / xfs_admin -U |
| PARTUUID | Partition-level, survives reformat |
Key takeaways:
- UUID identifies the filesystem, not the device. Device names depend on discovery order and can change. The UUID is written at
mkfstime and follows the filesystem . blkidandlsblk -fare the tools for finding the UUID.blkidprints the raw value;lsblk -fshows it in the device tree .- The
nofailoption is essential for non-critical mounts. Without it, a missing disk can prevent the system from booting. With it, the mount is skipped and the boot continues . mount -ais the test. It readsfstaband attempts every mount, catching syntax errors and wrong UUIDs before a reboot .- Reformatting changes the UUID. The old
fstabentry will fail. Re-runblkidand update the entry, or set a known UUID withtune2fs/xfs_admin. - PARTUUID is the partition-level alternative. It survives reformatting but identifies the partition, not the filesystem. Use
UUID=for filesystems,PARTUUID=when the filesystem UUID is not accessible .
Remember: The fstab file is read at boot. A device name in the first field is a bet that the kernel will assign the same name it did last time. That bet is lost when a disk is added, removed, or moved. The UUID is the identifier that does not depend on the bet. Use blkid to find it, UUID= to write it, nofail to protect the boot, and mount -a to prove it before the next reboot.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!