What is blkid?
The blkid command (block device id) is a command-line utility that is part of the util-linux package in most Linux distributions. Its main function is to display information about block devices, such as the filesystem type, UUID, and label. This information is essential when you need to mount partitions safely, create entries in /etc/fstab, or diagnose storage problems.
Basic syntax
The simplest use of blkid is to run it without arguments, which lists all detected block devices and their attributes. The general syntax is:
blkid [options] [device]
Some useful options include:
- -s : show only the specified field (e.g., UUID or TYPE).
- -p: display information in parsable format, ideal for scripts.
- -o : define the output format (value, list, udev).
- -d: skip loop devices and other virtual devices.
Usage examples
- To view all devices and their full information:
blkid - To obtain only the UUID of partition /dev/sda1:
blkid -s UUID -o value /dev/sda1 - To list all devices with their filesystem type:
blkid -s TYPE -o value - To use parsable output in a script:
blkid -p -o udev
Interpreting the output
The typical output of blkid looks like this:
/dev/sda1: UUID='3f8b2e1c-6a4d-4f9b-8e2a-1c7d5f6a9b2c' TYPE='ext4' PARTUUID='00112233-01'
Each line starts with the device name, followed by key=value pairs in single quotes. The most common fields are:
- UUID: unique identifier of the filesystem, independent of the device name.
- TYPE: indicates the filesystem type (ext4, xfs, vfat, ntfs, etc.).
- LABEL: user‑friendly label, if one has been assigned.
- PARTUUID: unique identifier of the partition, useful on systems that use GPT.
Tips and best practices
- Always verify the UUID before editing /etc/fstab; using the UUID avoids problems if the device order changes.
- In boot or auto‑mount scripts, prefer the -p -o udev option to get output that is easy to parse.
- If you need information about a specific device, specify its path (e.g., /dev/nvme0n1p2) to avoid scanning the whole system.
- Remember that blkid requires read permissions on the device; it is normally run as root or with sudo.
This post is also available in ESPAÑOL.