Home Command line utilities How To Find If The Disk Is SSD Or HDD In Linux
Find If The Disk Is SSD Or HDD In Linux

How To Find If The Disk Is SSD Or HDD In Linux

By sk
1147 Views

Picture this scenario. You are a newbie who have limited experience with Linux. You recently bought a new Laptop that has pre-installed with Linux, for example Ubuntu. You are not really sure whether the installed disk is SSD (Solid State Drive) or normal HDD (Hard Disk Drive). No problem! This brief guide will teach you how to find if the disk is SSD or HDD in Linux operating systems.

Find If The Disk Is SSD Or HDD In Linux

Starting from Kernel version 2.6.29, Linux operating systems can automatically detect SSD. There are a few ways to find to whether the disk is SSD or HDD. Here I have given 7 methods.

Method 1 - Check if the Disk is rotational

As you may already know, the traditional Hard Disk Drive (HDD) stores the data on a circular disc known as platter. When the disc spins, the moving read/write head will access the data. The faster the disk spins (rotates), the faster the hard disk works.

On the other hand, Solid State Drive (SDD) is modern storage technology and faster type of disk drive that stores the data on instantly-accessible flash memory chips. Unlike the traditional HDDs, the SSDs doesn't have any moving parts and SSDs don't rotate.

So, to find whether the installed disk is SSD or normal HDD, just check if the disk is rotational using the following command:

$ cat /sys/block/sda/queue/rotational

If the output is 1, the disk is HDD. If the output is 0 (zero), the disk is SDD. Because, SSDs won't rotate. So the output should be zero if you have SSD in your system.

Each drive has a directory in /sys/class/block/ location. So, you can check other drives details as well.

$ cat /sys/block/sdb/queue/rotational
$ cat /sys/block/sdc/queue/rotational

Note:

If you are on a KVM guest virtual machine, the drive letter would be vda. The result will vary depend on the bus type you chose during the virtual machine. For example if you choose SATA as bus type for the virtual disk, you will see the following output:

$ cat /sys/block/vda/queue/rotational 
1

Method 2 - Using lsblk command

The lsblk command reads the sysfs filesystem and udev db to gather information about all available or the specified block devices. The lsblk command is part of the util-linux package and comes pre-installed with most Linux distributions.

Just in case if lsblk command is not available, just install util-linux package using your distribution's package manager.

For example, on Arch-based systems, you can install it using command:

$ sudo pacman -S util-linux

On Debian-based systems:

$ sudo apt install util-linux

On RPM-based systems:

$ sudo yum install util-linux

On openSUSE:

$ sudo zypper install util-linux

Now, find if the disk is SSD or HDD using command:

$ lsblk -d -o name,rota

Sample output:

NAME   ROTA
loop0     1
loop1     1
loop2     1
loop3     1
loop4     1
loop5     1
loop6     1
loop7     1
loop8     1
loop9     1
loop10    1
loop11    1
loop12    1
loop13    1
loop14    1
loop15    1
loop16    1
loop17    1
loop18    1
loop19    1
loop20    1
sda       1
sr0       1

Here, "rota" means rotation device. If you get value of rota in the above output as 1, the disk is HDD. If the value is 0 (zero), then the disk is SSD.

Method 3 - Using SMART monitoring tools

The another way to find if the disk is SSD or HDD is using smartctl command. The smartctl is part of the S.M.A.R.T monitoring tools package, which is used to control and monitor S.M.A.R.T. enabled ATA and SCSI Hard Drives.

To install SMART monitoring tools on Arch Linux and its variants, run:

$ sudo pacman -S install smartmontools

On Debian, Ubuntu:

$ sudo apt install smartmontools

On RHEL, CentOS:

$ sudo yum install smartmontools

On openSUSE:

$ sudo zypper install smartmontools

After installing smartmontools package, run the following command to find if the disk is SSD or HDD:

$ sudo smartctl -a /dev/sda | grep 'Rotation Rate'

If the disk is SSD, you will get an output like below.

Rotation Rate:    Solid State Device

If the disk is HDD, you will get this output:

Rotation Rate: 5400 rpm

Method 4 - Using dmesg + Google

This is not a direct approach to find the disk type. In this method, we use dmesg command to find the disk model and then google the details to find if the disk is SSD or HDD.

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

You will see the disk model name among all other details.

[...]
[ 1.845159] scsi 0:0:0:0: Direct-Access ATA ST9500325AS DEM1 PQ: 0 ANSI: 5
[...]

Just google this model to find the disk details.

Method 5 - Using SCSI details + Google

This is same as the above method. We retrieve the disk model from /proc directory using command:

$ cat /proc/scsi/scsi

Sample output:

Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST9500325AS      Rev: DEM1
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: PLDS     Model: DVD+-RW DS-8A8SH Rev: KD11
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi6 Channel: 00 Id: 00 Lun: 00
  Vendor: Generic- Model: Multi-Card       Rev: 1.00
  Type:   Direct-Access                    ANSI  SCSI revision: 00

