The lsblk (pronounced “L-S-block”) command is commonly used to get the list of all the block devices in your system with their information, such as size, type, mount point, etc.
If you are wondering, what are block devices? Then it’s basically files that represent the device connected to your system (except for ram disk).
In this article, you will learn how to list out and get information about all the block devices using the lsblk command and its options (with practical examples).
Tutorial Details
Description | Lists Information about Block Devices. |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | lsblk |
Internet Required | No |
Syntax of the lsblk Command
The lsblk command takes two arguments: one is the option, and the other is the block device name (both are optional).
$ lsblk [OPTION] [DEVICE...]
When you execute this command without any options or arguments, you will get the list of all the block devices in a tree-like format.
The following is an explanation of each field mentioned in the above output:
NAME
: Device nameMAJ:MIN
: Major and minor device numbers:RM
: Indicates the removable device with “1” and non-removable device with “0“.SIZE
: Device size in human-readable format, i.e., K, M, G, T, etc.RO
: Indicates the read-only status with “1” and not read-only status with “0“.TYPE
: Device type, i.e., disk, loopback device, partition, or LVM device.MOUNTPOINT
: Mount point to which the referenced device is mounted.
The following is an explanation of each device you will see in the output:
- Loopback devices: It represents the ISO image, disk image, file system, or logical volume image and assign them in loop0, loop1, loop2, etc.
- CD-ROM: It mainly indicates CD/DVD in the sr0 or sr1 format.
- Disk partitions: It represents the disk partition in SDA and assign them in sda1, sda2, and sda3 formats.
If you want to check the information for a specific block device, then specify its mount path (let’s say “/dev/sda“) as an argument to this command.
$ lsblk /dev/sda
Output:
Now, let’s see a few commonly used options with the lsblk command.
lsblk Command Options:
The lsblk command offers various options that can be used to add or remove columns from the output, print extra information about specific devices, hide the header, and much more.
Limited Columns in the Output
Using the “-o
” flag, you can manipulate the columns in the output by specifying each column with its name using a comma as a separator.
$ lsblk -o NAME,SIZE,MOUNTPOINT
Output:
The following is a list of column names supported by this option.
NAME
– device namePATH
– path to the device nodeMAJ:MIN
– major:minor device numberFSAVAIL
– filesystem size availableFSSIZE
– filesystem sizeFSTYPE
– filesystem typeFSUSED
– filesystem size usedFSUSE%
– filesystem use percentageFSROOTS
– mounted filesystem rootsMOUNTPOINT
– where the device is mountedLABEL
– filesystem LABELUUID
– filesystem UUIDPTTYPE
– partition table typePARTLABEL
– partition LABELPARTUUID
– partition UUID
Check the complete list using the “lsblk -h
” command.
List Empty Block Devices
A block device with zero size is skipped in the output and can be included using the “-a
” flag.
$ lsblk -a
Output:
Print the Size Column in Bytes
The default format used to mention the block device size is in human-readable format, i.e., in K, M, G, T, etc. However, you can use the “-b
” flag to print the size in bytes rather than in a human-readable format.
$ lsblk -b
Output:
Print the Output in List Format
By default, the command output will be in tree-like format, which can be changed to list format using the “-l
” flag.
$ lsblk -l
Output:
Print the Output without a Header
The “-n
” flag will remove the header from the columns while showing the output.
$ lsblk -n
Output:
Display Only the SCSI Devices
The “-S
” flag will only print the information about the SCSI devices, which are mostly your hard disk or CD/DVD.
$ lsblk -S
Output
Bonus Tip! Print All the Partitions and their UUID
Linux offers another command-line utility, blkid, that can be used to list all the recognized partitions and their Universally Unique Identifier (UUID).
$ blkid
Output:
Here comes the end of this article.
If you have any questions or queries related to this topic, then feel free to ask them in the comment section.
Till then, peace!
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.