Linux Command Reference ยท Disks and Filesystems
Linux blkid command
Reference for the Linux blkid command: print UUID, LABEL and filesystem type of block devices, filter with -s and -o, look up devices by tag, and use it in fstab.
blkid reads the small signature that a filesystem, swap area or RAID/LVM member leaves at the start of a block device and prints the attributes it finds: the filesystem type (TYPE), the volume label (LABEL), the unique identifier (UUID) and, for partitioned disks, the partition identifiers (PARTUUID, PARTLABEL).
The UUID is the reason you will use it most. Device names such as /dev/sdb1 can change between boots when disks are added or reordered, but a UUID stays with the filesystem. That is why /etc/fstab and boot loaders refer to filesystems by UUID. blkid is the quick way to find the value to paste in.
sudo blkid sudo blkid /dev/sda1
Try it
The learning sandbox has no block devices you may probe and no blkid binary, so these two examples are read-only simulations: they use sample output (clearly stored in a variable) and show how scripts consume it. On a real machine, replace the here-document with sudo blkid.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
blkid [-s TAG] [-o FORMAT] [-p] [-c FILE] [DEVICE...] blkid -L LABEL blkid -U UUID blkid -t NAME=value [DEVICE...]
| Option | Description |
|---|---|
DEVICE |
One or more devices to examine. Without any, blkid lists every device it can find. |
-s TAG |
Show only this tag (-s UUID). Repeat the option for several tags. |
-o FORMAT |
Output format: full (default), value (only values), device (only device names), export (KEY=value lines), list. |
-L LABEL |
Print the device that has this label. |
-U UUID |
Print the device that has this UUID. |
-t NAME=value |
List only devices where the tag matches, for example -t TYPE=ext4. |
-p |
Probe the device directly instead of using the cache (low level, needs root). |
-c FILE |
Use FILE as cache; -c /dev/null disables the cache. |
Returns: 0 if at least one device matched. 2 if nothing was found, for example a device without a recognizable signature or a label that does not exist. Other values signal usage errors.
Usage notes
- Root is usually required. An unprivileged user sees only cached data, which may be stale or empty. Use
sudo blkid. - A blank result is not always an error. A partition that holds no filesystem, or an encrypted container (
TYPE="crypto_LUKS"), still reports itself; a totally empty disk prints nothing and returns 2. - Filesystem UUID is not partition UUID.
UUIDidentifies the filesystem and changes when you reformat.PARTUUIDidentifies the partition entry in the partition table and survives a reformat. Pick the one your fstab or boot loader line uses and do not mix them. - Short FAT UUIDs. FAT and exFAT volumes carry a 32-bit serial that is printed like
9AB4-77C1. - Prefer
lsblk -ffor an overview.lsblkshows the same attributes in a tree beside mount points;blkidis better when you need the exact value for a script. - Stable names without
blkid: the directories/dev/disk/by-uuid,/dev/disk/by-labeland/dev/disk/by-idhold symbolic links that udev maintains for the same purpose. - Quote values. Labels can contain spaces; use
-o valuewith quotes in scripts:"$(blkid -s UUID -o value /dev/sda1)". - Cache. The default cache file is managed by libblkid and can lag behind after changing a filesystem; run
blkid -gas root to garbage-collect it or use-pto bypass it.
Related
lsblk,findmnt,mount,mkfs, fstab and mount options- Lessons: Disks and logs, LVM and filesystems