The lsblk command in Linux: list block devices

Introduction

In the world of Linux system management, knowing the available block devices is essential for tasks such as partitioning, formatting, assembly and storage problem solution. The commandlsblk(list block devices) has become an indispensable tool thanks to its clear and structured output, which shows hierarchical disks, partitions, logical volumes and other block devices. Unlike older tools likefdisk -l, lsblk does not require root privileges to show most of the information and is well suited to scripts and automation environments.

What's lsblk?

lsblk belongs to the util-linux package and reads the information of the virtual file system/sysand the device managerudevto build a block device tree. Each output row represents a device and its columns indicate the name, the larger and smaller numbers, the size, the type of device, the assembly point and other useful attributes. The tool is designed to be readable by both humans and programs, as it supports output formats like JSON.

Basic syntax

The simplest way to use lsblk is to run it without arguments:

lsblk

This will show all the block devices detected in the system. If you want to limit the view to a particular device, you can specify its name:

lsblk / dev / sda

In addition, lsblk accepts numerous options that change the amount and format of the information shown.

Most useful options

  • -aor--all: shows empty devices, such as those of loop without associated file.
  • -bor--bytes: shows the size in bytes instead of legible units.
  • -for--fs: adds information about the file system, such as type, UUID and assembly 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 output in JSON format, ideal for integration in scripts.
  • -oor--output: allows to define exactly which columns will be shown, for examplelsblk -o NAME,SIZE,TYPE,MOUNTPOINT.

Practical examples

Suppose you want to get a quick list of all the disks and their partitions, with readable sizes and the assembly point:

lsblk -or NAME, SIZE, FSTYPE, MOUNTPOINT

This will produce a table where each line shows the name of the device, its size, the type of file system and where it is mounted.

If you need to identify the type devicesloopthat are associated with image files, you can combine-awith a type filter:

lsblk -a -o NAME, TYPE, SIZE, MOUNTPOINT | grep loop

To get the JSON output and process it withjq, just run:

lsblk -J | jq '.blockdevices [] | {name: .name, size: .size, mountain point: .mountain point} '

This approach is very useful in automation pipelines where volumes are required to be created or removed based on their current size.

Interpretation of the exit

The output of lsblk is organized in the form of a tree. The devices that appear without bleeding are the physical disks or top level storage units. Their partitions appear indentated under them, indicating a containment relationship. Type-devicesrom, disk, part, lvmandloopare distinguished in the columnTYPE. The fieldSIZEshows the total size of the device, whileROTAindicates whether the medium is rotating (value 1) or solid state (value 0). The columnMOUNTPOINTshows where the file system is mounted; if it is empty, the device is not mounted at that time.

Another useful column isMODEL, that, when combined with the option-o, shows the disk model as reported by the kernel, which helps to identify specific units on multiple disk servers.

Tips and tricks

  • Uselsblk -fto quickly view the UUID of each partition, essential information when editing the file/etc/fstab.
  • If you work with container environments or virtual machines, the option-d (--nodeps) omits slave devices and displays only the main devices.
  • To monitor real-time changes, combine lsblk withwatch: watch -n 1 lsblkupdate the list every second.
  • In scripts, you prefer the JSON output (-J) and process with tools likejqorpython -m json.toolto avoid text parsing problems.
  • Remember that lsblk only displays block devices; for character devices (such as/dev/ttyor/dev/random) you need to uselsdevor inspect/devdirectly.

Conclusion

The commandlsblkis a versatile and friendly tool that provides a clear and structured view of block devices in any Linux system. From simple display of disks and partitions to JSON data generation for automation, lsblk is adapted to multiple management and diagnostic scenarios. Domain your options and know how to interpret your output tree will allow you to manage storage more efficiently, reduce partitioning errors and accelerate resolution of disks and volumes related problems. Whether you are an experienced system manager or a newcomer to the Linux world, incorporating lsblk into your daily toolkit is an investment that is quickly paid for productivity and clarity.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish