Website Vidya
Linux & ServersStep-by-Step Guide

lsblk Command in Linux: Block Devices & Filesystems

Learn lsblk command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

RR
Rajesh RayLead Systems Educator
Published:
9 min read
PDF Cheat Sheet
lsblk Command in Linux: Block Devices & Filesystems
AI Executive SummaryWebsiteVidya AI

9 min read

Learn lsblk command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What lsblk Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

Storage provisioning, partition management, and disk troubleshooting in Linux rely on the lsblk command in linux. Provided by the essential util-linux package, lsblk (list block devices) queries the kernel to present an intuitive, tree-structured overview of all attached storage hardware and virtual block devices.

Unlike legacy tools such as fdisk -l or blkid that output flat text streams, lsblk visualizes the parent-child relationships between physical storage devices (such as SCSI disks /dev/sda or NVMe drives /dev/nvme0n1), partition tables, device-mapper targets (LVM physical and logical volumes, LUKS encrypted containers), and filesystem mount points.

With built-in support for customized column selection (-o), filesystem type and UUID extraction (-f), and structured JSON output (-J), lsblk is an indispensable tool for both interactive sysadmin diagnostics and automated cloud infrastructure provisioning.

Advertisement
lsblk Command in Linux: Block Devices & Filesystems — syntax, flags, and practical terminal workflow diagram
lsblk Command in Linux: Block Devices & Filesystems — command syntax, key options, and production workflow reference.

What lsblk Does and When to Use It

Architecturally, lsblk gathers information directly from the Linux kernel's sysfs virtual filesystem mounted at /sys/block/ and /sys/dev/block/, as well as udev device database caches. It does not require root privileges or issue low-level disk I/O reads to query device topology, making it exceptionally fast and completely non-intrusive.

To extract filesystem metadata (such as filesystem type, UUID, and volume labels), lsblk interfaces with the libblkid library. The library checks the superblock signatures cached by the kernel or reads device headers safely without mounting filesystems. When displaying trees, lsblk uses major:minor device numbers (MAJ:MIN) to correlate device mapper and loopback devices with their underlying physical parent block drivers.

Under the hood, lsblk gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as -a, -b, -f, -m turns raw process and service tables into actionable diagnostics during incident response.

Availability and Installation Across Linux Distributions

The lsblk utility is packaged in util-linux across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:

Advertisement

Before running administrative tasks or automation scripts, verify whether lsblk is installed and inspect which binary path and version your shell resolves:

type -a lsblk
lsblk --version 2>/dev/null || man -f lsblk

# Illustrative output (reviewed against documentation)
lsblk is /usr/bin/lsblk
lsblk (util-linux)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y util-linux

# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y util-linux

# Arch Linux
sudo pacman -S --noconfirm util-linux

# Alpine Linux
sudo apk add --no-cache util-linux

Command Syntax, Arguments, and Exit Status Codes

lsblk [options] [device...]

The command syntax is lsblk [options] [device...]. When invoked with no options, lsblk prints all non-empty storage devices in a tree view showing NAME, MAJ:MIN, RM (removable), SIZE, RO (read-only), TYPE (disk, part, lvm), and MOUNTPOINTS.

The most useful flags include -f (--fs), which displays filesystem type (FSTYPE), label (LABEL), and filesystem UUID; -o (--output) to customize exact column fields; -m (--perms) to inspect device node ownership and permission modes; -a (--all) to list empty devices and RAM disks; and -J (--json) to emit structured JSON arrays.

  • 0 — Block devices enumerated and displayed successfully.
  • 1 — Operational failure, such as specified block device not found.
  • 2 — Malformed command-line option or invalid column argument.

Important Options and Flags Reference

Option / FlagLong Form / ArgumentTechnical Behavior and Purpose
-a--allLists all devices, including empty devices and RAM disks.
-b--bytesPrints device sizes in exact bytes rather than human-readable units.
-f--fsOutputs filesystem information: FSTYPE, LABEL, UUID, FSAVAIL, FSUSE%, and MOUNTPOINTS.
-m--permsOutputs device owner, group, and permission mode bits.
-o <LIST>--output=<LIST>Specifies comma-separated list of output columns (e.g. NAME,SIZE,FSTYPE,UUID).
-p--pathsPrints complete device pathnames (e.g. /dev/sda1) rather than short basenames.
-J--jsonFormats output as a valid JSON object tree for automated parsing with jq.
-l--listProduces a flat list output instead of the default tree format.
-d--nodepsSuppresses child partitions and holders, printing only primary device lines.

