TrumanWong

lsblk

List block device information

Supplementary instructions

lsblk command is used to list information about all available block devices and also displays the dependencies between them, but it does not list RAM disk information. Block devices include hard drives, flash drives, cd-ROMs, etc. The lsblk command is included in the util-linux-ng package, which is now renamed util-linux. This package comes with several other tools, such as dmesg. To install lsblk, download the util-linux package here. Fedora users can install this package through the command sudo yum install util-linux-ng.

Options

-a, --all # Display all devices.
-b, --bytes # Display device size in bytes.
-d, --nodeps # Do not display slaves or holders.
-D, --discard # print discard capabilities.
-e, --exclude <list> # Exclude devices (default: RAM disks).
-f, --fs # Display file system information.
-h, --help # Display help information.
-i, --ascii # use ascii characters only.
-m, --perms # Display permission information.
-l, --list # Use list format to display.
-n, --noheadings # Do not display headings.
-o, --output <list> # Output column.
-P, --pairs # Use key="value" format to display.
-r, --raw # Use raw format display.
-t, --topology # Display topology information.

Example

The lsblk command will list all block devices in a tree view by default. Open a terminal and enter the following command:

lsblk

NAME MAJ:MIN rm SIZE RO type mountpoint
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 46.6G 0 part /
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 190M 0 part /boot
├─sda6 8:6 0 3.7G 0 part [SWAP]
├─sda7 8:7 0 93.1G 0 part /data
└─sda8 8:8 0 89.2G 0 part /personal
sr0 11:0 1 1024M 0 rom

The names of the 7 columns are as follows:

  1. NAME: This is the block device name.
  2. MAJ:MIN: This column displays the major and minor device numbers.
  3. RM: This column displays whether the device is a removable device. Note that in this example, the RM value of devices sdb and sr0 is equal to 1, which indicates that they are removable devices.
  4. SIZE: This column lists the capacity information of the device. For example, 298.1G indicates that the device size is 298.1GB, while 1K indicates that the device size is 1KB.
  5. RO: This item indicates whether the device is read-only. In this case, all devices have an RO value of 0, indicating that they are not read-only.
  6. TYPE: This column displays whether the block device is a disk or a partition on the disk. In this example, sda and sdb are disks, and sr0 is read-only storage (ROM).
  7. MOUNTPOINT: This column indicates the mount point where the device is mounted.

The default option does not list all empty devices. To view these empty devices, use the following command:

lsblk -a

The lsblk command can also be used to list ownership of a specific device, as well as groups and modes. This information can be obtained with the following command:

lsblk -m

This command can also obtain only the information of the specified device. This is accomplished by specifying the device name after the options provided to the lsblk command. For example, you might be interested in knowing the size of your disk drive in bytes. You can do this by running the following command:

lsblk -b /dev/sda

Equivalent to

lsblk --bytes /dev/sda

You can also combine several options to get specific output. For example, you might want to list devices in a list format instead of the default tree format. You may also be interested in removing headers for different column names. Two different options can be combined to get the desired output with the following command:

lsblk-nl

To get a list of SCSI devices, you can only use the -S option. This option is a capital S and should not be confused with the -s option, which prints dependencies in reverse order.

lsblk -S

lsblk lists SCSI devices, and -s is the reverse order option (reversing the organizational relationship of devices and partitions), which will give the following output. input the command:

lsblk -s