On Linux, you sometimes need to work with disks and/or partitions directly from the command line. Often, you actually want to perform actions on the filesystems, but you do so by specifying the partitions where they are stored. On the command line, you refer to these by using their device names (for example, “/dev/sda3”).
On systems with many disks, partitions, optical drives, and USB drives, it can be hard to identify the device name assigned to each of them.
What Does the lsblk Command Do?
lsblk displays information about storage devices. The utility is most often used to identify the correct device name to be passed to a subsequent command.
lsblk
Most of the time, lsblk
without any additional parameter, suffices to help identify the disk or partition you want to work with. From the picture above, for example, I can tell that “sda4” is a Windows partition, but that’s because I know its size is approximately 200GB. However, if you have two or more partitions of the same size, things may get more confusing. In other cases you may simply not know or remember the size of a particular disk or partition on your system.
On Linux, it’s dangerous to confuse device names, as you may destroy or corrupt useful data with a wrong command.
Useful lsblk Parameters
By default, lsblk displays just a few properties, as you saw in the picture above. But, if you add parameters to the command, you can make it output additional device properties. This, in turn, makes it much easier to identify the disk or partition you are looking for.
Find Out If It’s an SSD or Hard-Disk (HDD)
To see what extra columns lsblk can display, enter the following:
lsblk --help
In this scenario you will use ROTA and DISC-GRAN. ROTA tells you if a block device belongs to a rotational storage device. Hard disks are rotational, so the column outputs “1” besides them (binary logical value meaning “true”). DISC-GRAN shows you the discard granularity. SSDs support discard to free up unused data blocks. Hard disks do not support this feature, since they don’t need it, so this column will display a zero value for them (“0B,” meaning discard granularity of zero bytes).
lsblk -o +ROTA,DISC-GRAN
Show Filesystems Stored on Disks/Partitions
When you see a list of partitions, you might be able to tell what each of them stores, based on their sizes alone. When this is not enough, you can make lsblk output filesystems, too. It’s much easier to identify partitions this way because:
- Windows uses the NTFS filesystem
- Linux usually uses ext4
- A USB device uses FAT, FAT32 (vfat) or NTFS
- The EFI boot partition is usually very small and shows a vfat filesystem on it
Also, add the LABEL output column, which can help if partitions have been labeled when created/formatted.
lsblk -o +FSTYPE,LABEL
Show Removable Devices/USB Memory Sticks
lsblk -o +RM
will display an extra column that tells you if the device is removable. A “1” value means “true,” which indicates a USB stick or other types of removable media.
Show HDD/SSD Model
This is useful when you want to look up the exact code of your storage device model to upgrade your firmware or download drivers.
lsblk -d -o +MODEL
Show Filesystem UUID (Universally Unique Identifier)
Older Linux distributions mounted filesystems by specifying their device names in “/etc/fstab.” However, that proved unreliable since “/dev/sda2” might become “/dev/sdb2” when you add another storage device to the system. Nowadays, UUIDs are used instead, which remain constant no matter what you add/remove to/from your computer. For whatever reason you need UUIDs, you can make lsblk display them with
lsblk -o +UUID
Show Other lsblk Columns You Need
At the beginning of the tutorial, you used
lsblk --help
to see extra columns that lsblk can display. If the examples here are not sufficient for your needs, consult that help information again and combine parameters as needed. To do so, just enter lsblk -o +
, followed by the column names that you want to output. Separate column names with a comma (“,”). For example:
lsblk -o +SCHED,RM,FSTYPE
Conclusion
After you identify the device name you want to work with, remember to replace it with the full device path in the subsequent command you intend to use. For example, if you got “sda4” as a result in lsblk, you will have to replace it with “/dev/sda4” in the next command. So, instead of “sda4” you type “/dev/sda4” in a command like mkfs -t ext4 /dev/sda4
.
Our latest tutorials delivered straight to your inbox