LinuxCommandLibrary

lsblk

List block devices

TLDR

List all storage devices in a tree-like format

$ lsblk
copy

Also list empty devices
$ lsblk [[-a|--all]]
copy

Print the SIZE column in bytes rather than in a human-readable format
$ lsblk [[-b|--bytes]]
copy

Output info about filesystems
$ lsblk [[-f|--fs]]
copy

Use ASCII characters for tree formatting
$ lsblk [[-i|--ascii]]
copy

Output info about block-device topology
$ lsblk [[-t|--topology]]
copy

Exclude the devices specified by the comma-separated list of major device numbers
$ lsblk [[-e|--exclude]] [1,7,...]
copy

Display a customized summary using a comma-separated list of columns
$ lsblk [[-o|--output]] [NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT,...]
copy

SYNOPSIS

lsblk [options] [device...]

PARAMETERS

-a
    Show all block devices, including empty ones.

-b
    Print the SIZE in bytes rather than in a human-readable format.

-D
    Print information about discard (TRIM) capabilities.

-f
    Display filesystem information (FSTYPE, LABEL, UUID, MOUNTPOINT).

-J
    Use JSON output format.

-l
    Use a list format output rather than the default tree-like format.

-m
    Display permissions, owner, and group information (OWNER, GROUP, MODE).

-n
    Don't print a header line.

-o <list>
    Define the output columns to be displayed. Use lsblk --help for available columns.

-p
    Print full device paths (e.g., /dev/sda instead of sda).

-r
    Use raw output format.

-s
    Print inverse dependencies for a specific device, useful for LVM or RAID setups.

-V
    Display version information.

DESCRIPTION

lsblk is a utility used to list information about all available block devices on a Linux system. This includes hard drives, solid-state drives (SSDs), USB drives, CD-ROMs, RAM disks, LVM (Logical Volume Manager) volumes, and their respective partitions. It presents this information in a user-friendly, tree-like format by default, showing dependencies between devices and their partitions or sub-devices.

The command is invaluable for understanding the storage layout of a system, identifying specific devices by their name, size, or mount point, and troubleshooting disk-related issues. It gathers its information from the sysfs filesystem, specifically /sys/dev/block and /sys/block, providing a dynamic and accurate representation of the system's block device topology. Key columns typically displayed include NAME, MAJ:MIN (major and minor device numbers), RM (removable device), SIZE, RO (read-only), TYPE (disk, partition, lvm, etc.), and MOUNTPOINT. It offers numerous options to customize the output, allowing users to filter information, change the output format (e.g., list, raw, JSON), or display additional details like filesystem information or permissions.

CAVEATS

lsblk primarily focuses on local block devices. While it can show mounted network filesystems if they are backed by a block device visible to the kernel (e.g., iSCSI targets once connected and registered), it does not directly list network block devices or remote storage that isn't mapped to a local device node. For detailed information on very specific device types or advanced troubleshooting, other tools like fdisk, parted, or udevadm might be necessary. Some details (like certain permissions) might require root privileges.

COMMON USE CASES

lsblk is frequently used to:

  • Identify newly attached USB drives or external hard drives.
  • Examine the partition layout of a disk before formatting or resizing.
  • Find the UUID of a filesystem for entries in /etc/fstab.
  • Troubleshoot disk mounting issues by checking device names and mount points.

DEFAULT OUTPUT COLUMNS

By default, lsblk typically displays the following columns:

  • NAME: The device name (e.g., sda, sr0, dm-0).
  • MAJ:MIN: Major and minor device numbers.
  • RM: Removable device (1 for removable, 0 otherwise).
  • SIZE: The size of the device or partition.
  • RO: Read-only device (1 for read-only, 0 otherwise).
  • TYPE: The type of block device (e.g., disk, part, rom, lvm).
  • MOUNTPOINT: The directory where the device is mounted.

HISTORY

The lsblk command is part of the util-linux project, a collection of essential Linux utilities. It was developed to provide a more structured, readable, and consistent way of listing block devices compared to older methods that often involved parsing raw kernel output from /proc/partitions or relying on less standardized tools. Its design leveraged the sysfs filesystem, which became the standard for kernel device information, allowing lsblk to offer a rich and accurate view of the block device topology. It has become an indispensable tool for system administrators and users alike due to its clarity and flexibility.

SEE ALSO

fdisk(8), parted(8), df(1), mount(8), udevadm(8), blkid(8)

Copied to clipboard