This tutorial discusses how to use the lsblk command to display information about block devices in a system. The tool utilizes the /sys virtual filesystem to fetch information about the devices. However, it’s worth noting that the tool does not display the RAM disk in the output.
How to Install lsblk?
The lsblk command comes bundled as part of the utils-Linux package that has various low-level system tools. The utils-Linux package also contains tools such as fdisk, login daemon, all of which are essential for Linux system functionality.
To install the package on Ubuntu and Debian based distributions, use the command below:
For Fedora and REHL family, use the following command:
How to Use lsblk?
Without arguments, the lsblk command will display a list of the block devices in a tree-format, as shown below:
The output from the lsblk command comes arranged in various columns. The following are the columns from the command and what they represent:
- NAME: The first column shows the device name.
- MAJ:MIN: The second column, respectively, indicates the major and minor device numbers.
- RM: This column displays Boolean values for removable and non-removable devices. 1 indicates that the device is removable, and 0 indicates that the device is non-removable.
- SIZE: This displays the device size in a readable format, i.e., In K, M, G, T, etc. You can use the lsblk –bytes /dev/<name> to display the size in bytes.
- RO: This column shows the read-only status of a device. 1 indicates the device is read-only, and 0 indicates not read-only.
- TYPE: This column shows the type of devices, such as disk, loopback device, partition, or LVM device.
- MOUNTPOINT: This displays the mount point on which the device is mounted.
Devices in lsblk output
Some of the devices you will see in the lsblk output are:
- Loopback devices: Loopback devices mainly contains ISO image, a disk image, a file system, or a logical volume image. Their main identification is using loop0, loop1, etc.
- CD-ROM: They are mainly indicated with sr0 and have properties such as RM of 1.
- Disk partitions: The main indicator used for Disk partitions is sda, followed by sda1, sda2…sda(n).
List all devices
The default lsblk command does not display all free devices. To do this, add the -a argument to the command as:
List format
The lsblk command will display the output in a tree-like format. However, you can change this by using the -l argument as:
Selective Columns
We can also use -o followed by the names of the columns we want to output for selective information as:
Device Permissions
To view device permissions and ownership, use the command:
Information about specific devices
To list information about a particular block device, specify the device name in the lsblk command as:
List devices without the header
To remove the header from the output, use the -n flag in the command as:
Display SCSI Devices
To display SCSI devices only, use the -S flag in the command:
Conclusion
In this tutorial, we discussed how to work with the lsblk command to display information about block devices that are connected to the system. The only way to master working with this command is to experiment. Therefore, consider experimenting with the commands discussed in this tutorial.