lsblk Command in Linux (List Block Devices)

Written by: Bobbin Zachariah   |   Last updated: October 15, 2023

lsblk command is used to list information about all available block devices in Linux, whether they are mounted or not. Block devices can include physical devices such as hard drives and SSDs, as well as virtual devices such as loop devices and LVM logical volumes.

The lsblk command is normally used to display block devices and partition information. Whereas df command is used mostly for disk space usage of mounted filesystems.

The lsblk utility is preinstalled in most Linux Distributions. It comes under the utils-linux package.

Basic Usage

lsblk syntax is quite straightforward and can be expressed as follows:

lsblk [options] [device...]

The simplest form to use lsblk is without any arguments, which will display a list of block devices in a tree format.

lsblk
output of lsblk

Because lsblk uses udev, it doesn't need to directly access hardware or require root privileges for many of its operations.

lsblk Commands

Useful lsblk commands:

  • lsblk -a: Lists all block devices, including the ones that are not in use.
  • lsblk -f: Shows file system type, label, and UUID in the output.
  • lsblk -m: Displays the information with permission masks.
  • lsblk -o: Allows you to specify which columns to display in the output.
  • lsblk -b: Display size in bytes instead of in a human-readable format.
  • lsblk -l: Displays the information in a list format, rather than a tree format.
  • lsblk -p: Shows the full path of each device in the output.

Output Explained

lsblk command output with seven columns such as NAME, MAJ:MIN, RM, SIZE, RO, TYPE, and MOUNTPOINT. Each column is explained:

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 gives information on the size of the device.

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 the block device is a disk or a partition(part) within a disk. In the picture, sda is the disk while sr0 is a read-only memory (rom).

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

Examples

Let's check how to use lsblk command with examples.

01. To list all block devices

Use option -a to display all devices including empty devices:

lsblk -a
lsblk display all devices

02. To change the default lsblk output in tree-like format, use -l option

lsblk -l
lsblk list format

03. Display file system-related information

When you use the -f (or --fs) option with lsblk, it shows additional columns related to file system information, including file system type, label, and UUID (Universally Unique Identifier).

$ lsblk -f
NAME  FSTYPE   FSVER LABEL       UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
loop0 squashfs 4.0                                                          0   100% /snap/core22/858
loop2 squashfs 4.0                                                          0   100% /snap/core22/864
loop3                                                                       0   100% /snap/radare2/2460
loop4                                                                       0   100% /snap/snapd/20092
loop5                                                                       0   100% /snap/snapd/20290
loop6                                                                       0   100% /snap/radare2/2467
sda   ext4     1.0   linode-root 8654faf8-c54a-2d86-f082-73098653e58f   16.1G    28% /
sdb   swap     1                 0346c46b-bd50-4f7f-8aef-2cac6d3dec15                [SWAP]

You may also use blkid which is more straightforward and script-friendly for focused tasks involving UUIDs and filesystem types.

03. Show specific device

Use lsblk following the device name to display information about a specific device.

For example:

lsblk /dev/sda5
lsblk information about specific device

04. Display only selective columns

If you want you can display the output of specific columns use the -o option.

For example to list name and size columns type:

lsblk -o name,size
list specific columns

05. Display device permissions

You can use lsblk to print each device ownership and permissions using -m option.

lsblk -m
lsblk display device permissions

06. To Display only SCSI devices use -S option.

lsblk -S
lsblk display scsi devices

07. Display output in ASCII character format.

The default tree format is not user friendly and you can use -i option to display in ASCII format:

lsblk -i

08. To display the zone model of each device use -z option.

lsblk -z

09. Exclude specific devices by major number

lsblk -e 8,11

The -e option used to exclude devices based on their major number. You can provide a comma-separated list of major device numbers you wish to exclude.

$ lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0   7:0    0  73.9M  1 loop /snap/core22/858
loop2   7:2    0  73.9M  1 loop /snap/core22/864
loop3   7:3    0 187.2M  1 loop /snap/radare2/2460
loop4   7:4    0  40.8M  1 loop /snap/snapd/20092
loop5   7:5    0  40.9M  1 loop /snap/snapd/20290
loop6   7:6    0 187.2M  1 loop /snap/radare2/2467
sda     8:0    0  24.5G  0 disk /
sdb     8:16   0   512M  0 disk [SWAP]
$ lsblk -e 7
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda    8:0    0 24.5G  0 disk /
sdb    8:16   0  512M  0 disk [SWAP]

Here I have excluded major 7 which narrowed the output to list all available disks using major 8.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is an experienced Linux engineer who has been supporting infrastructure for many companies. He specializes in Shell scripting, AWS Cloud, JavaScript, and Nodejs. He has qualified Master’s degree in computer science. He holds Red Hat Certified Engineer (RHCE) certification and RedHat Enable Sysadmin.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment