How to use the command "blkid" (with examples)
- Linux
- November 5, 2023
The command “blkid” is a Linux utility that lists all recognized partitions and their Universally Unique Identifier (UUID). This command is useful for identifying and managing partitions on your system.
Use case 1: List all partitions
Code:
sudo blkid
Motivation: When working with storage devices on Linux, it is important to know the partitions that are currently recognized by the system. The “blkid” command provides a comprehensive list of all recognized partitions.
Explanation: The command “sudo blkid” executes the “blkid” command as the root user, allowing it to access the necessary system information. Without using “sudo”, the command may not have sufficient privileges to retrieve the partition details.
Example Output:
/dev/sda1: UUID="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4" PARTUUID="xxxxxxxx-xx"
/dev/sda2: UUID="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="swap" PARTUUID="xxxxxxxx-xx"
/dev/sdb1: UUID="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4" PARTUUID="xxxxxxxx-xx"
/dev/sdc1: UUID="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ntfs" PARTUUID="xxxxxxxx-xx"
...
Use case 2: List all partitions in a table, including current mountpoints
Code:
sudo blkid -o list
Motivation: To get a more detailed overview of the partitions and their associated mountpoints, the “-o list” option can be used with the “blkid” command. This option provides a concise table format, making it easier to read and understand the partition information.
Explanation: Adding the “-o list” option to the “blkid” command instructs it to display the partition details in a table format. This includes the device path, UUID, filesystem type, and current mountpoint.
Example Output:
device UUID FSTYPE MOUNTPOINT
-------------------------------------------------------------------------------------
/dev/sda1 xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ext4 /
/dev/sda2 xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx swap
/dev/sdb1 xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ext4 /mnt/data
/dev/sdc1 xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ntfs
...
Conclusion:
The “blkid” command is a valuable tool for managing partitions on a Linux system. By using this command, users can easily obtain UUIDs and other information related to their partitions, facilitating various administrative tasks such as mounting, formatting, or modifying partitions. The examples provided demonstrate how to use the “blkid” command to list all partitions and display them in a table format, incorporating current mountpoints.