21.1 lsblk: Listing Block Devices and Their Layout
Right, let’s talk about lsblk. This is one of those utilities you’ll use so often it’ll become a reflex, like checking your rearview mirror before changing lanes. It’s the fastest, most straightforward way to answer the fundamental question: “What storage is actually attached to this machine, and how is it currently organized?”
Forget fumbling through /dev/ and trying to guess which sdX letter you are. lsblk gives you a clean, hierarchical tree view of every block device—your hard drives, SSDs, USB sticks, optical drives, and their partitions—showing you exactly how they relate to each other. It’s like an X-ray for your storage.
The Default View: Your Storage at a Glance
Just run it. No arguments. This is its most useful form.
lsblk
You’ll get output that looks something like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 238G 0 part /
nvme0n1 259:0 0 1.8T 0 disk
├─nvme0n1p1 259:1 0 100M 0 part
├─nvme0n1p2 259:2 0 16M 0 part
└─nvme0n1p3 259:3 0 1.8T 0 part /data
Let’s break down what we’re seeing. NAME is the device node in /dev/. Notice the hierarchy: the physical disk (e.g., sda) and its child partitions indented underneath it. TYPE is crucial here; it tells you what kind of object you’re looking at.
SIZE is presented in human-readable units, which is almost always what you want. RM tells you if the device is removable (1 for yes, 0 for no)—a lifesaver when you’re trying to figure out if that /dev/sdb is your internal drive or the USB stick you forgot about. RO does the same for read-only status. MOUNTPOINT is the crown jewel: it instantly shows you where a filesystem is currently active, saving you from a separate mount or df command.
Why the Output Looks Like That (It’s Not Random)
You’ll notice devices are named sda, sdb, nvme0n1, etc. This isn’t arbitrary. It’s a relic of history mixed with modern sense.
sdX: Stands for SCSI Disk. Yes, even your SATA and USB drives use this because the kernel treats them like SCSI devices through a layer of abstraction. It’s a holdover, but a consistent one.sdais the first discovered,sdbthe second, and so on.nvmeXnY: This is the modern, sensible naming scheme for NVMe drives.nvme0is the first controller,n1is the namespace on that controller, andp1is the first partition. It’s actually logical! Praise the kernel gods.
The MAJ:MIN numbers are the major and minor device numbers the kernel uses to identify the device. You’ll rarely need these, but they’re the underlying reality that the friendly /dev/sda name abstracts away. It’s good to know they’re there.
Getting the Gory Details with -f and -o
The default view is great, but sometimes you need more. This is where lsblk flexes its muscles.
Want to see the filesystem type, label, and UUID? Use the -f flag (think “filesystem”).
lsblk -f
NAME FSTYPE FSVER LABEL UUID MOUNTPOINT
sda
├─sda1 vfat FAT32 ABCD-1234 /boot/efi
└─sda2 ext4 1.0 a1b2c3d4-e5f6-7890-abcd-ef1234567890 /
nvme0n1
└─nvme0n1p1 ntfs Backup 1234567890ABCDEF
Why is this a big deal? Because most system configuration files (like /etc/fstab) use the UUID or label to identify devices, not the flaky /dev/sdX name which can change if you plug another drive in. This output lets you directly copy the UUID into your fstab. It’s a huge time-saver.
If you want to go full nerd and see everything lsblk knows, use --json or the -o flag to specify exactly which columns you want. The list of available columns is vast (lsblk --help will show you). Want to see the device’s minimum I/O size? Go for it.
lsblk -o NAME,SIZE,ROTA,MOUNTPOINT,MIN-IO
NAME SIZE ROTA MOUNTPOINT MIN-IO
sda 238.5G 1 / 512
nvme0n1 1.8T 0 /data 4096
Notice ROTA? That stands for Rotational. A 1 means it’s a spinning hard disk (so RotationAl). A 0 means it’s not—it’s an SSD. This is a brilliantly simple way to tell your physical disks apart.
Common Pitfalls and the “Gotcha” Moment
The biggest “gotcha” with lsblk is also its greatest feature: it only shows block devices. This seems obvious, but it trips people up. If a device isn’t showing up in lsblk, it means the kernel doesn’t see it as a block device. This could mean:
- A driver issue (the kernel doesn’t know what the hardware is).
- A connection problem (the cable is loose, the port is dead).
- It’s the wrong type of device (e.g., a serial device might show up in
/dev/asttyS0but never inlsblk).
Another quirk: lsblk by default tries to show the ownership of the mountpoint, which requires permissions. If you run it as a unprivileged user, you might see some mountpoints but not others, or see empty MOUNTPOINT columns for devices you don’t own. If you need the absolute truth, run it with sudo. The command itself doesn’t need elevated privileges to list devices, but seeing some of the associated metadata does.
So, the next time you’re about to fdisk a disk, make lsblk your first stop. It’s the single best way to orient yourself before you start making potentially destructive changes. It’s the friend that points out the “CAUTION: WET FLOOR” sign before you embarrassingly slip and fall.