How to Find if the System is Running on HDD or SSD in Linux

Brief: You will be introduced to some of the commands that will show you whether the system has an HDD or SSD. To directly jump to the command, click here.

I don’t know about you, but when I’m assisting others with their systems and discover that the performance isn’t up to my expectations, the first thing that comes to mind is to see if the system is using an HDD or SSD drive.

And when I ask them about it, they say we don’t know. Yes, I deal with some non-tech-savvy people, so their answer is valid, but I don’t want you to be like that, and for that reason, we have come up with an article where you will find how to check whether your system is equipped with an HDD or an SDD.

So let’s find out some of the common commands to check drive type in Linux, which will be very handy whenever you want to find out the information about the drive type.

List of commands to find drive type

As far as I know, there are no specific commands in Linux that will tell you whether the drive is an HDD or SSD, but you can use several commands like lsblk, hdparm, smartctl, and reading the disk information from /sys/block/sdX/queue/rotational to find the information with some tweaks.

Find disk type using the lsblk command

I chose the lsblk command as my first choice to find the drive type in Linux because it is a common command that almost every Linux user has used. You may be wondering how we can use the lsblk command to find the drive type.

As far as I know, it only displays drive information such as device name, mount location, major and minor, and type, but it’s not what you think.

Absolutely correct at your place, but you can tweak the default output of the lsblk command using the -o option to show information about the drive.

To tweak the default output of the lsblk command, we are going to use the -o option, which will print only the column that we will specify next to the “-o parameters.”

To make things easier for you, I have selected the columns “NAME,” “ROTA,” and “SIZE,” which will display the drive name, rotation (if the drive is an HDD, the value will be “1,” and if it’s an SSD, the value will be “0,”) and the size of the specific partition.

Let me now use the following command on my system to determine the drive type:

$ lsblk -o NAME,ROTA,SIZE 

The output of the above command

shen@trendoceans:~$ lsblk -o NAME,ROTA,SIZE
NAME    ROTA   SIZE
sda        0 465.8G
├─sda1     0   529M
├─sda2     0   100M
...................
...................
└─sda12    0  30.9G
sdb        1 931.5G
├─sdb1     1   499M
├─sdb2     1   100M
...................
...................
├─sdb8     1 416.9G

The command above prints “0” because, as you may know, HDDs have a rotational mechanism while SSDs do not. If the command learns that the drive has a rotational mechanism, it will simply enter the number “1” in the (ROTA) rotational column.

Find disk type by reading /sys/block/sdX/queue/rotational

The same information can be found by using the cat command to read the /sys/block/sdX/queue/rotational file, but first, make sure to update the drive name to match your system.

When you run the following command into your terminal, the output will be in the “0” and “1” order, which means that if the command print says “0”, the attached drive is an SSD, and if it says “1”, the attached drive is an HDD.

$ cat /sys/block/sdb/queue/rotational
or
$ cat /sys/block/sd*/queue/rotational

As I invoked the above command on my external HDD drive, which is /dev/sdb, I got the following output on my screen:

0

The same command can also be used to make a basic bash script that will tell you whether the hardware has an HDD or SDD drive.

if [ "$(cat /sys/block/sda/queue/rotational)" = 0 ]; then
    echo "Bruh! You do have an SSD on your system."
else
    echo "Bruh! You do have an HDD on your system."
fi

Find disk type by using hdparm command

The problem with the above command is that it will print “1” even if you have attached a thumb or USB drive to your system, which is not right because USB drives don’t have a rotation mechanism. Therefore, we cannot fully rely on the above command.

You can confirm the same thing using hdparm or smartctl commands such as the one listed below.

$ sudo hdparm -I /dev/sda | grep "Nominal Media Rotation Rate"

As you can see, the output shows “Solid State Device” when the above command found it to be an SSD drive, or it will print the rpm speed of the HDD drive.

Nominal Media Rotation Rate: Solid State Device

If your system is connected to an HDD drive, the output will look like this:

Nominal Media Rotation Rate: 5400

Find disk type by using smartctl command

Alternatively, you can use the SmartCTL utility tool to find information about the disk. This tool does more than just display information about the drive type, which we’ll cover someday.

Until then, learn how to get information about the type of drive by installing the “smartmontools” utility by executing the command below

$ sudo apt install smartmontools 

After installing “smartmontools” on your system, run the following command to display only rotation rate information while suppressing other extra information.

$ sudo smartctl -a /dev/sdb | grep "Rotation Rate"

The output of the above command clearly states that the drive is an HDD, and the rpm of the drive is 5400. You can also use the above command to find the RPM of the HDD drive in Linux.

Rotation Rate:    5400 rpm

Find disk type by using the model number

Most likely, the above-tweaked command will help you identify the type of drive, but if for some strange reason you are unable to do so, you can extract the drive’s model name and search online for information about it. There, you will undoubtedly find some helpful details about the relevant drives.

Use dmesg command to extract the model number

A dmesg command is a kernel ring buffer where everything gets logged, and from that, you can extract the model number of the drive by explicitly searching for the drive model number.

$ sudo dmesg | grep -i -e ata -e scsi

The output of the above command

[    1.944569] ata2: SATA max UDMA/133 abar m2048@0xb1334000 port 0xb1334180 irq 
[    2.260153] ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
................................................................................
................................................................................
[    2.262527] ata1.00: ATA-11: Samsung SSD 860 EVO 500GB, RVT04B6Q, max UDMA/133
[    2.263057] ata1.00: disabling queued TRIM support
................................................................................
................................................................................
[    2.268536] ata1.00: configured for UDMA/133
[    2.279105] scsi 0:0:0:0: Direct-Access     ATA      Samsung SSD 860  4B6Q PQ: 0 ANSI: 5

You may need to take the model name or number from the above message and search online for it in accordance with the output.

Use lsblk command to extract the model and serial

Additionally, you can find the model name and the serial number of the drive using the lsblk command, which is useful for discovering the attached drive’s warranty information.

Run the below command to print the model and serial number of the device along with the name, and rotation.

$ lsblk -o NAME,ROTA,SIZE,MODEL,SERIAL

The output of the above command:

NAME    ROTA   SIZE MODEL                     SERIAL
sda        0 465.8G Samsung SSD 860 EVO 500GB S4BNNE7W208398C
├─sda1     0   529M
├─sda2     0   100M
...................
...................
└─sda12    0  30.9G
sdb        1 931.5G TOSHIBA MQ04ABF100        Z9XQPR13Q
├─sdb1     1   499M
├─sdb2     1   100M
...................
...................
├─sdb8     1 416.9G

Cheat sheet for determining whether a drive is SSD or HDD

  • Find the SSD or HDD of the drive using lsblk
    • $ lsblk -o NAME,ROTA,SIZE
  • Find the SSD or HDD of the drive by reading cat /sys/block/sd*/queue/rotational
    • $ cat /sys/block/sd*/queue/rotational
  • Find the SSD or HDD of the drive using hdparm
    • $ sudo hdparm -I /dev/sda | grep "Nominal Media Rotation Rate"
  • Find the SSD or HDD of the drive using hdparm
    • $ sudo smartctl -a /dev/sdb | grep "Rotation Rate"
  • Find disk type by using the model and serial
    • $ sudo dmesg | grep -i -e ata -e scsi
    • $ lsblk -o NAME,ROTA,SIZE,MODEL,SERIAL

Wrap up

That’s all there is to say at this time. Here you have learned how to find the attached drive as an HDD or SSD in a Linux-based system. In this specific article, you have also learned where to look for the drive’s model and serial number.

Please let me know in the comments section if there is anything else you would like to add.

Leave a Reply