blkid Command in Linux

Introduction

In this lab, we'll delve into the Linux blkid command, a vital utility for any systemadmin. It allows you to identify filesystem types and query crucial disk attributes. The blkid command helps locate and display block device information, including filesystem type, UUID, labels, and more. We'll start by executing the blkid command without arguments to get a broad overview of block devices. Then, we'll learn to query specific devices and filter output based on filesystem types. This lab provides practical examples for effectively using blkid in Linux system administration tasks.

Introduction to blkid Command

In this step, we will explore the blkid command, an essential tool in Linux environments used by systemadmin for identifying filesystem formats and retrieving disk attributes.

The blkid command is your go-to utility for locating and printing block device attributes. It reveals crucial information about block devices, encompassing filesystem type, UUID, labels, and more.

Let's begin by running the blkid command without any parameters:

sudo blkid

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"

The output presents key details about each block device, including the device name, filesystem type, UUID, and label.

You can also use the blkid command to query specific block devices by providing the device path. For example:

sudo blkid /dev/sda1

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"

This will display comprehensive information for the specified block device, allowing systemadmin to effectively manage storage.

Identifying Filesystem Types with blkid

In this step, we'll explore how to leverage the blkid command to identify the filesystem types of different block devices.

The blkid command allows querying the filesystem type associated with a specific block device. Let's put it to the test:

sudo blkid /dev/sda1

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"

The output confirms that the /dev/sda1 block device is formatted with the ext4 filesystem.

You can use the -t option to filter the output and display only block devices with a specific filesystem type. For instance:

sudo blkid -t TYPE=ext4

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"

This command limits the output to block devices with the ext4 filesystem type, useful for systemadmin tasks.

Similarly, the -t option enables filtering by other attributes, such as the filesystem label or UUID:

sudo blkid -t LABEL="cloudimg-rootfs"

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"

This command filters the output to display only the block device with the "cloudimg-rootfs" label.

Querying Disk Attributes with blkid

In this final section, we'll learn how to use the blkid command to query diverse disk attributes, including the UUID, label, and partition information, valuable for any systemadmin.

The blkid command is capable of displaying detailed information about block devices, including their UUID, labels, and partition specifics. Let's test it out:

sudo blkid /dev/sda1

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"

This command reveals the UUID, label, filesystem type, and partition UUID for the /dev/sda1 block device.

You can also use the blkid command to view information about all block devices connected to the system. This is especially helpful for systemadmin tasks on Linux servers:

sudo blkid

Example output:

/dev/sda1: LABEL="cloudimg-rootfs" UUID="d2d2b1f8-7f4f-4c2a-9d7f-d7f7d7f7d7f7" TYPE="ext4" PARTUUID="d2d2b1f8-01"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"

This output displays comprehensive information for all block devices, including their device names, UUIDs, labels, filesystem types, and partition UUIDs.

Summary

In this lab, we explored the blkid command, a critical tool in Linux for identifying filesystem types and querying disk attributes. We learned how to use blkid to locate and print block device information, including filesystem type, UUID, labels, and more, all essential skills for a systemadmin. We also discovered how to filter the output to show only block devices with a specific filesystem type.

The blkid command is a versatile tool for gathering detailed information about storage devices on a Linux system. By mastering blkid, system administrators and users can more effectively manage and troubleshoot their Linux environments, even accessing the system as root when necessary.

400+ Linux Commands