Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Disks and Filesystems

Linux lsblk command

Reference for the Linux lsblk command: list disks, partitions and their mount points as a tree, choose columns with -o, get script-friendly output with -P and -J.

lsblk lists block devices (disks, partitions, LVM volumes, loop devices) in a tree that shows how they nest and where they are mounted. It reads the kernel's view from /sys and udev, needs no root rights, and does not touch the devices themselves, so it is the safe first command when you plug in a disk and want to know what it is called.

It is the friendly alternative to reading /proc/partitions or running fdisk -l.

Terminal
lsblk [OPTION]... [DEVICE]...

Try it

The sandbox has no /sys/dev/block, so lsblk itself prints an error here. Both examples therefore work on sample output that you would get from a real machine; the parsing code is the part you can reuse.

Bash Parsing key=value output (-P)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Working with bytes (-b) and the tree

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
lsblk [-a] [-b] [-d] [-f] [-l] [-n] [-p] [-r] [-J | -P] [-o COLUMNS] [-t] [DEVICE]...
Option Description
-a, --all Also list empty devices (such as a card reader without a card).
-b, --bytes Print sizes in bytes instead of 476.9G.
-d, --nodeps Show only the devices themselves, not their partitions.
-f, --fs Show filesystem information: NAME,FSTYPE,LABEL,UUID,MOUNTPOINT.
-l, --list List format instead of a tree.
-n, --noheadings Do not print the header line.
-p, --paths Full device paths (/dev/sda1).
-r, --raw Raw output with escaped spaces, good for awk.
-J, --json JSON output.
-P, --pairs KEY="value" pairs, one device per line.
-o COLUMNS Choose columns, for example NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT. lsblk --help lists all of them.
-t, --topology I/O topology (alignment, scheduler, request sizes).
-e CODES Exclude devices by major number. -e7 hides loop devices.

Useful column names: NAME, SIZE, TYPE (disk, part, lvm, loop, rom, crypt), RO, RM (removable), MOUNTPOINT, FSTYPE, LABEL, UUID, MODEL.

Returns: 0 on success; 1 on failure; 32 if a requested device was not found; 64 if only some devices were found. It fails if /sys is unavailable, as in minimal containers.

Usage notes

  • No root needed for the basic listing. Reading filesystem types, labels and UUIDs (-f) uses the udev database, or may need root when that database is empty. blkid probes the devices directly.
  • Before you format or write to a device, check the NAME, SIZE, MODEL and MOUNTPOINT columns. Mixing up /dev/sda and /dev/sdb with dd or mkfs destroys data.
  • Names change. sda and sdb can swap between boots. Identify disks by UUID, LABEL or /dev/disk/by-id/ in configuration files, not by sdX.
  • Mount points are for mounted filesystems only. A partition with an empty MOUNTPOINT may still be in use as swap ([SWAP]) or by LVM.
  • Parsing. Prefer -P or -J (with jq) over cutting columns: names may contain spaces in labels, and the tree characters (โ”œโ”€) are in the first column unless you pass -l or -r.
  • Loop devices for snap packages and disk images clutter the list on some systems; hide them with -e7.
  • Containers usually lack /sys/dev/block, so lsblk prints "failed to access sysfs directory" and exits non-zero. Use findmnt or df there.
  • lsblk shows structure, not usage. For free space use df; for partition tables use fdisk and parted.