How to Use the Linux blkid Command

The blkid command is an essential administrative utility in the Linux operating system used to identify, locate, and display the attributes of block storage devices. This guide covers the primary functions of blkid, explains the specific drive attributes it reveals—such as UUIDs, filesystem types, and partition labels—and demonstrates practical command-line examples for managing storage devices and configuring system mounts reliably.


What Does the blkid Command Do?

The name blkid stands for "Block Identification." It functions by querying the libblkid library and scanning available block devices (such as hard drives, solid-state drives, USB sticks, and virtual disk partitions) to extract their low-level metadata.

Unlike basic disk listing tools like lsblk or fdisk, which primarily show partition layouts and sizes, blkid focuses on identifying how those partitions are formatted and recognized by the operating system.

Key Drive Attributes Identified by blkid

When run against storage devices, blkid provides several critical attributes (known as tags):

Primary Use Cases

1. Configuring Persistent Mounts in /etc/fstab

The most common use of blkid is locating filesystem UUIDs for inclusion in the /etc/fstab file. Using UUIDs instead of device path names ensures the operating system correctly mounts root and secondary storage partitions even if drives are re-ordered or plugged into different physical ports.

2. Identifying Filesystem Types Before Mounting

Before executing a mount command, administrators can verify whether a partition is formatted with a supported filesystem without having to read partition tables manually.

3. Searching for Specific Storage Devices

System scripts and automated deployment tools regularly use blkid to quickly detect whether a specific disk label or filesystem type is present on the machine.


Common blkid Command Examples

Running blkid usually requires superuser (root) privileges to read attributes directly from raw block devices.

Display All Block Devices

Running the command without arguments lists all available block devices and their associated attributes:

sudo blkid

Example Output:

/dev/sda1: UUID="e4b89f32-84b2-4d22-83b6-99d8be8d58c1" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="7c90b0e3-01"
/dev/sda2: UUID="4F82-5A91" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System" PARTUUID="7c90b0e3-02"
/dev/sdb1: LABEL="BackupDrive" UUID="2a76f6b4-93c2-482a-9e1e-28b33534ad10" TYPE="xfs"

Inspect a Specific Device

Target a specific partition by appending its device path:

sudo blkid /dev/sda1

Find Devices by Filesystem Type

Use the -t (tag) flag to filter results based on specific attributes, such as locating all ext4 partitions:

sudo blkid -t TYPE=ext4

Extract Only the UUID

To isolate only the UUID attribute for scripting or easy copying:

sudo blkid -s UUID -o value /dev/sda1

Display Results in a Formatted Table

For easier human readability, the output format can be customized using the -o flag:

sudo blkid -o list