lsblk — List Block Devices

Swiss-army utility for inspecting Linux storage topology

lsblk (part of util-linux) reads /sys + udev DB to display block devices in a tree, optionally JSON, providing size, type, transport, mount-point, UUID, and more

Canonical pattern:

lsblk [options] [device…]

  1. Run lsblk (no args) to map every disk & partition.
  2. Add -f or -t to pull filesystem or topology detail.

Basic Listing

Tree vs list, human vs bytes

1 Tree (default)

lsblk displays all non-RAM devices in an ASCII hierarchy

2 Flat list

lsblk -l (one row per device)

3 Show mount-points

lsblk -f adds FS, LABEL, UUID info.

4 Exact bytes

lsblk --bytes avoids 4K/MB human abbreviations; critical for JSON math

Columns & Formats

Craft custom views or machine-readable output

1 Select columns

lsblk --output NAME,SIZE,MODEL

2 JSON / key-value

lsblk --json ⇢ parse with jq

lsblk --pairs ⇢ key="value" per line

3 Headers off

lsblk -n (no header row)

4 Remember layout

Env var LSBLK_COLUMNS defines default column set.

Filtering Devices

Include / exclude specific types or majors

1 Include only disks

lsblk -d (no partitions) or lsblk -o NAME,TYPE | grep disk

2 By transport / SCSI

lsblk -S show SCSI / NVMe model, serial.

3 Major-number filters

lsblk --exclude 1,7 skip RAM (1) and loop (7)

4 Only particular partitions

lsblk --include 8 show block major 8 (SCSI disks).

Topology & Hierarchy

How disks connect & what features they offer

1 Physical lanes

lsblk -t adds rota (SSD?), sched, rq-size, phy-sec.

2 I/O alignment

Column ALIGNMENT reports misaligned partitions → performance hints.

3 Hot-plug capabilities

Column HCTL shows host:channel:target:lun for SCSI.

Mounts & Permissions

Understand what’s in use before tinkering

1 Mount-points

lsblk -f -o NAME,FSTYPE,MOUNTPOINT

2 Who can see what?

Non-root sees everything but some fields blank if udev inaccessible

Automation & Scripting

Parse safely; avoid text-fragility

  1. lsblk --json --bytes | jq '.blockdevices[] | select(.type==\"disk\")'
  2. Combine with --nodeps to target parents only.
  3. Exit status 0 success; 32 when no devices found; other non-zero on error.

Cheat-Sheet Recipes

Handy one-liners for daily ops

GoalCommand
List removable USBs only lsblk -o NAME,RM,SIZE,MOUNTPOINT | awk '$2==1'
Find orphaned partitions lsblk -f | grep -v '/'
JSON inventory for CMDB lsblk --json --bytes > /var/tmp/disks.json
Check for 4 KiB mis-aligned starts lsblk -o NAME,PHY-SEC,LOG-SEC,START | awk '$4%8'

Best Practices & Caveats

Keep data safe & scripts stable

  1. Always include --bytes when parsing numbers programmatically.
  2. Prefer --json over awk/grep to survive util-linux updates.
  3. Remember dm-crypt / LVM hide parents; inspect with -p.
  4. Loop devices (major 7) filtered unless --all requested.
  5. Update util-linux: release 2.39 fixed JSON size bug, added columns like ZONED

References

Manual pages & technical notes

  1. lsblk(8) man-page, man7.org
  2. GeeksforGeeks lsblk examples
  3. util-linux 2.39 release notes
  4. --exclude explanation, manpages.ubuntu.com
  5. JSON bug discussion (GitHub #1636)
  6. Filtering disks discussion, StackExchange
  7. Site Reliability Engineer Handbook chapter on lsblk