List device names, drive information, and partitions in Linux with lsblk

lsblk displays information about storage devices. This utility is often used to determine the exact device name passed to the next command.

On Linux, sometimes you need to work with disks and / or partitions directly from the command line. Usually, you really want to take action on file systems, but ultimately do so by specifying the partitions where they are stored. On the command line, you do this by using their device names (e.g. ' / dev / sda3 ').

On systems with multiple drives, partitions, optical drives and USB drives, it may be difficult to determine the device name assigned to each drive.

How to use the lsblk command to list device names, drive information, and partitions in Linux

  1. What does the lsblk command do?
  2. Useful lsblk parameters
    1. Find out if it's an SSD or a hard drive (HDD)
    2. Displays the file system stored on a drive or partition
    3. Display mobile device or USB memory stick
    4. Display HDD / SSD model
    5. Display UUID (Universally Unique Identifier) ​​file system
  3. Show other lsblk columns you need

What does the lsblk command do?

lsblk displays information about storage devices. This utility is often used to determine the exact device name passed to the next command.

 lsblk 

List device names, drive information, and partitions in Linux with lsblk Picture 1List device names, drive information, and partitions in Linux with lsblk Picture 1

In most cases, just lsblk, without any additional parameters, is sufficient to help determine the drive or partition you want to work with. For example, from the picture above, you can say that sda4 is a Windows partition, because you know its capacity is about 200GB. However, if you have two or more partitions of the same size, things can become more confusing. In other cases, you simply don't know or don't remember the capacity of a specific drive or partition on your system.

On Linux, it is dangerous to confuse the device name, because you can destroy or damage useful data with a wrong command.

Useful lsblk parameters

By default, lsblk only displays a few properties, as you saw in the image above. But, if you add parameters to the command, you can make it output additional device properties. This makes it much easier to identify the drive or partition you are looking for.

Find out if it's an SSD or a hard drive (HDD)

To see which columns lsblk can display, enter the following:

 lsblk --help 

In this situation, you will use ROTA and DISC-GRAN.

  1. ROTA tells you whether a block device (the file represents a certain type of device, with data that can be read or written in the form of a block), usually has the ability to search forward / backward, and / or map. data) belongs to a rotary storage device. Hard disks can spin, so this column outputs a '1' next to them (binary logical value means 'true' ).
  2. DISC-GRAN shows you the level of detail of discard granularity. SSDs support removal to free up unused data blocks. Hard disks do not support this feature, because they do not need it, so this column displays the value 0 .
 lsblk -o +ROTA,DISC-GRAN 

List device names, drive information, and partitions in Linux with lsblk Picture 2List device names, drive information, and partitions in Linux with lsblk Picture 2

Displays the file system stored on a drive or partition

When you see a list of partitions, you can know what they store, based on their size. If this is not enough, you can also create lsblk output file systems. It is much easier to define partitions this way because:

  1. Windows uses the NTFS file system
  2. Linux usually uses ext4
  3. USB devices use FAT, FAT32 (vfat) or NTFS
  4. EFI boot partitions are usually very small and show a vfat file system on them

In addition, adding a LABEL output column , may help, if the partitions were labeled when creating or formatting.

 lsblk -o +FSTYPE,LABEL 

Display mobile device or USB memory stick

 lsblk -o +RM 

This command will display an additional column telling you whether the device is removable. The value '1', synonymous with 'true', refers to a USB or other type of removable media.

Display HDD / SSD model

This is useful when you want to look up the exact code of a storage device model to upgrade the firmware or download the driver.

 lsblk -d -o +MODEL 

Display UUID (Universally Unique Identifier) ​​file system

Older Linux distributions have mounted the file system by specifying their device name in '/ etc / fstab'. However, that proved to be unreliable because '/ dev / sda2' could become '/ dev / sdb2', when you add another storage device to the system. Currently, the UUID is used instead, unchanged whether you add or remove anything from your computer. For whatever reason you need a UUID, you can make lsblk display them with:

 lsblk -o +UUID 

Show other lsblk columns you need

At the beginning of the article, you used:

 lsblk --help 

This command is intended to see additional columns that lsblk may display. If the examples here aren't enough for your needs, refer to that help information again and combine the parameters as needed. To do so, simply enter lsblk -o + , followed by the name of the column you want to export. Separate column names with commas. For example:

 lsblk -o +SCHED,RM,FSTYPE 

After determining the name of the device you want to work with, remember to replace it with the full device path in the next command you plan to use. For example, if the result is 'sda4' in lsblk, you will have to replace it with '/ dev / sda4' in the next command. So instead of 'sda4', enter '/ dev / sda4' into a command such as:

 mkfs -t ext4 /dev/sda4 

Hope you are succesful.

4.2 ★ | 6 Vote