How to Use the 'blkid' Command (with Examples)
- Linux
- December 17, 2024
The blkid
command is a utility in Unix-like operating systems used for listing and identifying block devices. Each block device, such as hard drives or USB drives, can contain multiple partitions, and blkid
provides details about these partitions, including their Universally Unique Identifier (UUID). The UUID is a critical piece of information that helps differentiate between partitions, especially when managing filesystem mounts across different systems and sessions. This tool is essential for system administrators and users who need to manage storage devices efficiently.
Use Case 1: List All Partitions
Code:
sudo blkid
Motivation:
In a complex computing environment, you may have multiple storage devices connected at any given time. Each device can have various partitions, each potentially formatted with different filesystems. Understanding what devices and partitions are available, along with their UUIDs and filesystem types, is crucial for configuring access, managing backups, or simply verifying storage configurations. Running blkid
provides a comprehensive overview of all recognized storage partitions, which can be particularly helpful after plugging in new hardware or diagnosing hardware changes in the current system setup.
Explanation:
sudo
: This command requires administrative privileges to access detailed information about block devices, as these operations can affect critical system components. Runningblkid
withsudo
ensures that the command has the necessary permissions to view all devices, even those that are not accessible to standard users.blkid
: This is the primary command to list block devices and their associated metadata. When used without additional options,blkid
scans all block devices and provides essential information including UUID, filesystem type (TYPE
), and labels.
Example Output:
/dev/sda1: UUID="e7f5ca0b-7b4c-4c2b-a0e4-958e7526d530" TYPE="ext4" PARTUUID="000b634e-01"
/dev/sda2: UUID="8E7F-1D27" TYPE="vfat" PARTUUID="000b634e-02"
/dev/sdb1: UUID="73ef8196-da73-495f-85b9-62f824456abc" TYPE="xfs" PARTUUID="04d4440e-01"
In this example, the system lists devices /dev/sda1
, /dev/sda2
, and /dev/sdb1
with their respective UUIDs, types of filesystems, and partition UUIDs.
Use Case 2: List All Partitions in a Table, Including Current Mountpoints
Code:
sudo blkid -o list
Motivation:
For system administrators and users managing disk partitions, understanding how and where each partition is mounted in the filesystem hierarchy is vital. This is especially relevant for tasks like automating backups, configuring new systems, developing scripts for system management, or even for educational purposes. Displaying partitions in a tabular form, along with their mount points, provides a quick overview that helps in the efficient management and understanding of storage resources.
Explanation:
sudo
: As with the previous use case, administrative access is crucial to gather comprehensive device information across the system peripherals.blkid
: The core command responsible for retrieving block device information.-o list
: This option changes the output format to a list. Instead of providing information for each partition on separate lines, this option organizes it neatly into a table. The table structure is particularly useful for quickly discerning which partitions are mounted and where, thereby facilitating system organization and analysis.
Example Output:
device fs_type label mount point UUID
-------------------------------------------------------------------------------------
/dev/sda1 ext4 rootfs / e7f5ca0b-7b4c-4c2b-a0e4-958e7526d530
/dev/sda2 vfat boot /boot 8E7F-1D27
/dev/sdb1 xfs backup /mnt/backup 73ef8196-da73-495f-85b9-62f824456abc
Here, the output provides a tabular view where /dev/sda1
is mounted on the root directory with the filesystem type ext4
, and so forth up to /dev/sdb1
, which is mounted on /mnt/backup
.
Conclusion
The blkid
command is a versatile utility that offers valuable insights into the partition structure and configuration of block devices on a Unix-like operating system. Whether you’re managing a single desktop, setting up a server or teaching system management, understanding and efficiently using blkid
can significantly enhance your ability to navigate and control storage devices. With options to display information in different formats, it facilitates quick decision-making processes necessary for system stability and configuration management.