Where to start First steps track · 15 stages
Linux Labs

blkid — filesystem UUID, label and type

5 min Ubuntu 24.04 · util-linux 2.39

The blkid command prints the UUID, label and type of the filesystem on a device — what goes into /etc/fstab.

Cheat sheet

7 commands Printable version
  • sudo blkid every device with a filesystem
  • sudo blkid /dev/vdb1 one device
  • sudo blkid -s UUID -o value /dev/vdb1 just the UUID, for scripts
  • sudo blkid -L data which device has the label data
  • sudo blkid -U 5d1c0f4e-… which device has this UUID
  • sudo blkid -p /dev/vdb the disk itself: its table
  • lsblk -f the same as a tree

Overview

blkid reads the start of a device and reports what is written there. For a partition with a filesystem it is one line of pairs: /dev/vdb1: LABEL="data" UUID="…" TYPE="ext4" …. With -o export the same pairs come one per line:

text
student@ubuntu:~$ sudo blkid -o export /dev/loop0p1
DEVNAME=/dev/loop0p1
LABEL=data
UUID=4db8b2fe-ff93-4036-b20c-8175523f9825
BLOCK_SIZE=4096
TYPE=ext4
PARTLABEL=data
PARTUUID=fac85c19-a932-4417-9a8c-ac6d9c329d29
Tag Belongs to Comes from
UUID the filesystem set by mkfs, changes on every new mkfs
LABEL the filesystem mkfs.ext4 -L, e2label
TYPE the filesystem ext4, xfs, swap, vfat
PARTUUID the partition in the table set by fdisk or parted when the partition is created
PARTLABEL the partition in GPT the name from mkpart data …

In /etc/fstab a partition is referred to by UUID or label: UUID=… or LABEL=data. A name like /dev/vdb1 depends on the order in which disks are attached and may go to another disk after a reboot. More on the fstab line in mount.

Run blkid with sudo. Without root it cannot read the devices and prints only what it cached earlier — sometimes nothing.

Options

5

The full list is in man blkid.

Option What it does Example
-s --match-tag TAG Print only this tag — UUID, LABEL, TYPE; may be repeated. sudo blkid -s UUID /dev/vdb1
-o --output value|export|list Output format; value prints bare values, export prints NAME=value lines. sudo blkid -s UUID -o value /dev/vdb1
-L --label LABEL Print the device that has this label. sudo blkid -L data
-U --uuid UUID Print the device that has this UUID. sudo blkid -U 3f6c1a2e-9b7d-4c55-8e21-6d0b9a4f7c13
-p --probe Probe the device directly, bypassing the cache; on a whole disk shows PTTYPE. sudo blkid -p /dev/vdb

Nothing found. Try a shorter query.

Recipes

4

A line for fstab

bash
UUID=$(sudo blkid -s UUID -o value /dev/vdb1)
echo "UUID=$UUID /srv/data ext4 defaults,nofail 0 2" |
  sudo tee -a /etc/fstab
sudo findmnt --verify

Compare an fstab line with the device

bash
grep /srv/data /etc/fstab
sudo blkid /dev/vdb1           # does the UUID match fstab?

If it does not, fix fstab. mkfs is not the answer here: it wipes the data.

Find a device by label or UUID

bash
sudo blkid -L data             # /dev/vdb1
findfs LABEL=data              # the same, as a separate command

What is on a disk with no filesystem

bash
sudo blkid -p /dev/vdb    # PTUUID="…" PTTYPE="gpt"

Troubleshooting

5

blkid prints nothing

The device holds neither a filesystem nor a partition table — a new disk. The exit code in this case is 2. Or blkid ran without sudo. sudo blkid -p shows what is really on the disk.

The output has only PARTLABEL and PARTUUID

The partition is in the table, but there is no filesystem on it: UUID, LABEL and TYPE appear after mkfs.

The UUID in fstab is not found

After a new mkfs the filesystem has a new UUID. Take it from sudo blkid and fix the fstab line. findmnt --verify checks the table before a reboot.

Two partitions have the same UUID

The partition was copied whole (dd, a cloned disk). Change the copy's UUID: sudo tune2fs -U random /dev/vdc1 for ext4 — see Filesystems.

fstab has PARTUUID instead of UUID

Both work, but they are different values: PARTUUID= looks up the partition in the table, UUID= looks up the filesystem. The key in fstab must match the blkid tag.

Terms

2
filesystem UUID
A filesystem identifier allowing references independent of its current device name. Also appears in: Filesystems: ext4, xfs, fsck, lsblk, mkfs
filesystem label
A short name given to a filesystem at creation (mkfs.ext4 -L) or later (e2label). It finds the partition: LABEL=data in fstab, blkid -L data. Also appears in: Software RAID with mdadm, mkfs, qemu-img, Disk quotas

See also

  • mount — add a partition to fstab and mount it.
  • mkfs — create a filesystem; the UUID and label come from it.
  • lsblk — lsblk -f shows the same tags as a tree.
  • fdisk-parted — partitions, their PARTUUID and PARTLABEL.
  • filesystems — change the label and UUID with tune2fs.
  • loop-device — a practice disk made from a file.
Loading…