Use the Linux blkid command to find the block device details
Today, we will show you how to use lsblk and blkid to find information about Block devices. We use a machine with CentOS 7.0 installed.
Lsblk
Lsblk is a Linux tool that displays information about all available Block devices in your system. It obtains information from the sysfs file system. By default, this tool will display all Block devices in a tree format (except for memory Virtual Disks.
Default lsblk output
By default, lsblk outputs Block devices in the tree format:
NAME -- device NAME
MAJ: MIN -- each device in the Linux operating system is represented by a file. For block (Disk) devices, the primary and secondary device numbers are used to describe the device.
RM -- Removable device. If this is a Removable device, 1 is displayed; otherwise, 0 is displayed.
TYPE -- device TYPE
MOUNTPOINT -- device Mount location
RO-for read-only file systems, 1 is displayed here; otherwise, 0 is displayed.
SIZE -- device capacity
Display the device owner
If you want to display information about the device owner, including the user, group, and mount mode of the file system, you can use the-m option, as shown in the following figure:
- Lsblk-m
List device blocks
If you only want to list devices and do not want them to output in a tree, you can use the-l option:
- Lsblk-l
Use in script
Tip: If you want to remove the header from the script, you can use the-n option as follows:
- Lsblk-ln
Blkid
The blkid command is a command line tool that displays information about available Block devices. It can identify the type of block device content (such as file system and swap zone) and obtain attributes (such as tokens and key-value pairs) from the metadata of the content (such as the volume tag or UUID field ). It has two main functions: to search for a device with a specified key-value pair, or to display a key-value pair of one or more devices.
Blkid usage
Running blkid without adding any parameters will output all available devices, their universal unique identifier (UUID), file system type, and volume label (if any ).
- # Blkid
List devices by name or UUID
If you only want to display the information of a specific device, you can add the device name as an option after blkid:
- # Blkid/dev/sda1
If you know the UUID of a device and want to know its device name, you can use the-U option, like this:
- # Blkid-U d3b1dcc2-e3b0-45b0-b703-d6d0d360e524
Details
If you want more details, you can use the-p and-o udev options to display them in neat format, as shown in the following code:
- # Blkid-po udev/dev/sda1
Reset Cache
Sometimes the device list may not be updated. In this case, you can use the-g option to clear the blkid cache to clear nonexistent devices.
- # Blkid-g
This article permanently updates the link address: