Lsblk - Command to List Block Device in Linux

Lsblk command is used to list information about all available block devices in Linux. However, it does not list information about RAM disks. Lsblk can list information about block devices such as hard disk, USB flash drives, CD-ROM e.t.c.

The lsblk commands use sysfs filesystem and udev db to gather information. The output will be displayed in a tree-like format.

Install lsblk on Linux

The lsblk command comes packaged under util-linux. This package includes many utilities such as fdisk, dmesg, kill, findmnt, hwclock, lscpu, etc.

Lsblk is by default available on all modern Linux distributions. If it is not installed by default, use the following commands to install lsblk.

On Ubuntu/Debian

$ sudo apt-get install util-linux

On CentOS/Redhat

$ sudo yum install util-linux-ng

On Fedora

$ sudo yum install util-linux-ng

How to Use Lsblk Command

The lsblk command by default will list all block devices in a tree-like format.

Open your terminal, type:

$ lsblk
lsblk command
Output of lsblk

There are seven columns namely:

NAME: This is the device name.

MAJ:MIN: This column shows the major and minor device number.

RM: This column shows whether the device is removable or not. Note in this example the device sdb and sr0 have their RM values equals to 1 indicating they are removable.

SIZE: This is column give information on the size of the device. For example, 298.1G indicate the device is 298.1GB and 1K indicate the device size is 1KB.

RO: This indicates whether a device is read-only. In this case all devices have a RO=0, indicating they are not read only.

TYPE: This column shows information whether the block device is a disk or a partition(part) within a disk. In this example, sda and sdb are disks while sr0 is a read-only memory (rom).

MOUNTPOINT: This column indicates mount point on which the device is mounted.

List All Block Devices

The default option does not list all empty devices. To view these also use the command as follows:

$ lsblk -a

Print Size Column in Bytes

To print size column in bytes use -b or --bytes option.

For example to print all partitions in the hard disk (/dev/sda) with size in bytes, run:

$ lsblk --bytes /dev/sda
Print size column in bytes
Print size column in bytes

List Device Permissions and Owner

To list the device ownership, group and mode (permissions) use -m option.

$ lsblk -m
print device owner, group and mode
print device owner, group and mode

List Specific Block Devices

To list information about a specific block device, use device name followed the lsblk command.

For example:

$ lsblk /dev/sda

List Devices Without Header in List Form

To remove header and list output format, use -nl option.

$ lsblk -nl
lsblk no header and list
lsblk no header and list

List SCSI Devices

To list of SCSI devices use -S option.

$ lsblk -S
lsblk SCSI devices
lsblk print only SCSI devices

Conclusion

In this tutorial, we learned how to use lsblk command to list information about block devices in Linux. Try it out today!

Leave a Comment