And then Google the details to know if the disk is SSD or HDD.

Method 6 - Using Sg3-utils

Sg3-utils is a collection of utilities for devices using the SCSI command set. Each utility in this package implements one SCSI command.

Sg3-utils is available in the default repositories of Debian and Ubuntu. To install it on your system, simply run:

$ sudo apt install sg3-utils

Now, check for Vital Product Data (VPD) for the block device characteristics by running the following command:

$ sudo sg_vpd --page=bdc /dev/sda

Sample output:

Block device characteristics VPD page (SBC):
Nominal rotation rate: 5400 rpm
Product type: Not specified
WABEREQ=0
WACEREQ=0
Nominal form factor not reported
ZONED=0
BOCS=0
FUAB=0
VBULS=0

Go through the output. If the output contains this line - "Nominal rotation rate: 5400 rpm", it is HDD. For SSD, you probably would see - "Non-rotating medium".

Method 7 - Benchmark Disk Access Performance

Find if the disk is SSD or HDD by reading random blocks from the disk using command:

time for i in `seq 1 1000`; do
    dd bs=4k if=/dev/sda count=1 skip=$(( $RANDOM * 128 )) >/dev/null 2>&1;
done

This command will read 1000 random 4k blocks from first 16GB of a disk.

If your disk is SSD, the operation should complete in about a second. If the disk is HDD, then it will take a few seconds to complete.

This will be helpful to check disks in your VPS. If you're using a VPS and wanted to check if the hosting provider gave you whether SSD or HDD, this is one way to find out!

What if there are multiple disks?

What If I have two disks, one is SSD and another is HDD? Both disks are same size and from the same manufacturer. I don't know on which disk my Linux is installed. In that case, simply find on which disk the root filesystem is located using the following command:

$ df / -h

Sample output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       458G  341G   95G  79% /

Alternatively, use lshw command to find more details about the disks:

$ sudo lshw -short -C disk

Sample output:

H/W path                 Device           Class          Description
====================================================================
/0/100/1d/1/1/6/0.0.0    /dev/sdb         disk           Multi-Card
/0/100/1d/1/1/6/0.0.0/0  /dev/sdb         disk           
/0/1/0.0.0               /dev/sda         disk           500GB ST9500325AS
/0/2/0.0.0               /dev/cdrom       disk           DVD+-RW DS-8A8SH

As you see in the above output, my root filesystem is installed in /dev/sda. Now follow any one of the above methods to find if the disk is HDD or SSD.

Note:

In some new Laptops like Lenovo ideapad s240, you will see a different device name, for example nvme0n1. Let us view the list of available block devices using command:

$ ls /sys/block

Sample output:

loop0   loop11  loop14  loop17  loop2   loop3  loop6  loop9
loop1   loop12  loop15  loop18  loop20  loop4  loop7  nvme0n1
loop10  loop13  loop16  loop19  loop21  loop5  loop8

Let us find out on which disk the root filesystem is located:

$ df / -h

Sample output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p6  96G   34G   58G   34%  /

As you see in the above outputs, there is no sda or sdb. Don't panic! This is normal. The /dev/nvme... device name indicates newer NVMe "disks."  If the disk is connected through an NVM Express port instead of a traditional SATA or SAS port, you will see a different device name as shown in the above output.

Here, /dev/nvme0n1 is equivalent to to /dev/sda. Hence, /dev/nvme0n1p6 is equivalent to /dev/sda6.


Suggested read:


Hope it was useful.

SSD icon Image by PagDev from Pixabay

Hdd icon Image by Clker-Free-Vector-Images from Pixabay

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

6 comments

Jalal April 15, 2020 - 11:21 pm

Hi,
It was very useful

Reply
sk April 16, 2020 - 12:28 am

Glad you found it useful. Stay tuned with us for more useful guides. Thank you.

Reply
drtffc April 17, 2020 - 9:02 pm

And what if…
lsblk -o name, rota
says:
sda 1

and
lsblk -D
says:

NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 4K 1G 0

It is an ssd but on a kvm guest…

Reply
sk April 17, 2020 - 9:13 pm

Both commands are different and provides different results. Where is the rotational output(rota) in the second command?

Reply
drtffc April 18, 2020 - 3:19 am

Dear sk, have you ever heard about trimmable hdd?
As far as I know it is an ssd feature.

Reply
sk April 18, 2020 - 10:32 am

Sorry, I didn’t know about Trim feature and I didn’t test this guide in KVM guest yet. I did a google search and found this.https://unix.stackexchange.com/questions/306229/how-do-i-check-trim Someone in this thread has mentioned – “DISC-MAX is not a reliable indicator. lsblk -D shows me non-zero (64M) for my SD card mmcblk0, which has not TRIM”. I don’t know yet if this statement is correct. I will do some testing on KVM guests.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More