10 “lsblk” command examples in Linux – List block devices

By | July 22, 2023

Introduction

This article will explore the 'lsblk' command to understand the structure of storage devices through practical examples with filtering options. This will help you manage, monitor, analyze, and troubleshoot block devices on a Linux system. Block devices are storage devices that store and retrieve data in fixed-size blocks.

Installation

To install 'lsblk', you can refer to the following commands base on your Linux distro:

On Debian/Ubuntu

$sudo apt-get install util-linux

On CentOS/RedHat

$sudo yum install util-linux-ng

Using the lsblk command with examples

The 'lsblk' command is the tool that can be used to retrieve information about storage devices and attributes, such as device names, sizes, labels, file systems, mount points, owner, etc.

1. Display block device

By running lsblk command only without any options, output will list block devices, with their names, sizes, type and mount point. For example:

$ lsblk

Sample output

jayce@Ubuntu-01:~$ lsblk
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                 7:0    0     4K  1 loop /snap/bare/5
loop1                 7:1    0 302.3M  1 loop /snap/code/131
loop2                 7:2    0 302.3M  1 loop /snap/code/132
loop3                 7:3    0 116.8M  1 loop /snap/core/14946
loop4                 7:4    0 118.2M  1 loop /snap/core/15419
loop5                 7:5    0  55.6M  1 loop /snap/core18/2751
loop6                 7:6    0  55.7M  1 loop /snap/core18/2785
loop7                 7:7    0  63.5M  1 loop /snap/core20/1891
loop8                 7:8    0  63.4M  1 loop /snap/core20/1950
loop9                 7:9    0  73.8M  1 loop /snap/core22/750
loop10                7:10   0  73.9M  1 loop /snap/core22/766
loop11                7:11   0 240.6M  1 loop /snap/firefox/2356
loop12                7:12   0 349.7M  1 loop /snap/gnome-3-38-2004/137
loop13                7:13   0 239.9M  1 loop /snap/firefox/2487
loop14                7:14   0 349.7M  1 loop /snap/gnome-3-38-2004/140
loop15                7:15   0 460.7M  1 loop /snap/gnome-42-2204/105
loop16                7:16   0 466.5M  1 loop /snap/gnome-42-2204/111
loop17                7:17   0  91.7M  1 loop /snap/gtk-common-themes/1535
loop18                7:18   0  11.7M  1 loop /snap/kubectl/2963
loop19                7:19   0  45.9M  1 loop /snap/snap-store/638
loop20                7:20   0  11.7M  1 loop /snap/kubectl/2987
loop21                7:21   0  12.3M  1 loop /snap/snap-store/959
loop22                7:22   0  53.3M  1 loop /snap/snapd/19361
loop23                7:23   0  53.3M  1 loop /snap/snapd/19457
loop24                7:24   0   304K  1 loop /snap/snapd-desktop-integration/49
loop25                7:25   0   452K  1 loop /snap/snapd-desktop-integration/83
sda                   8:0    0    50G  0 disk
├─sda1                8:1    0     1M  0 part
├─sda2                8:2    0   513M  0 part /boot/efi
└─sda3                8:3    0  49.5G  0 part
  ├─vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
  │                                           /
  └─vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]
sr0                  11:0    1   3.6G  0 rom

2. Exclude the loop devices

Note the lots of loop devices that appear on ubuntu based systems using snap package system. If you want to hide all the loop devices use the "-e7" option with lsblk like this:

$ lsblk -e7
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 111.8G  0 disk 
└─sda1   8:1    0  95.4G  0 part /var/snap/firefox/common/host-hunspell
                                 /
sdb      8:16   0 111.8G  0 disk 
└─sdb1   8:17   0  95.8G  0 part [SWAP]
sdc      8:32   0 447.1G  0 disk 
└─sdc1   8:33   0   400G  0 part /media/enlightened/a935afc9-17fd-4de1-8012-137e82662ff0
sde      8:64   0     0B  0 disk 
$

The e option basically excludes devices of the specified major number.

3. Listing all devices

With option '-a' or '--all', the output will print all devices, including empty devices, as in the following example:

$ lsblk -a

Sample output

jayce@Ubuntu-01:~$ lsblk -a -e7
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                   8:0    0    50G  0 disk
├─sda1                8:1    0     1M  0 part
├─sda2                8:2    0   513M  0 part /boot/efi
└─sda3                8:3    0  49.5G  0 part
  ├─vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
  │                                           /
  └─vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]
sr0                  11:0    1   3.6G  0 rom

4. Display size column in byte format

If you do not like readable size format, you can use '-b' or ' --bytes' option to display output size format in bytes.

$ lsblk -b

Sample output

