Wikipedia defines a device file or special file as an interface to a device driver that appears in a file system as if it were an ordinary file. Block devices include Hard disks, Flash drives, Optical media, etc.

This tutorial discusses how to use the lsblk command to display information about block devices in a system. The tool utilizes the /sys virtual filesystem to fetch information about the devices. However, it’s worth noting that the tool does not display the RAM disk in the output.

How to Install lsblk?

The lsblk command comes bundled as part of the utils-Linux package that has various low-level system tools. The utils-Linux package also contains tools such as fdisk, login daemon, all of which are essential for Linux system functionality.

To install the package on Ubuntu and Debian based distributions, use the command below:

sudo apt-get install util-linux

For Fedora and REHL family, use the following command:

sudo yum install util-linux-ng

How to Use lsblk?

Without arguments, the lsblk command will display a list of the block devices in a tree-format, as shown below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-01.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

The output from the lsblk command comes arranged in various columns. The following are the columns from the command and what they represent:

  1. NAME: The first column shows the device name.
  2. MAJ:MIN: The second column, respectively, indicates the major and minor device numbers.
  3. RM: This column displays Boolean values for removable and non-removable devices. 1 indicates that the device is removable, and 0 indicates that the device is non-removable.
  4. SIZE: This displays the device size in a readable format, i.e., In K, M, G, T, etc. You can use the lsblk –bytes /dev/ to display the size in bytes.
  5. RO: This column shows the read-only status of a device. 1 indicates the device is read-only, and 0 indicates not read-only.
  6. TYPE: This column shows the type of devices, such as disk, loopback device, partition, or LVM device.
  7. MOUNTPOINT: This displays the mount point on which the device is mounted.

Devices in lsblk output

Some of the devices you will see in the lsblk output are:

  1. Loopback devices: Loopback devices mainly contains ISO image, a disk image, a file system, or a logical volume image. Their main identification is using loop0, loop1, etc.
  2. CD-ROM: They are mainly indicated with sr0 and have properties such as RM of 1.
  3. Disk partitions: The main indicator used for Disk partitions is sda, followed by sda1, sda2…sda(n).

List all devices

The default lsblk command does not display all free devices. To do this, add the -a argument to the command as:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-02.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

List format

The lsblk command will display the output in a tree-like format. However, you can change this by using the -l argument as:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-03.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

Selective Columns

We can also use -o followed by the names of the columns we want to output for selective information as:

sudo -o NAME,TYPE,MOUNTPOINT

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-04.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

Device Permissions

To view device permissions and ownership, use the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-05.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

Information about specific devices

To list information about a particular block device, specify the device name in the lsblk command as:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-06.png" data-lazy- height="425" src="data:image/svg xml,” width=”594″>

List devices without the header

To remove the header from the output, use the -n flag in the command as:

Display SCSI Devices

To display SCSI devices only, use the -S flag in the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/linux-lsblk-command-tutorial-for-beginners-07.png" data-lazy- height="425" src="data:image/svg xml,” width=”645″>

Conclusion

In this tutorial, we discussed how to work with the lsblk command to display information about block devices that are connected to the system. The only way to master working with this command is to experiment. Therefore, consider experimenting with the commands discussed in this tutorial.

About the author

<img alt="John Otieno" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/01/echo/john-150×150.png5ff5f96588eb1.jpg" height="112" src="data:image/svg xml,” width=”112″>

John Otieno

Computer science student and resident of Kenya