The -f (--fs) option is essential when configuring persistent mounts in /etc/fstab. In modern Linux distributions, mounting filesystems by device name (like /dev/sdb1) is hazardous because device names can shift across reboots when storage controllers reorder disks. Running lsblk -f displays the permanent filesystem UUID, allowing administrators to declare reliable UUID=... entries in fstab.

Advertisement

Combining -J (--json) with jq is the modern standard for automated cloud-init and storage provisioning pipelines. Instead of fragile text scraping of fdisk output with awk or regex, lsblk -J emits clean, typed data structures containing exact partition sizes, filesystem types, and mount points.

When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.

Practical Basic and Advanced Usage Examples

1. Display Block Device Tree Hierarchy

List all block devices and partitions in their default tree view.

lsblk

# Illustrative output (reviewed against documentation)
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0    50G  0 disk 
├─sda1        8:1    0     1G  0 part /boot
└─sda2        8:2    0    49G  0 part 
  ├─vg-root 253:0    0    40G  0 lvm  /
  └─vg-swap 253:1    0     9G  0 lvm  [SWAP]
sr0          11:0    1  1024M  0 rom

The tree shows that sda is partitioned into sda1 and sda2, with sda2 holding an LVM volume group containing vg-root and vg-swap.

2. Display Filesystem Types and UUIDs with -f

Extract filesystem types, UUIDs, and mount points for fstab configuration.

lsblk -f

# Illustrative output (reviewed against documentation)
NAME        FSTYPE      FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda                                                                                         
├─sda1      ext4        1.0         3d88b410-1240-4bf5-88a1-8e921d740c01    680M    28% /boot
└─sda2      LVM2_member 001         A1B2-C3D4-E5F6-7890-ABCD-EF01-234567                    
  ├─vg-root ext4        1.0         c48201ad-89ff-410a-b21a-4299912048aa     18G    52% /
  └─vg-swap swap        1           89a1c021-4201-44bb-8812-9844201a01ff                   [SWAP]

The -f flag exposes UUIDs for each partition and volume, providing the exact identifiers needed for fstab.

3. Print Full Device Pathnames with -p

Display full canonical paths (/dev/sda) instead of short basenames.

lsblk -p

# Illustrative output (reviewed against documentation)
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/sda               8:0    0   50G  0 disk 
├─/dev/sda1            8:1    0    1G  0 part /boot
└─/dev/sda2            8:2    0   49G  0 part 
  ├─/dev/mapper/vg-root 253:0 0   40G  0 lvm  /
  └─/dev/mapper/vg-swap 253:1 0    9G  0 lvm  [SWAP]

The -p option prefixes device names with /dev/, making output convenient for copy-pasting into partition tools.

4. Select Custom Columns for Storage Reporting (-o)

Specify exact columns to display only the device attributes required.

lsblk -o NAME,SIZE,FSTYPE,MODEL,MOUNTPOINTS

# Illustrative output (reviewed against documentation)
NAME         SIZE FSTYPE      MODEL            MOUNTPOINTS
sda           50G             QEMU HARDDISK    
├─sda1         1G ext4                         /boot
└─sda2        49G LVM2_member                  
  ├─vg-root   40G ext4                         /
  └─vg-swap    9G swap                         [SWAP]

The -o flag limits output to the requested columns, adding hardware MODEL metadata.

5. Export Storage Topology as JSON for Automation (-J)

Emit structured JSON for programmatic parsing with jq in shell scripts.

lsblk -J -o NAME,SIZE,FSTYPE,MOUNTPOINTS

# Illustrative output (reviewed against documentation)
{
   "blockdevices": [
      {
         "name": "sda",
         "size": "50G",
         "fstype": null,
         "mountpoints": [null],
         "children": [
            {
               "name": "sda1",
               "size": "1G",
               "fstype": "ext4",
               "mountpoints": ["/boot"]
            }
         ]
      }
   ]
}

The -J flag outputs a well-formed JSON object tree representing block devices and child partitions.

6. List Only Top-Level Disks Without Partitions (-d)

Filter out child partitions to identify raw physical drives attached to the system.

lsblk -d -o NAME,SIZE,MODEL,ROTA

# Illustrative output (reviewed against documentation)
NAME  SIZE MODEL            ROTA
sda    50G QEMU HARDDISK       1
sdb   200G QEMU HARDDISK       1

-d suppresses partitions. ROTA=1 indicates spinning hard drives, while ROTA=0 indicates non-rotational SSD/NVMe.

Real-World Workflows, Pipelines, and Shell Automation

Automated Unformatted Disk Discovery and Partitioning Pipeline

In cloud-init or automated provisioning scripts, identify unformatted and unmounted raw storage volumes attached to a virtual machine so they can be partitioned and formatted automatically.