jayce@Ubuntu-01:~$ lsblk -b
NAME                MAJ:MIN RM        SIZE RO TYPE MOUNTPOINTS
loop0                 7:0    0        4096  1 loop /snap/bare/5
loop1                 7:1    0   317022208  1 loop /snap/code/131
loop2                 7:2    0   317026304  1 loop /snap/code/132
sda                   8:0    0 53687091200  0 disk
├─sda1                8:1    0     1048576  0 part
├─sda2                8:2    0   537919488  0 part /boot/efi
└─sda3                8:3    0 53146025984  0 part
  ├─vgubuntu-root   253:0    0 49199185920  0 lvm  /var/snap/firefox/common/host-hunspell
  │                                                /
  └─vgubuntu-swap_1 253:1    0  3896508416  0 lvm  [SWAP]
sr0                  11:0    1  3826831360  0 rom

5. Display information about filesystems

To output information about UUID (unique ID), device labels, mount points, file system types, etc., use the '-f' or '--fs' option.

$ lsblk -f

Sample output

jayce@Ubuntu-01:~$ lsblk -f
NAME                FSTYPE      FSVER            LABEL                    UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
loop0               squashfs    4.0                                                                                    0   100% /snap/bare/5
loop1               squashfs    4.0                                                                                    0   100% /snap/code/131
sda
├─sda1
├─sda2              vfat        FAT32                                     7C04-B053                               506.7M     1% /boot/efi
└─sda3              LVM2_member LVM2 001                                  3uPfc3-rtSZ-FMbH-PKAo-E7p9-UmiN-53qoJT
  ├─vgubuntu-root   ext4        1.0                                       fd23872b-bbb8-4bb3-b7b9-425ed0ae0308     21.6G    47% /var/snap/firefox/common/host-hunspell
  │                                                                                                                             /
  └─vgubuntu-swap_1 swap        1                                         9d3263eb-474e-4aea-a596-93a164093a9c                  [SWAP]
sr0                 iso9660     Joliet Extension Ubuntu 22.04.1 LTS amd64 2022-08-10-16-21-45-00

6. Use ASCII characters

You can use '-i' or '--ascii' option to output ASCII characters formatting.

$ lsblk -i

Sample output

jayce@Ubuntu-01:~$ lsblk -i
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                 7:0    0     4K  1 loop /snap/bare/5
loop1                 7:1    0 302.3M  1 loop /snap/code/131
loop2                 7:2    0 302.3M  1 loop /snap/code/132
loop3                 7:3    0 116.8M  1 loop /snap/core/14946
loop4                 7:4    0 118.2M  1 loop /snap/core/15419
loop5                 7:5    0  55.6M  1 loop /snap/core18/2751
sda                   8:0    0    50G  0 disk
|-sda1                8:1    0     1M  0 part
|-sda2                8:2    0   513M  0 part /boot/efi
`-sda3                8:3    0  49.5G  0 part
  |-vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
  |                                           /
  `-vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]
sr0                  11:0    1   3.6G  0 rom

7. Output information about block-device topology

To display the device block topology, use 'lsblk' command along with option '-t' or '--topology'.

$ lsblk -t

Sample output

jayce@Ubuntu-01:~$ lsblk -t
NAME                ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED       RQ-SIZE  RA WSAME
loop0                       0    512      0     512     512    1 none            128 128    0B
loop1                       0    512      0     512     512    1 none            128 128    0B
loop2                       0    512      0     512     512    1 none            128 128    0B
sda                         0    512      0     512     512    1 mq-deadline     254 128    0B
├─sda1                      0    512      0     512     512    1 mq-deadline     254 128    0B
├─sda2                      0    512      0     512     512    1 mq-deadline     254 128    0B
└─sda3                      0    512      0     512     512    1 mq-deadline     254 128    0B
  ├─vgubuntu-root           0    512      0     512     512    1                 128 128    0B
  └─vgubuntu-swap_1         0    512      0     512     512    1                 128 128    0B
sr0                         0   2048      0    2048    2048    1 mq-deadline      64 128    0B

8. Display list format instead of tree format

The 'lsblk' command will display the output in a tree format. However, you can change it to list format by using the '-l' or '--list' option.

$ lsblk -l

Sample output

jayce@Ubuntu-01:~$ lsblk -l
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0             7:0    0     4K  1 loop /snap/bare/5
loop1             7:1    0 302.3M  1 loop /snap/code/131
loop2             7:2    0 302.3M  1 loop /snap/code/132
loop3             7:3    0 116.8M  1 loop /snap/core/14946
loop4             7:4    0 118.2M  1 loop /snap/core/15419
loop5             7:5    0  55.6M  1 loop /snap/core18/2751
sda               8:0    0    50G  0 disk
sda1              8:1    0     1M  0 part
sda2              8:2    0   513M  0 part /boot/efi
sda3              8:3    0  49.5G  0 part
sr0              11:0    1   3.6G  0 rom
vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
                                          /
vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]

9. Excluding the devices specified by the comma-separated list of major device numbers

With the '-e' or '--exclude' option, the output will exclude block devices by major type.

For example, if the major node type of 'loop' block device is '7', and you want to exclude it from the output, use the following command:

$ lsblk -e [major-value]

Sample output

jayce@Ubuntu-01:~$ lsblk -e 7
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                   8:0    0   50G  0 disk
├─sda1                8:1    0    1M  0 part
├─sda2                8:2    0  513M  0 part /boot/efi
└─sda3                8:3    0 49.5G  0 part
  ├─vgubuntu-root   253:0    0 45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
  │                                          /
  └─vgubuntu-swap_1 253:1    0  3.6G  0 lvm  [SWAP]
sr0                  11:0    1  3.6G  0 rom

10. Display specific columns only

With option '-o' or '--output', it will display specific columns that you want to list.

For example, to display only the NAME, SERIAL, MODEL, TYPE, SIZE and MOUNTPOINT of block devices, you can use the following command:

$ lsblk --output NAME,SERIAL,MODEL,TYPE,SIZE,MOUNTPOINT

Sample output

jayce@Ubuntu-01:~$ lsblk --output NAME,SERIAL,MODEL,TYPE,SIZE,MOUNTPOINT
NAME                SERIAL               MODEL                          TYPE   SIZE MOUNTPOINT
loop0                                                                   loop     4K /snap/bare/5
loop1                                                                   loop 302.3M /snap/code/131
loop2                                                                   loop 302.3M /snap/code/132
sda                                      VMware Virtual S               disk    50G
├─sda1                                                                  part     1M
├─sda2                                                                  part   513M /boot/efi
└─sda3                                                                  part  49.5G
  ├─vgubuntu-root                                                       lvm   45.8G /
  └─vgubuntu-swap_1                                                     lvm    3.6G [SWAP]
sr0                 01000000000000000001 VMware Virtual SATA CDRW Drive rom    3.6G

Here is my favorite way of doing it to display details about all the storage drives on the system, whether internal ssd, usb drives, external hdds and ssds.

$ lsblk -e7 -o "NAME,PTTYPE,FSTYPE,SIZE,LABEL,PARTLABEL,PATH,PHY-SEC,VENDOR"
NAME   PTTYPE FSTYPE   SIZE LABEL PARTLABEL PATH      PHY-SEC VENDOR
sda    dos           111.8G                 /dev/sda      512 ATA     
└─sda1 dos    ext4    95.4G                 /dev/sda1     512 
sdb    dos           111.8G                 /dev/sdb      512 ATA     
└─sdb1 dos    swap    95.8G                 /dev/sdb1     512 
sdc    gpt           447.1G                 /dev/sdc      512 ATA     
└─sdc1 gpt    ext4     400G                 /dev/sdc1     512 
sdd    dos           465.8G                 /dev/sdd      512 Samsung 
└─sdd1 dos    ext4     420G                 /dev/sdd1     512 
sde                      0B                 /dev/sde      512 Seagate 
$

The vendor ATA simply means that the drive is connected via a SATA (mostly internal) cable on the motherboard. Whereas the Samsung, and Seagate drives are external portable SSDs and HDDs respectively.

11. Checking whether it is a SSD or Hard Disk Drive (HDD)

To find out what is SSD or Hard Disk Drive, use the following command:

$ lsblk --output +ROTA,DISC-GRAN

Sample output

jayce@Ubuntu-01:~$ lsblk --output +ROTA,DISC-GRAN
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS                            ROTA DISC-GRAN
loop0                 7:0    0     4K  1 loop /snap/bare/5                              1        0B
loop1                 7:1    0 302.3M  1 loop /snap/code/131                            1        0B
loop2                 7:2    0 302.3M  1 loop /snap/code/132                            1        0B
sda                   8:0    0    50G  0 disk                                           1        0B
├─sda1                8:1    0     1M  0 part                                           1        0B
├─sda2                8:2    0   513M  0 part /boot/efi                                 1        0B
└─sda3                8:3    0  49.5G  0 part                                           1        0B
  ├─vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell    1        0B
  │                                           /
  └─vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]                                    1        0B
sr0                  11:0    1   3.6G  0 rom                                            1        0B

- ROTA: this column will show whether or not a block device belongs to a rotational storage device. Hard disk drive can spin, so this column outputs the value '1' (a binary logical value means 'true').

