9 “blkid” command examples in Linux – View storage / block devices

By | August 20, 2023

This article explores the 'blkid' command, whose purpose is retrieving information about block devices, LABEL, UUID, file system type, etc. The useful command can help us to identify or troubleshoot issues related to block devices and their attributes.

Installation

To use 'blkid' command, your Linux system needs to have the 'util-linux' package installed.

blkid: command not found

In case 'blkid' command is not installed on your system yet, run the following commands based on your Linux distro:

On Debian/Ubuntu

$sudo apt-get install util-linux

On CentOS/RedHat

$sudo yum install util-linux-ng

Syntax

blkid [options] [device...]

Options to customize its output

-c, --cache-file <file>    read from <file> instead of reading from the default
-d, --no-encoding          don't encode non-printing characters
-g, --garbage-collect      garbage collect the blkid cache
-o, --output <format>      output format; can be one of:
-k, --list-filesystems     list all known filesystems/RAIDs and exit
-s, --match-tag <tag>      show specified tag
-t, --match-token <token>  find device with a specific token
-l, --list-one             look up only first device with token specified by -t
-L, --label <label>        convert LABEL to device name
-U, --uuid <uuid>          convert UUID to device name
-p, --probe                low-level superblocks probing
-i, --info                 gather information about I/O limits
-H, --hint <value>         set hint for probing function
-S, --size <size>          overwrite device size
-O, --offset <offset>      probe at the given offset
-u, --usages <list>        filter by "usage" 
-n, --match-types <list>   filter by filesystem type
-D, --no-part-details      don't print info from partition table

1. Display the attributes of all the block devices

By running 'blkid' command only without any options, you will get all attributes of all block devices in your Linux system.

$ blkid
/dev/mapper/vgubuntu-swap_1: UUID="9d3263eb-474e-4aea-a596-93a164093a9c" TYPE="swap"
/dev/mapper/vgubuntu-root: UUID="fd23872b-bbb8-4bb3-b7b9-425ed0ae0308" BLOCK_SIZE="4096" TYPE="ext4"
/dev/loop1: TYPE="squashfs"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-08-10-16-21-45-00" LABEL="Ubuntu 22.04.1 LTS amd64" TYPE="iso9660" PTTYPE="PMBR"
/dev/sda2: UUID="7C04-B053" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="27e3efb3-6f62-463d-85d6-ea15deae4711"
/dev/sda3: UUID="3uPfc3-rtSZ-FMbH-PKAo-E7p9-UmiN-53qoJT" TYPE="LVM2_member" PARTUUID="9d1ea21c-d934-434d-9061-f2f065ce7a12"

Note: Sometimes you might have to run blkid with sudo (root privileges) to display all block devices. By default, it includes all the loop devices in the list on ubuntu based systems.

2. View information of specific block device

To display attributes of only one block device, for example '/dev/sda1', run the following command:

$ blkid /dev/sda2
/dev/sda2: UUID="7C04-B053" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="27e3efb3-6f62-463d-85d6-ea15deae4711"

You can also display all information of a specific device by combining the command with option -p and '-o' with format 'udev' as the following command:

$ sudo blkid -p -o udev /dev/sda2
ID_FS_UUID=7C04-B053
ID_FS_UUID_ENC=7C04-B053
ID_FS_VERSION=FAT32
ID_FS_BLOCK_SIZE=512
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_UUID=27e3efb3-6f62-463d-85d6-ea15deae4711
ID_PART_ENTRY_TYPE=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
ID_PART_ENTRY_NUMBER=2
ID_PART_ENTRY_OFFSET=4096
ID_PART_ENTRY_SIZE=1050624
ID_PART_ENTRY_DISK=8:0

3. Display only UUIDs of block devices

With option '-s' or '--match-tag' with tag 'UUID', the command will display UUID information of devices as follows:

$ blkid -s UUID
/dev/mapper/vgubuntu-swap_1: UUID="9d3263eb-474e-4aea-a596-93a164093a9c"
/dev/mapper/vgubuntu-root: UUID="fd23872b-bbb8-4bb3-b7b9-425ed0ae0308"
/dev/sr0: UUID="2022-08-10-16-21-45-00"
/dev/sda2: UUID="7C04-B053"
/dev/sda3: UUID="3uPfc3-rtSZ-FMbH-PKAo-E7p9-UmiN-53qoJT"

