lsblk Command: Tutorial & Examples
List block devices
The lsblk
command in Linux displays a list of all block devices, such as hard drives and
their partitions, connected to the machine. It extracts its information directly from
the Linux Kernel. Unlike similar commands like fdisk
or ls
, lsblk
provides a tree-like hierarchical structure view of the devices, which is much
easier to understand.
Understanding lsblk
is crucial for managing storage devices and partitions. It can be used to identify devices and
their partitions, check disk space, and diagnose disk related issues.
How lsblk
Works
The lsblk
command gathers information from the sysfs
filesystem under /sys
,
specifically sysfs/block
. It lists all block devices and their associated partitions in a tree-like structure, with
the device at the top and its partitions as branches.
Solving Issues with lsblk
lsblk
can be helpful in several situations. For example, if you're experiencing
a disk space issue, you can use lsblk
to quickly check the sizes of your disks and
their partitions.
It's also handy if you're unsure which device corresponds to a particular disk or partition. The detailed output
of lsblk
includes the mount points of partitions, which can help you identify the correct
device to work with.
Examples of Using lsblk
Here are a few examples of how to use lsblk
:
To list all block devices and partitions in a tree-like structure:
lsblk
Typical output would look like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 9G 0 part
├─vg_root-lv_root
│ 253:0 0 6.5G 0 lvm /
└─vg_root-lv_swap
253:1 0 2.5G 0 lvm [SWAP]
To list block devices along with their size and file system type:
lsblk -fs
The output would include additional information:
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 /boot
└─sda2 LVM2_member
├─vg_root-lv_root
│ ext4 /
└─vg_root-lv_swap
swap [SWAP]
Conclusion
The lsblk
command is a powerful tool for managing and diagnosing issues with your storage devices. Its straightforward
output makes it easy to understand the layout of your disks and partitions, and its various options allow you to
customize the information displayed.