Linux tip: How to use the lsblk command

Network World | Aug 30, 2018

In today’s Linux tip, we’re going to look at the lsblk command, which provides useful information on block devices.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In today’s Linux tip, we’re going to look at the lsblk command that provides useful information on block devices. What are block devices? They’re devices that are read and written to a block at a time – usually 512 bytes. The most common kind of block device is, of course, a hard disk.
Issue the lsblk command and you might see something like this:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 64K 1 loop /snap/hello/20
loop1 7:1 0 13M 1 loop /snap/beautiful-dog/1
loop2 7:2 0 141.5M 1 loop /snap/minecraft/11
loop3 7:3 0 86.9M 1 loop /snap/core/4830
loop4 7:4 0 86.9M 1 loop /snap/core/4917
loop5 7:5 0 4.9M 1 loop /snap/canonical-livepatch/41
loop6 7:6 0 75.3M 1 loop /snap/hexchat/39
loop7 7:7 0 165.3M 1 loop /snap/minecraft/14
loop8 7:8 0 70M 1 loop /snap/hexchat/38
loop9 7:9 0 87M 1 loop /snap/core/5145
loop10 7:10 0 4.9M 1 loop /snap/canonical-livepatch/39
loop11 7:11 0 11.8M 1 loop /snap/hellosound/4
loop12 7:12 0 4.9M 1 loop /snap/canonical-livepatch/42
sda 8:0 0 111.8G 0 disk
└─sda1 8:1 0 111.8G 0 part /
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 500M 0 part
└─sdb2 8:18 0 465.3G 0 part /apps
sr0 11:0 1 1024M 0 rom
Ack! What’s all that? Well, in this example, we’re seeing a lot of snaps (containerized software packages) along with our hard disks and cdrom drive. All of these are block devices.
In the next command, I’m going to use a grep command to omit the snaps from my display. When we omit the snaps, we see this:
$ lsblk | grep -v loop
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 111.8G 0 disk
└─sda1 8:1 0 111.8G 0 part /
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 500M 0 part
└─sdb2 8:18 0 465.3G 0 part /apps
sr0 11:0 1 1024M 0 rom
In this display, we clearly see we have two disks – sda and sdb and that sdb has two partitions – sdb1 and sdb2. Notice that we also see the major and minor device numbers, partition sizes, device types (disk or partition) and mount points.
RM tells whether the device is removable. 1 = yes, so only the sr0 device is removable.
RO tells whether the device is read-only. 0=no, so none of them are.
The lsblk command provides a useful and easy-to-understand view of your block devices and is probably one that you will use any time you want a clear description of system disks and other block devices.
Closing: That’s your 2-minute Linux tip for today. If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.