Introduction
In the world of Linux system administration, knowing the available block devices is essential for tasks such as partitioning, formatting, mounting, and troubleshooting storage. The lsblk command (list block devices) has become an indispensable tool thanks to its clear and structured output, which hierarchically displays disks, partitions, logical volumes, and other block devices. Unlike older tools such as fdisk -l, lsblk does not require root privileges to show most of the information and adapts well to scripts and automation environments.
What is lsblk?
lsblk belongs to the util-linux package and reads information from the virtual /sys filesystem and the udev device manager to build a tree of block devices. Each line of the output represents a device and its columns indicate the name, major and minor numbers, size, device type, mount point, and other useful attributes. The tool is designed to be readable by both humans and programs, as it supports output formats such as JSON.
Basic Syntax
The simplest way to use lsblk is to run it without arguments:
lsblk
This will display all block devices detected on the system. If you want to limit the view to a specific device, you can specify its name:
lsblk /dev/sda
Furthermore, lsblk accepts numerous options that modify the amount and format of the displayed information.
Most Useful Options
-aor--all: shows empty devices, such as loop devices without an associated file.-bor--bytes: displays the size in bytes instead of human‑readable units.-for--fs: adds information about the filesystem, such as type, UUID, and mount point.-ior--ascii: forces the use of ASCII characters in the tree, useful when the output is copied to terminals that do not support Unicode.-Jor--json: generates the output in JSON format, ideal for integration into scripts.-oor--output: allows you to define exactly which columns to display, for examplelsblk -o NAME,SIZE,TYPE,MOUNTPOINT.
Practical Examples
Suppose you want to get a quick list of all disks and their partitions, with readable sizes and the mount point:
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
This will produce a table where each line shows the device name, its size, the filesystem type, and where it is mounted.
If you need to identify loop‑type devices associated with image files, you can combine -a with a type filter:
lsblk -a -o NAME,TYPE,SIZE,MOUNTPOINT | grep loop
To obtain the output in JSON and process it with jq, simply run:
lsblk -J | jq '.blockdevices[] | {name:.name, size:.size, mountpoint:.mountpoint}'
This approach is very useful in automation pipelines where you need to create or delete volumes based on their current size.
Interpreting the Output
The output of lsblk is organized as a tree. Devices that appear without indentation are the physical disks or top‑level storage units. Their partitions appear indented beneath them, indicating a containment relationship. Devices of type rom, disk, part, lvm, and loop are distinguished in the TYPE column. The SIZE field shows the total size of the device, while ROTA indicates whether the medium is rotational (value 1) or solid‑state (value 0). The MOUNTPOINT column shows where the filesystem is mounted; if it is empty, the device is not currently mounted.
Another useful column is MODEL, which, when combined with the -o option, displays the disk model as reported by the kernel, helping to identify specific units in servers with multiple disks.
Tips and Tricks
- Use
lsblk -fto quickly view the UUID of each partition, information essential when editing the/etc/fstabfile. - If you work with container or virtual machine environments, the
-d(--nodeps) option omits slave devices and shows only the top‑level devices. - To monitor changes in real time, combine lsblk with
watch:watch -n 1 lsblkupdates the list every second. - In scripts, prefer the JSON output (
-J) and process it with tools such asjqorpython -m json.toolto avoid text‑parsing issues. - Remember that lsblk only shows block devices; for character devices (such as
/dev/ttyor/dev/random) you need to uselsdevor inspect/devdirectly.
Conclusion
The lsblk command is a versatile and friendly tool that provides a clear and structured view of block devices on any Linux system. From simple visualization of disks and partitions to generating JSON data for automation, lsblk adapts to multiple administration and troubleshooting scenarios. Mastering its options and knowing how to interpret its tree output will allow you to manage storage more efficiently, reduce partitioning errors, and speed up the resolution of disk‑ and volume‑related problems. Whether you are an experienced system administrator or a newcomer to the Linux world, incorporating lsblk into your daily toolkit is an investment that quickly pays off in productivity and clarity.
This post is also available in ESPAÑOL.