Understanding UUIDs
UUID (Universally Unique Identifier) is a 128-bit identifier assigned to file systems at creation time. Linux uses UUIDs to refer to storage devices in /etc/fstab, bootloader configuration, and systemd mount units. The critical reason to use UUIDs instead of device names like /dev/sda1: device names change when you add, remove, or rearrange disks, but a UUID is permanently tied to the file system.
Why UUIDs exist for storage
Problem with device names:
Server with 2 disks: /dev/sda (system) + /dev/sdb (data)
You add a new disk → system now sees it as /dev/sdb (new disk)
→ Old data disk becomes /dev/sdc
→ /etc/fstab entry for /dev/sdb now mounts the WRONG disk!
Solution with UUIDs:
/etc/fstab: UUID=abc-123 → always mounts the specific file system
No matter what device name the OS assigns, the UUID is correct.Finding UUIDs
# Method 1: blkid (most common)
sudo blkid
blkid output
/dev/sda1: UUID="a1b2c3d4-e5f6-7890-abcd-ef1234567890" TYPE="ext4" PARTUUID="..."
/dev/sda2: UUID="12345678-1234-1234-1234-123456789abc" TYPE="swap"
/dev/sdb1: UUID="fedcba98-7654-3210-fedc-ba9876543210" TYPE="xfs" LABEL="data"
# Method 2: ls of symlinks in /dev/disk/by-uuid/
ls -la /dev/disk/by-uuid/
# Method 3: lsblk
lsblk -f
# Get UUID for a specific device
sudo blkid /dev/sdb1
# Get UUID only (for scripting)
sudo blkid -s UUID -o value /dev/sdb1
Using UUIDs in fstab
# Get the UUID
UUID=$(sudo blkid -s UUID -o value /dev/sdb1)
echo $UUID
# Add to /etc/fstab
sudo nano /etc/fstab
/etc/fstab entry using UUID
# UUID format in fstab:
UUID=fedcba98-7654-3210-fedc-ba9876543210 /data xfs defaults,noatime 0 2
# For swap partition:
UUID=12345678-1234-1234-1234-123456789abc none swap sw 0 0
# Test the fstab entry
sudo mount -a
df -h /data
Labels as an alternative
Labels are human-readable alternatives to UUIDs. They are easier to remember but require discipline to keep unique across all disks. UUIDs are always unique (randomly generated), so they are safer.
# Set a label on an ext4 file system
sudo tune2fs -L backups /dev/sdb1
# Set a label on an XFS file system (must be unmounted)
sudo xfs_admin -L backups /dev/sdb1
# Set a label when creating a file system
sudo mkfs.ext4 -L backups /dev/sdb1
sudo mkfs.xfs -L backups /dev/sdb1
# Use label in fstab
# LABEL=backups /backup ext4 defaults 0 2
# List all labels
sudo blkid | grep LABEL
When UUIDs change
UUIDs are assigned at file system creation and do not change in normal operation. They change only when:
- You run
mkfsto reformat the partition (completely new file system) - You clone a disk with a tool that copies the file system (then both disks have the same UUID — a problem)
- You explicitly regenerate the UUID with
tune2fs -U random /dev/sdb1
# Generate a new UUID for an ext4 file system (if cloning caused duplicate UUIDs)
sudo tune2fs -U random /dev/sdb1
sudo blkid /dev/sdb1 # Verify the new UUID
# For XFS (must be unmounted)
sudo xfs_admin -U generate /dev/sdb1
# After changing UUID, update /etc/fstab to use the new UUID
Conclusion
Always use UUIDs in /etc/fstab instead of device names. Device names (sda, sdb) are assigned by the kernel at boot based on device detection order — adding a disk can shift everything around and break mounts that relied on device names. Get the UUID with sudo blkid /dev/sdbX and use the full UUID string in fstab. If you clone a disk, regenerate the UUID on the clone with tune2fs -U random.
FAQ
Is Understanding UUIDs important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support