blkid is a command-line utility in Linux that is used to display information about block devices, such as hard drives, solid-state drives (SSDs), or removable storage devices, such as USB drives. blkid can be used to display a variety of information about a block device, including its device name, type, UUID (Universally Unique Identifier), filesystem, and label.
To use blkid, you will need to have the blkid utility installed on your Linux system. blkid is usually included as part of the util-linux package, which is a collection of system utilities that are commonly used on Linux systems.
Syntax
The syntax of the blkid command is:
# blkid [options] [device name]
You can easily list the UUIDs of your volumes with the blkid command:
# blkid
The output will show you the UUID of each device attached to your system, and you can use this command any time you add new volumes to your server to list your UUIDs. This is also the first step in adding a new volume to your /etc/fstab file. While I did say that using UUIDs is not required, it’s definitely recommended and can save you from trouble later on.
You can also use the blkid utility to check the filesystem type, as shown in this snipped example from an Ubuntu system:
$ sudo blkid /dev/sda1: [...] TYPE="ext4" /dev/sda5: [...] TYPE="swap" /dev/sdb1: [...] TYPE="ext4" $
This output also shows that the filesystem on /dev/sdb1 is an ext4 filesystem.
blkid Command Examples
1. To display information about all the block devices on your system, you can use the following command:
# blkid
This command will display a list of all the block devices on your system, along with the information about each device that blkid is able to gather.
2. To display information about a specific block device, you can use the following command:
# blkid /dev/sda /dev/sda
This command will display information about the /dev/sda block device, which is typically the first hard drive on a typical Linux system.
3. To display information about a block device in a specific format, you can use the -o option followed by the name of the format you want to use. For example, to display the UUID of the /dev/sda block device in the uuid format, you could use the following command:
# blkid -o uuid /dev/sda
This command will display only the UUID of the /dev/sda block device.
2. List all partitions in a table, including current mountpoints:
$ sudo blkid -o list
Conclusion
A UUID is a unique identification number assigned when the partition or volume is formatted using mkfs. You can determine a filesystem’s UUID using either the blkid or the lsblk -f command. Filesystems can be mounted either persistently in the /etc/fstab file using their UUID or temporarily using the -U uuid option on the mount command.