List Device Names, Disk and Partition Information in Linux with lsblk

Lsblk Featured

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 Without Parameters

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:

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 Show Ssds And Hard Disks

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.

Show Removable Devices/USB Memory Sticks

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.

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

Show Other lsblk Columns You Need

At the beginning of the tutorial, you used

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:

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.

3 comments

  1. My display shows the same sda/b/c etc as you show, but in addition has ‘loop0’ numbered zero onwards to the number of ‘snap’ installations. Is there an explanation for this or is it a natural feature of ‘snap’ installations?
    (I use Linux Mint 19.2 on an old Lenovo G560 laptop)

    1. I don’t currently have snapd installed to check, but I’m guessing these are small filesystems contained in small standalone files, mounted as loop devices. It’s something similar to how you mount an ISO file and get to have sort of a virtual CD/DVD-ROM appear in your filesystem manager.

    2. Completion: Since snap apps come with their own libraries, I presume the app and its dependencies are contained in these small filesystems mounted as loop devices. This way, the app’s files never touch the system files, they are kept separate/isolated from each other.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.