- Posted on
- • Filesystem
Checking Filesystem Information with `lsblk`
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Exploring Your Linux Filesystem with the lsblk
Command
When managing a Linux system, it's essential to have a grasp of your disk drives and their respective partitions – not just for regular maintenance, but also for performing tasks like troubleshooting, system monitoring, or even when planning upgrades. One of the simplest and most effective tools for this purpose is the lsblk
command, which stands for "list block devices."
What is lsblk
?
lsblk
is a utility in Linux used to display information about all available or the specified block devices. It reads the sysfs
filesystem and udev
db to gather information. Block devices, in Linux terms, are storage devices that can be used for storing data, such as hard drives, solid state drives, and USB drives. This tool provides a neatly-formatted overview of these devices, their partitions, sizes, and where they are mounted in the filesystem.
Basic Usage of lsblk
To begin with, simply open your terminal and type lsblk
and press Enter. This will display a list of all the block devices, along with their major and minor device numbers, their size, the type of device, and where they are mounted:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 96G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sdb 8:16 0 500G 0 disk
├─sdb1 8:17 0 500G 0 part /data
In the output above, the device names (sda
, sdb
) are listed with their partitions (sda1
, sdb1
), sizes, and mount points. The RM
column shows whether the device is removable. The RO
column tells if the device is read-only. The TYPE
column shows whether the device is a disk or a partition (part).
Advanced Options
Show Filesystem Details
For more detailed output, including the filesystem type, you can combine lsblk
with the -f
option:
$ lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 ext4 7f49265f-8c08-4503-8844-6239db85ed1e /
├─sda2
└─sda5 swap d6f6bb73-d6b7-4a1f-93d0-7869cb10f010 [SWAP]
sdb
├─sdb1 xfs d8325f76-fbc4-4f55-b256-407ea3b0113e /data
This output now includes the filesystem type (FSTYPE
), and may also show a label (LABEL
) and UUID if available, which are useful for identifying and mounting file systems.
Exclude Loop Devices
On systems with many loop devices, for instance when using Docker, Cloudbase, or when mounting image files, output might get cluttered. To exclude them, use the -e
option:
$ lsblk -e 7
This usage of -e
filters out devices with a major number of 7, which are loop devices.
JSON and Tree View Outputs
For scripting purposes, a JSON output can be very useful. lsblk
offers a JSON formatted output which can be parsed by tools like jq
:
$ lsblk -J
For human-readable insights, especially during presentations or for better clarity, you can use the tree (-T) output:
$ lsblk -T
Conclusion
Whether you're a seasoned system administrator or a curious Linux beginner, understanding and using lsblk
is crucial for managing and inspecting your filesystems and block devices. Its full power is seen when combined with other commands and options, tailored to suit specific information needs. Get comfortable with lsblkk
– it’s a tool that pairs simplicity with profound capabilities, helping you to navigate the storage architecture of your Linux systems efficiently.
Further Reading
For further reading on Linux filesystem management and tools similar to lsblk
, consider these resources:
Linux Block Device Management: Dive deeper into block device management. More details at Red Hat Documentation.
Advanced Guide to
lsblk
: Explores more sophisticated usage oflsblk
. See Linuxize Tutorial.Understanding Filesystems in Linux: An in-depth guide on various filesystems supported by Linux at IBM Developer.
Mounting Disks in Linux: Learn the basics of mounting and unmounting filesystems. Available at Tecmint Guide.
Using
jq
with JSON Output: Provides techniques to parse JSON output from Linux commands includinglsblk
. Read more at jq Tutorial.