- DISC-GRAN: this column will show the discard granularity. SSDs support discarding to free up unused data blocks, HDD don't support this feature, so it normally will show no discard capabilities '0B'.

12. Display without slave or holders entries

You can use '-d' or '--nodeps' option to remove all the child devices in the output. It just displays the devices that you provided and doesn't include their partitions, etc.

Run the following command to output information about the 'sda' device only.

$ lsblk -d /dev/sda –output

Sample output

jayce@Ubuntu-01:~$ lsblk -d /dev/sda –output NAME,PTTYPE,FSTYPE,TYPE,SIZE,MOUNTPOINT
NAME PTTYPE FSTYPE TYPE SIZE MOUNTPOINT
sda  gpt           disk  50G

13. Displaying zone model for devices

The zone model of a block storage device can be discovered by option '-z' or '--zoned'. There are some possible values of the zoned model attributes, which are none, host-aware, host-managed.

$ lsblk -z

Sample output

jayce@Ubuntu-01:~$ lsblk -z
NAME                ZONED
loop0               none
loop1               none
loop2               none
sda                 none
├─sda1              none
├─sda2              none
└─sda3              none
  ├─vgubuntu-root   none
  └─vgubuntu-swap_1 none
sr0                 none

14. Display information about device owner, group, and mode of block devices

To output information about permissions of block devices, use options '-m' or '--perms'.

$ lsblk -m

Sample output

jayce@Ubuntu-01:~$ lsblk -m
NAME                  SIZE OWNER GROUP MODE
loop0                   4K root  disk  brw-rw----
loop1               302.3M root  disk  brw-rw----
loop2               302.3M root  disk  brw-rw----
loop3               116.8M root  disk  brw-rw----
loop4               118.2M root  disk  brw-rw----
loop5                55.6M root  disk  brw-rw----
sda                    50G root  disk  brw-rw----
├─sda1                  1M root  disk  brw-rw----
├─sda2                513M root  disk  brw-rw----
└─sda3               49.5G root  disk  brw-rw----
  ├─vgubuntu-root    45.8G root  disk  brw-rw----
  └─vgubuntu-swap_1   3.6G root  disk  brw-rw----
sr0                   3.6G root  cdrom brw-rw----

15. Hiding column headings

To exclude column heading when printing output, use option '-n' or '--noheadings'.

$ lsblk -n

Sample output

jayce@Ubuntu-01:~$ lsblk -n
loop0                 7:0    0     4K  1 loop /snap/bare/5
loop1                 7:1    0 302.3M  1 loop /snap/code/131
loop2                 7:2    0 302.3M  1 loop /snap/code/132
loop3                 7:3    0 116.8M  1 loop /snap/core/14946
loop4                 7:4    0 118.2M  1 loop /snap/core/15419
loop5                 7:5    0  55.6M  1 loop /snap/core18/2751
sda                   8:0    0    50G  0 disk
├─sda1                8:1    0     1M  0 part
├─sda2                8:2    0   513M  0 part /boot/efi
└─sda3                8:3    0  49.5G  0 part
  ├─vgubuntu-root   253:0    0  45.8G  0 lvm  /var/snap/firefox/common/host-hunspell
  │                                           /
  └─vgubuntu-swap_1 253:1    0   3.6G  0 lvm  [SWAP]
sr0                  11:0    1   3.6G  0 rom

16. Display block devices which are NOT in-use

If you want to identify block devices which are not in-use, you can combine 'lsblk' with option '-T' or '--tree' and 'jq' command. It is used to transform JSON data into a more readable format and display it to the standard output.

Run the following command to check which block devices and their children have no mount points.

$ lsblk --tree -o PATH,MOUNTPOINT -J | jq -r '.blockdevices[] | del(select(.mountpoint!=null or .children[]?.mountpoint!=null)) | .path // empty'

Sample output

jayce@Ubuntu-01:~$ lsblk --tree -o PATH,MOUNTPOINT -J | jq -r '.blockdevices[] | del(select(.mountpoint!=null or .children[]?.mountpoint!=null)) | .path // empty'
/dev/sr0

17. Display SCSI devices

To display SCSI devices only, use the '-S' or '--scsi' option.

$ lsblk -S

Sample output

jayce@Ubuntu-01:~$ lsblk -S
NAME HCTL       TYPE VENDOR   MODEL                           REV SERIAL               TRAN
sda  32:0:0:0   disk VMware,  VMware Virtual S               1.0                       spi
sr0  3:0:0:0    rom  NECVMWar VMware Virtual SATA CDRW Drive 1.00 01000000000000000001 sata

Conclusion

Managing block storage devices is one of the tasks we will have to do often while working on Linux. The only way to become proficient at working with this command is practicing, so consider working with the examples we mentioned in this article.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *