lsblk and blkid: Inspecting Block Devices and UUIDs

lsblk and blkid: Inspecting Block Devices and UUIDs

How are lsblk and blkid different?

Conclusion: lsblk shows device topology and sizes; blkid reads UUID, LABEL, and filesystem type. They serve different jobs, so you use both.

The first step in any storage task is knowing exactly which device connects where and what its UUID is. Get this wrong and you can write a bad /etc/fstab line that leaves the system unbootable.

  • lsblk: lists the hierarchy of disk → partition → LVM/crypt, plus size and mount points
  • blkid: reads each device's UUID / LABEL / TYPE (filesystem) / PARTUUID

Which to reach for

  • See the big picture, capacity, mount state → lsblk / lsblk -f
  • Pull a single UUID for fstabblkid -s UUID -o value <dev>

Assumptions (target environment)

  • Distro: both Ubuntu and RHEL families (commands ship with util-linux)
  • A full scan may require root (sudo)

How do I list block devices with lsblk?

Conclusion: Run lsblk with no arguments to get a tree of every block device. The TYPE column distinguishes disk / part / lvm / crypt.

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   100G  0 disk
├─sda1        8:1    0     1G  0 part /boot
└─sda2        8:2    0    99G  0 part /
sdb           8:16   1  14.5G  0 disk
└─sdb1        8:17   1  14.5G  0 part /media/usb
nvme0n1     259:0    0 476.9G  0 disk
└─nvme0n1p1 259:1    0 476.9G  0 part /data

What the key columns mean:

  • NAME: device name (tree indentation shows parent/child)
  • RM: 1 if removable (USB sticks, etc.)
  • SIZE: capacity
  • RO: 1 if read-only
  • TYPE: disk / part / lvm / crypt / rom / loop
  • MOUNTPOINTS: mount target (empty if not mounted)

lsblk only reads sysfs / udev, so a regular user can run it (no root needed).

Handy options

$ lsblk -p          # full paths (e.g. /dev/sda1)
$ lsblk -d          # disks only, collapse partitions
$ lsblk -b          # sizes in bytes (for scripts)
$ lsblk -J          # JSON output (easy to pipe into jq)

How do I see UUIDs and filesystems with lsblk -f?

Conclusion: lsblk -f shows filesystem type, LABEL, UUID, and usage in one tree. For day-to-day checks this is usually enough.

$ lsblk -f
NAME        FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1      ext4   1.0   boot  6e1f...-a2c1                           812M    12%  /boot
└─sda2      ext4   1.0         9b3d...-77e0                          61.2G    35%  /
nvme0n1
└─nvme0n1p1 xfs          data  c4a8...-1f93                          410G     8%   /data

-f (--fs) uses libblkid under the hood and folds the same data blkid reports into the tree. Seeing FS type, UUID, and free space at a glance makes this your usual starting point.

To print only the columns you want, use -o:

$ lsblk -o NAME,SIZE,FSTYPE,UUID,MOUNTPOINT

List available column names with the COLUMNS section of lsblk --help, or use lsblk -O (all columns).

How do I check UUID, LABEL, and type with blkid?

Conclusion: blkid is the dedicated tool for filesystem attributes. Combine -s and -o value to extract just the UUID.

Run with no arguments to enumerate attributes for known devices.

$ sudo blkid
/dev/sda1: LABEL="boot" UUID="6e1f...-a2c1" TYPE="ext4" PARTUUID="2b1c...-01"
/dev/sda2: UUID="9b3d...-77e0" TYPE="ext4" PARTUUID="2b1c...-02"
/dev/nvme0n1p1: LABEL="data" UUID="c4a8...-1f93" TYPE="xfs" PARTUUID="8f0a...-01"

Pass a device to inspect just that one:

$ sudo blkid /dev/sda2

Extract only the UUID (for scripts)

For copying into fstab or for scripts, you want the value alone. Use -s (attribute name) and -o value (value only).

$ sudo blkid -s UUID -o value /dev/sda2
9b3d...-77e0

blkid probes the device superblock, so a full scan needs root. As a regular user it returns only what is cached in /run/blkid/blkid.tab, which may come back empty.

How do UUID and PARTUUID differ?

Conclusion: UUID belongs to the filesystem; PARTUUID belongs to the partition table (mostly GPT). Reformatting changes the UUID but keeps the PARTUUID.

Identifier Source Changes on reformat Typical use
UUID filesystem superblock yes fstab mount entries (most common)
LABEL filesystem label string freely editable human-readable identification
PARTUUID GPT partition table survives reformat bootloaders / areas with no FS
PARTLABEL GPT partition label freely editable per-partition identification

Swap and unformatted areas may have no filesystem UUID. Point at them with PARTUUID for stability.

How do I use UUID in fstab?

Conclusion: Names like /dev/sda2 can shift at boot, so UUID= is the safe choice in fstab. Paste the value you got from blkid.

The number in /dev/sdX can swap when you add a disk or boot timing changes. A fixed UUID removes that risk.

# 1. Get the UUID
$ sudo blkid -s UUID -o value /dev/sda2
9b3d...-77e0

# 2. Write it into /etc/fstab (tab/space separated)
# <device>          <mount> <type> <options>      <dump> <pass>
UUID=9b3d...-77e0   /data   xfs    defaults       0      2

See Mount and fstab Basics for the full walkthrough.

Common pitfalls and fixes

Conclusion: Most "no UUID" or "device missing" problems come down to missing privileges, an unformatted area, or a stale cache.

  • blkid is empty / partial → add sudo. Probing needs root
  • A freshly plugged USB is not in lsblk → re-run lsblk; if still absent, check dmesg | tail for detection logs
  • Some area shows no UUID → it is unformatted or swap. Point at it with PARTUUID
  • System will not boot after editing fstab → make mount -a validation a habit before reboot

Copy-paste: build an fstab line in one command

DEV=/dev/sda2
echo "UUID=$(sudo blkid -s UUID -o value "$DEV")  /data  $(sudo blkid -s TYPE -o value "$DEV")  defaults  0  2"

Summary / Next reading