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

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

May be interested

  • Restore deleted drive partitions with Active Partition RecoveryRestore deleted drive partitions with Active Partition Recovery
    recover data from partitions deleted by viruses, because missed hands often take a lot of time and effort. if you don't find the right tool you may lose data forever.
  • How to Format a Hard Drive on UbuntuHow to Format a Hard Drive on Ubuntu
    you can format the drive using the disks utility that comes pre-installed on ubuntu. if the disks utility reports an error or the partition is damaged, you can use gparted to format it. in addition, gparted can also resize existing partitions, allowing you to create additional partitions from an empty drive.
  • Manage Windows hard drive partitions without softwareManage Windows hard drive partitions without software
    3rd party software that helps you manage hard drive partitions for free or for a fee. disk partition management tool available in windows is not much you know
  • Beautiful wooden living room partitions help the house more spacious and luxuriousBeautiful wooden living room partitions help the house more spacious and luxurious
    partition is a convenient solution for families who want spacious space but still separate areas. wooden partitions are both beautiful and luxurious as the first choice of many homeowners to decorate the living room space of the family.
  • How to format a storage drive using Linux TerminalHow to format a storage drive using Linux Terminal
    storage devices are an integral part of computer hardware and computers in general. this tutorial will show you how to format a storage device right from the linux terminal.
  • How to Boot Linux from USB on Windows 10How to Boot Linux from USB on Windows 10
    whether you want to install linux on your pc from a flash drive (usb) or just boot into a portable version of linux, creating a linux bootable usb on windows 10 is very simple. tipsmake today will guide you on how to download the necessary software to create a linux usb, set up a boot drive, and proceed to boot your pc from a flash drive instead of a hard drive.
  • Advantages and disadvantages of hard drive partitioningAdvantages and disadvantages of hard drive partitioning
    you can easily create partitions to separate different types of data. here's what you need to know about partitions and the benefits and disadvantages of this.
  • How to find names in ExcelHow to find names in Excel
    how to find names in excel. you have a long list of hundreds and thousands of names, you are looking for ways to find names in excel to help save time when processing data. so invite you to learn how to find names in excel that tipsmake.com share below.
  • Partition to create the second hard drive on WindowsPartition to create the second hard drive on Windows
    if you want to split the hard drive into different parts, you can use partitions to do that. with disk management - a default windows tool, we will introduce you to all terms and instructions on how to resize, delete and create partitions. basically, this is a virtual process to add additional hard drives.
  • How to use the last command in LinuxHow to use the last command in Linux
    want to know who, what time and which device to access your linux computer? please read the following article.