Linux blkid Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux blkid command, a powerful tool for identifying filesystem types and querying disk attributes. The blkid command can be used to locate and print block device information, including filesystem type, UUID, labels, and more. We will start by running the blkid command without any arguments to see the overall block device information, and then learn how to query specific block devices and filter the output based on filesystem types. This lab provides practical examples and insights into effectively using the blkid command in Linux system administration tasks.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/sudo -.-> lab-422577{{"`Linux blkid Command with Practical Examples`"}} end

Introduction to blkid Command

In this step, we will explore the blkid command, a powerful tool in Linux for identifying filesystem types and querying disk attributes.

The blkid command is used to locate and print block device attributes. It can be used to show information about block devices, including filesystem type, UUID, labels, and more.

Let's start by running the blkid command without any arguments:

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 shows the block device information, 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 as an argument:

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 the detailed information for the specified block device.

Identifying Filesystem Types with blkid

In this step, we will learn how to use the blkid command to identify the filesystem types of block devices.

The blkid command can be used to query the filesystem type of a specific block device. Let's try it out:

sudo blkid /dev/sda1

Example output:

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

The output shows that the /dev/sda1 block device has an ext4 filesystem type.

You can also use the -t option to filter the output and only show block devices with a specific filesystem type:

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 will only display block devices with the ext4 filesystem type.

Similarly, you can use the -t option to filter 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 will only display the block device with the "cloudimg-rootfs" label.

Querying Disk Attributes with blkid

In this final step, we will explore how to use the blkid command to query various disk attributes, such as the UUID, label, and partition information.

The blkid command can display detailed information about block devices, including their UUID, labels, and partition details. Let's try 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 shows the UUID, label, filesystem type, and partition UUID for the /dev/sda1 block device.

You can also use the blkid command to display information about all block devices on the system:

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 shows the detailed information for all block devices on the system, including their device names, UUIDs, labels, filesystem types, and partition UUIDs.

Summary

In this lab, we explored the blkid command, a powerful 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. 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 that can be used to gather detailed information about the storage devices on a Linux system. By understanding how to effectively use blkid, system administrators and users can better manage and troubleshoot their Linux environments.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like