echo "Scanning for unformatted raw data disks..."
RAW_DISKS=$(lsblk -J -d -o NAME,TYPE,FSTYPE,MOUNTPOINTS | jq -r '
  .blockdevices[]
  | select(.type == "disk" and .fstype == null and .mountpoints == [null] and (.name | startswith("loop") | not))
  | .name
')

for disk in $RAW_DISKS; do
  echo "Discovered unformatted raw disk: /dev/$disk"
  echo "Ready for provisioning: sudo parted /dev/$disk mklabel gpt"
done

# Illustrative output (reviewed against documentation)
Scanning for unformatted raw data disks...
Discovered unformatted raw disk: /dev/sdb
Ready for provisioning: sudo parted /dev/sdb mklabel gpt

Combining lsblk -J with jq cleanly filters for disks that have no filesystem and no active mount points.

Persistent Filesystem Mount Configuration Verification

Before modifying /etc/fstab, generate a clear audit mapping device names, UUIDs, filesystem types, and current mount points to prevent boot failures.

echo "=== Current Persistent Mount Mapping ==="
lsblk -p -r -n -o NAME,UUID,FSTYPE,MOUNTPOINT | while read -r dev uuid fstype mnt; do
  if [ -n "$uuid" ] && [ -n "$mnt" ]; then
    echo "Device: $dev -> UUID=$uuid -> Mount: $mnt (Type: $fstype)"
  fi
done

# Illustrative output (reviewed against documentation)
=== Current Persistent Mount Mapping ===
Device: /dev/sda1 -> UUID=3d88b410-1240-4bf5-88a1-8e921d740c01 -> Mount: /boot (Type: ext4)
Device: /dev/mapper/vg-root -> UUID=c48201ad-89ff-410a-b21a-4299912048aa -> Mount: / (Type: ext4)

Extracts active mounts and their UUIDs cleanly, providing verified parameters for /etc/fstab entry authoring.

Pipelines, Redirection, Quoting, and Shell Expansion

When embedding lsblk inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.

Permissions, Security Implications, and Safe Execution

Unlike fdisk, parted, or blkid, lsblk does not require superuser (root) privileges to execute. Any unprivileged user can run lsblk to inspect storage topology, filesystem types, and mount points because sysfs (/sys/block) is world-readable.

The -m (--perms) flag exposes the device node mode bits (such as brw-rw---- root:disk /dev/sda). Users who belong to the disk group possess raw block device read/write privileges, which allows bypassing filesystem permissions and reading raw data blocks directly.

GNU/Linux, BSD, and BusyBox Implementation Differences

The lsblk utility is specific to Linux and is maintained as part of the util-linux project. It relies on Linux sysfs and udev architectures, and is not available on BSD (macOS, FreeBSD).

On macOS, the equivalent command is diskutil list; on FreeBSD, use geom disk list. In minimal Alpine Linux containers, lsblk is provided by installing the util-linux package (apk add util-linux).

Troubleshooting Common Errors and Diagnostics

lsblk: command not found

Root Cause: The util-linux package is not installed, which commonly occurs in minimal Docker or container base images.

Resolution: Install util-linux using your distribution's package manager.

sudo apt-get update && sudo apt-get install -y util-linux

Newly attached disk does not appear in lsblk output

Root Cause: The Linux kernel has not yet rescanned the SCSI or NVMe bus after a live disk attachment in a virtualized or SAN environment.

Resolution: Trigger a manual SCSI bus rescan through sysfs.

echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan

lsblk shows [SWAP] but no filesystem UUID for swap partition

Root Cause: The swap partition has not been formatted with mkswap, or was activated without an assigned UUID.

Resolution: Turn off swap with swapoff, run mkswap /dev/partition to assign a filesystem signature and UUID, and re-enable with swapon.

sudo swapoff /dev/sda2
sudo mkswap /dev/sda2
sudo swapon /dev/sda2

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
Yes. lsblk reads block devices known to the Linux kernel via sysfs, so it displays all attached physical and virtual drives, partitions, and volumes regardless of whether they are mounted.
Run lsblk -o NAME,ROTA. The ROTA column indicates rotational media: ROTA=1 means a traditional spinning hard drive (HDD), while ROTA=0 indicates a solid-state drive (SSD or NVMe).
Run lsblk -f or lsblk -o NAME,UUID. The UUID column lists the unique filesystem identifier required for /etc/fstab.
lsblk displays all block devices in a clear tree showing partitions, LVM volumes, and mount points without requiring root privileges. fdisk -l requires root privileges, reads the physical partition table headers from disk, and outputs a technical sector-by-sector table.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout