Use the Linux blkid command to find the block device details

Source: Internet
Author: User

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:

  1. 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:

  1. Lsblk-l
Use in script

Tip: If you want to remove the header from the script, you can use the-n option as follows:

  1. 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 ).

  1. # 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:

  1. # 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:

  1. # 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:

  1. # 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.

  1. # Blkid-g

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.