Today we'll show you how to use the lsblk and blkid tools to find information about block devices, and we're using a CentOS 7.0-equipped machine.
Lsblk
lsblk is a Linux tool that displays information about all the 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-like format (except for memory virtual disks).
Lsblk Default Output
By default, LSBLK will export the block device to a tree format:
Name--Names of the devices
Each device in the maj:min --linux operating system is represented as a file, where the device is described by a primary and secondary device number for a block (disk) device.
RM --removable devices. If this is a removable device will display 1, otherwise display 0.
Type--Types of devices
mountpoint --Location of device mounts
RO -for read-only file systems, this will show 1, otherwise 0.
size --capacity of the device
Display the owner of the device
To display information about the owner of the device, including the user who owns the file, the group it belongs to, and the file system mount mode, you can use the-M option, like this:
- Lsblk -m
List device blocks
If you only want to list the devices and don't want them to be in a tree-like output, you can use the-l option:
- Lsblk -l
Using in Scripts
Advanced Tip: If you want to get rid of a table header if you wish to use it in a script, you can use the-N option:
- LSBLK -LN
Blkid
The blkid command is a command-line tool that can display information about the available block devices. It identifies the type of block device content (such as the file system, swap area), and gets attributes (such as tokens and key-value pairs) from the content's metadata, such as the volume label or UUID field. It has two main functions: to search for a device with a specified key value pair, or to display key-value pairs for one or more devices.
Blkid How to use
Running blkid without adding any parameters will output all available devices, their universal unique identifiers (UUID), the file system type, and the volume label (if one is set).
- # Blkid
List devices by name or UUID
If you only want to display information for a particular device, you can add the device's name as an option behind 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
More information
If you want to get more details, you can use the-p and-O udev options to display them in a neat format, like this:
- # Blkid-po UDEV/DEV/SDA1
Resetting the cache
Sometimes the list of devices may not be updated, and if this is the case, you can use the-G option to clean up the blkid cache, eliminating devices that do not already exist.
- # blkid-g
Via:http://linoxide.com/linux-command/linux-command-lsblk-blkid/
Adrian Dinu Translator: Felixonmars proofreading: Wxy
Find block device details with the Linux blkid command