lsblk in Ubuntu

In this article, we would cover command-line utility – lsblk in Ubuntu. It is used to display block devices specific information in a tree format. It helps us to identify partitions present in devices.

lsblk utilizes data kept somewhere to provide us the relevant information. First of those, it reads sysfs filesystem. sysfs filesystem is a pseudo-filesystem which provides information about kernel modules, devices etc.

Apart from that, it also gathers data from udev database. All the device related information is stored in udev database. So, from here it can easily get necessary data. If you would like to know about how to monitor device events with udev.

It is worth mentioning here that, if it can’t read data from udev database. Then, only option it is left with is to read UUIDs, LABELs from the filesystem itself.

lsblk in Ubuntu

Following is the syntax for lsblk command-line utility –

lsblk [options] [device]

First, we go ahead with no options. Just open a terminal and issue the following –

lsblk

It would return with –

NAME   MAJ:MIN RM  SIZE    RO    TYPE    MOUNTPOINTS
loop0    7:0    0  73M      1    loop    /snap/lxd/22147
loop1    7:1    0  102.4M   1    loop    /snap/lxd/23270
loop2    7:2    0  47M      1    loop    /snap/snapd/16292
loop3    7:3    0  62M      1    loop    /snap/core20/1581
loop4    7:4    0  61.9M    1    loop    /snap/core20/1518
sda      8:0    0  50G      0    disk 
├─sda1   8:1    0  1M       0    part 
├─sda2   8:2    0  512M     0    part    /boot
├─sda3   8:3    0  1G       0    part    [SWAP]
└─sda4   8:4    0  48.5G    0    part    /
sr0      11:0   1  1024M    0    rom

The first column – NAME, it displays device name.

MAJ:MIN – Major:Minor numbers, Major number identifies the driver and Minor number is used only by the identified drivers of the device. We will cover it more in coming articles.

RM – shows whether the device is removable or not. 1 here shows that it is removable, for the rest it is zero.

SIZE – self-explanatory.

RO – Read-only. If the device is read-only then, it’s value is 1 otherwise its 0.

TYPE – identifies device type. For instance, PART is for partition.

MOUNTPOINTS – where the device is mounted.

Second, we can also get device specific information as well –

lsblk /dev/sda1

It ignores the rest and displays information only related to /dev/sda1

Third, to display empty and RAM disk devices –

lsblk -a

Fourth, as we see from the output above that /dev/sda disk has got four partitions. If we simply use the code – lsblk /dev/sda then, it would display information related to its partitions as well. But, if don’t want information related to its partitions then –

lsblk --nodeps /dev/sda

Fifth, to display output related to filesystems –

lsblk -f

It would show us the additional data – FSTYPE, FSVER, LABEL, UUID, FSAVAIL and FSUSE%.

Sixth, we can also get the output in JSON format –

lsblk -J

Seventh, if we want output as block-device topology –

lsblk -t

In conclusion, we have covered here – lsblk in Ubuntu.

Similar Posts