Additionally, you can combine blkid with option -o or --output to display only UUID value as this command:

$ blkid -s UUID -o value
9d3263eb-474e-4aea-a596-93a164093a9c
fd23872b-bbb8-4bb3-b7b9-425ed0ae0308
2022-08-10-16-21-45-00
7C04-B053
3uPfc3-rtSZ-FMbH-PKAo-E7p9-UmiN-53qoJT

4. List all devices in a list format

Option -o also gives list output for readability format:

$ blkid -o list
device              fs_type   label      mount point             UUID
-----------------------------------------------------------------------------------------------------
/dev/mapper/vgubuntu-swap_1
                    swap                 [SWAP]                  9d3263eb-474e-4aea-a596-93a164093a9c
/dev/mapper/vgubuntu-root
                    ext4                 /                       fd23872b-bbb8-4bb3-b7b9-425ed0ae0308
/dev/loop1          squashfs             /snap/firefox/2987
/dev/sr0            iso9660   Ubuntu 22.04.1 LTS amd64 (not mounted) 2022-08-10-16-21-45-00
/dev/sda2                    vfat                     /boot/efi                        7C04-B053
/dev/sda3                    LVM2_member              (not mounted)                    3uPfc3-rtSZ-FMbH-PKAo-E7p9-UmiN-53qoJT/dev/loop5                   squashfs                 /snap/core18/2785
/dev/sda1                                             (not mounted)

5. Display only specific filesystem type

You can use -t or --match-token option to output block devices having specific filesystem type by running the following command:

$ blkid -t TYPE=ext4
/dev/mapper/vgubuntu-root: UUID="fd23872b-bbb8-4bb3-b7b9-425ed0ae0308" BLOCK_SIZE="4096" TYPE="ext4"

6. Display attributes for devices by specific labels

Option '-t' can also be used to retrieve which devices match with provided labels by running the below command:

$ blkid -t LABEL="Ubuntu 22.04.1 LTS amd64"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-08-10-16-21-45-00" LABEL="Ubuntu 22.04.1 LTS amd64" TYPE="iso9660" PTTYPE="PMBR"

7. Display first device in the list of specified attribute

In case you need to output only the first device from the retrieved list of a specified attribute, option -l or --list-one can be combined with option '-t', as shown in the following example:

$ blkid -t TYPE=squashfs
/dev/loop1: TYPE="squashfs"
/dev/loop19: TYPE="squashfs"
/dev/loop27: TYPE="squashfs"
/dev/loop17: TYPE="squashfs"
/dev/loop8: TYPE="squashfs"
/dev/loop25: TYPE="squashfs"
/dev/loop15: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop23: TYPE="squashfs"
/dev/loop13: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop21: TYPE="squashfs"
/dev/loop11: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop0: TYPE="squashfs"
/dev/loop18: TYPE="squashfs"
/dev/loop9: TYPE="squashfs"
/dev/loop26: TYPE="squashfs"
/dev/loop16: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"
/dev/loop24: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop22: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop20: TYPE="squashfs"
/dev/loop10: TYPE="squashfs"
jayce@Ubuntu-01:~$ blkid -t TYPE=squashfs -l
/dev/loop1: TYPE="squashfs"

8. Display I/O Limits of specific block devices

With option '-i' or '--info', the command will give us output device's "I/O Limits" to ensure they are using properly aligned and sized I/O.

$ sudo blkid -i /dev/sda1
/dev/sda1: MINIMUM_IO_SIZE="512" PHYSICAL_SECTOR_SIZE="512" LOGICAL_SECTOR_SIZE="512"

9. Update device list

In some situations, new additional or removable devices have not been updated to device list. Run command with option -g or --garbage-collect to perform an update on device list:

$ blkid -g

Conclusion

Along with 'lsblk' and 'fdisk', the command 'blkid' will make it easier to manage block storage devices in Linux. By practicing the examples mentioned in this article, you will become proficient in using the command.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *