All articles

Identify Linux disks by UUID

4 minutes read


Linux publication

Share this article

𝕏✉

Illustration for Identify Linux disks by UUID

Names such as /dev/sda2 describe device discovery, not permanent identity. Hardware order can change after a reboot, controller change, or new disk installation. Before touching /etc/fstab or replacing storage, map the live path to identifiers that describe the filesystem or partition you actually mean.

Build an explicit inventory

lsblk --output \
  NAME,KNAME,TYPE,SIZE,FSTYPE,LABEL,UUID,PARTUUID,MOUNTPOINTS

Always request columns in scripts. The default lsblk output is intended for humans and can change. MOUNTPOINTS also matters because one filesystem can be mounted at more than one location.1

If a device has just appeared and metadata looks incomplete, let udev finish first:

udevadm settle
lsblk --fs

lsblk combines sysfs and udev information, so timing can affect what it displays immediately after a device event.1

Ask blkid for filesystem metadata

sudo blkid
sudo blkid /dev/nvme0n1p2

blkid reports attributes found by probing block devices, including filesystem type, label, UUID, and partition UUID where available. Non-root output may rely on cached information, while low-level probing generally requires privileges.2

The identifiers are not interchangeable:

  • UUID normally identifies a filesystem.
  • PARTUUID identifies a partition table entry.
  • LABEL is readable but may not be unique.
  • /dev/disk/by-id/ names are useful when the identity of the physical device matters.

Cross-check the path you care about

findmnt --target /var/lib/app \
  --output TARGET,SOURCE,FSTYPE,UUID,PARTUUID,OPTIONS

This catches bind mounts, device-mapper layers, and other cases where guessing from a block-device list is unsafe.

fstab accepts tags such as UUID= and PARTUUID=. The manual recommends tags over kernel device names because device-name order can change.3

Before changing fstab

Record the current findmnt output, the exact identifier, filesystem type, and intended mount options. Then validate a copied table with findmnt --verify --tab-file copy-of-fstab before editing the live file.

[!CAUTION] Inspection commands do not prove that a device is safe to format. Never run mkfs, wipefs, or partitioning tools based on a name alone. Confirm the model, serial, size, current mounts, and backups through independent views.

Sources and further reading
  1. lsblk(8)
  2. blkid(8)
  3. fstab(5)