Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

lsblk

List disks, partitions, LVM volumes and other block devices as a tree, with size, type and mount point.

Level
RHCSA exam
Group
Disks and file systems
Needs root
No
Package
util-linux

What it does

lsblk reads /sys and shows every block device and what sits on it: partitions, LVM logical volumes, RAID, encrypted volumes. With -f it adds the file system type, label, UUID and free space. It is the first command before you touch a disk.

How to write it

lsblk [OPTION]... [DEVICE]...

Options 33

Most used

What to show

-f, --fs
File system info: type, label, UUID, free space, mount point.
-o, --output LIST
Choose columns, like NAME,SIZE,FSTYPE,MOUNTPOINTS.
-O, --output-all
All columns.
-p, --paths
Full device paths (/dev/vdb1).
-d, --nodeps
Only the disks, not the partitions.
-a, --all
Also empty devices.
-A, --noempty
Hide empty devices.
-e, --exclude LIST
Leave out these major numbers (default RAM disks).
-I, --include LIST
Only these major numbers.
-m, --perms
Owner, group and mode.
-t, --topology
Alignment, sector sizes, scheduler.
-D, --discard
Discard (TRIM) support.
-S, --scsi
Only SCSI devices.
-N, --nvme
Only NVMe devices.
-v, --virtio
Only virtio devices.
-z, --zoned
Zone model.
-s, --inverse
Upside-down tree (from the device up).
-M, --merge
Group parents of sub-trees (RAID, multipath).
-E, --dedup COLUMN
Hide duplicates of a column.

Format

-l, --list
List, no tree.
-T, --tree[=COLUMN]
Tree format.
-J, --json
JSON output.
-P, --pairs
KEY="value" output.
-r, --raw
Raw output.
-y, --shell
Column names usable as shell variables.
-n, --noheadings
No header line.
-b, --bytes
Sizes in bytes.
-i, --ascii
ASCII tree lines.
-x, --sort COLUMN
Sort by a column.
-w, --width N
Output width.
--sysroot DIR
Read /sys from another root.
-h, --help
Show help.
-V, --version
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1All disks and partitions

    lsblk
    NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
    vda           252:0    0   20G  0 disk
    ├─vda1        252:1    0    1G  0 part /boot
    └─vda2        252:2    0   19G  0 part
      ├─rhel-root 253:0    0   17G  0 lvm  /
      └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]
    vdb           252:16   0   10G  0 disk

    vdb has no partitions: a new disk.

  2. 2File systems and UUIDs

    lsblk -f

    FSTYPE, LABEL, UUID, FSAVAIL, FSUSE%, MOUNTPOINTS.

  3. 3Only the disks

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

    Model and connection (sata, nvme, usb).

  4. 4One disk with full paths

    lsblk -p /dev/vdb

    Copy the paths for the next commands.

  5. 5Choose columns

    lsblk -o NAME,SIZE,TYPE,FSTYPE,UUID,MOUNTPOINTS

    Just what you need.

  6. 6Find empty disks

    lsblk -dn -o NAME,TYPE,SIZE | awk '$2=="disk"' ; lsblk -f

    A disk with no children and no FSTYPE is unused.

  7. 7JSON for scripts

    lsblk -J -o NAME,SIZE,MOUNTPOINTS | jq '.blockdevices[].name'

    Machine-readable.

  8. 8Check SSD TRIM support

    lsblk -D

    DISC-GRAN not 0 = discard works (fstrim.timer can use it).

  9. 9Who owns a device file

    lsblk -m /dev/vdb

    Owner, group and mode of the device node.

  10. 10See the device under a mount point

    lsblk -s /dev/mapper/rhel-root

    Inverse tree: from the LV down to the disk.

  11. 11Find USB disks that are plugged in (security)

    lsblk -o NAME,TRAN,SIZE,MOUNTPOINTS | grep usb

    Check for unknown removable storage.

Exit codes

0 :: Done. 1 :: Error. 32 :: No device found. 64 :: Some devices worked, some failed.