| |

LFCS 81 🐧 UUID-Based Mounting

⏱️ Estimated read: 11 min | |

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

CommandPurpose
sudo blkidShow UUIDs for all block devices
sudo blkid /dev/sdb1Show UUID for one device
sudo blkid -s UUID -o value /dev/sdb1Print only the UUID value
lsblk -fTree view with UUID and mount point
ls -l /dev/disk/by-uuid/UUID symlinks to device nodes

fstab Fields

FieldExampleMeaning
DeviceUUID=...Filesystem identifier
Mount point/mnt/dataDirectory to attach
Typeext4Filesystem type
Optionsdefaults,nofailMount options
Dump0Backup flag (obsolete)
Pass2fsck order

UUID vs PARTUUID

IdentifierBelongs ToSurvives Reformatfstab Prefix
UUIDFilesystemNo (new UUID)UUID=
PARTUUIDPartition tableYesPARTUUID=
LABELFilesystemYes (if set)LABEL=

Verification

StepCommandExpected
Test fstabsudo mount -aNo errors
Confirm mountfindmnt /mnt/dataShows device and options
Confirm sourcedf -hT /mnt/dataCorrect 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

PitfallWhy It HappensFix
“can’t find UUID” at bootWrong UUID or reformatted filesystemRe-run blkid and update the entry
System drops to emergency modeMissing device without nofailAdd nofail
Wrong filesystem mountedDevice name changedSwitch to UUID=
Mount point does not existDirectory not createdmkdir -p before mount -a
UUID changes after cloneFilesystem was recreatedSet 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

ItemValue
UUID128-bit filesystem identifier
Stored inFilesystem metadata (superblock)
Find withblkid, lsblk -f
fstab prefixUUID=
fstab fieldsdevice, mount point, type, options, dump, pass
Boot safetynofail
Verificationmount -a, findmnt
UUID changeReformat or tune2fs -U / xfs_admin -U
PARTUUIDPartition-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 mkfs time and follows the filesystem .
  • blkid and lsblk -f are the tools for finding the UUID. blkid prints the raw value; lsblk -f shows it in the device tree .
  • The nofail option 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 -a is the test. It reads fstab and attempts every mount, catching syntax errors and wrong UUIDs before a reboot .
  • Reformatting changes the UUID. The old fstab entry will fail. Re-run blkid and update the entry, or set a known UUID with tune2fs/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.


Was this helpful?


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!