I want to know whether a disk is a solid-state drive or hard disk.

lshw is not installed. I do yum install lshw and it says there is no package named lshw. I do not know which version of http://pkgs.repoforge.org/lshw/ is suitable for my CentOS.

I search the net and there is nothing that explain how to know whether a drive is SSD or HDD. Should I just format them first?

Result of fdisk -l:

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00074f7d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          14      103424   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              14         536     4194304   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             536       14594   112921600   83  Linux

Disk /dev/sdc: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sdb: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sdd: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
  • 1
    If this really is a SSD you might want to reformat it to align the erase blocks with the partitions. – symcbean Feb 21 '13 at 13:58
  • SATA (Serial ATA) refers to the connection type of the drive, and does not imply that it is a Hard Disk Drive (HDD). SSDs can simultaneously be SATA, so I'm suggesting an edit to the title. – SpellingD Feb 21 '13 at 17:10
up vote 228 down vote accepted

Linux automatically detects SSD, and since kernel version 2.6.29, you may verify sda with:

cat /sys/block/sda/queue/rotational

You should get 1 for hard disks and 0 for a SSD.

It will probably not work if your disk is a logical device emulated by hardware (like a RAID controller).

See this answer for more information...

  • 2
    On Stackoverflow somebody found this sys-info didn't work. – PythoNic Jul 23 '14 at 10:55
  • @Totor I have got two disk, how can I find out which one is ssd? – user11498 Aug 5 '14 at 6:42
  • 2
    @user11498 replace sda by sdb and see which one is SSD... – Totor Aug 5 '14 at 14:04
  • 3
    @Totor You are correct in the "hybrid" drives. However, dual-drive hybrids show up as two individual drives, where SSHD (Solid-State Hybrid Drive) shows up as a single drive. So, the SSHD would show rotational of 1. – Terrance Jun 30 '16 at 16:18
  • 4
    On virtual servers, you may need to fetch /sys/block/vda/queue/rotational – MonoThreaded Nov 8 '16 at 21:45

With lsblk (part of the util-linux package):

lsblk -d -o name,rota
NAME ROTA
sda     0
sdb     0
sdc     1

where ROTA means rotational device (1 if true, 0 if false)

  • 1
    That utility seems to report the same information as in /sys/block/.../rotational. – dma_k Oct 20 '15 at 10:45
  • @dma_k Little wonder, considering it appears to use that one. Try it yourself: strace lsblk -d -o name,rota /dev/sda 2>&1 | grep --context=3 --color rotational – Michael Kjörling May 13 '16 at 16:30
  • 4
    Actually I was looking into various ways because some USB controllers don't tell that drive is actually non-rotational (for example, USB flash) and there is no way in Linux to tell the truth. At the end of the day I have fixed that by creating the explicit rule in /etc/udev/rules.d/90-non-rotational.rules: ACTION=="add|change", SUBSYSTEMS=="usb", ENV{ID_SERIAL}=="SanDisk_Ultra_Fit_*-0:0", ATTR{queue/rotational}="0", ATTR{queue/scheduler}="deadline" – dma_k Jun 8 '16 at 18:01
  • lsblk reports "0" for all my good old SATA spinning HDDs here (ASROCK mobo). « some USB controllers don't tell that drive is actually non-rotational (for example, USB flash) » @dma_k this is so true --and better this way than the other way for USB wired external spinning HDDs IMHA. – tuk0z Sep 14 '16 at 20:45

Use smartctl to retrieve vendor information,

sudo smartctl -a /dev/sdb

If you see a line like this,

Rotation Rate: Solid State Device

That would be a SSD drive.

  • 5
    smartctl command not found – Igor Ganapolsky Aug 7 '16 at 16:05
  • 5
    smartctl is part of the package smartmontools – trr Aug 16 '16 at 1:37

I needed to do this on the VPS and none of the provided solutions worked for me,

this answer did the trick

https://serverfault.com/questions/551453/how-do-i-verify-that-my-hosting-provider-gave-me-ssds/551495#551495

so, it is about reading random data from the drive and assessing the time.

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

here are my results for SSD

real    0m1.375s
user    0m0.285s
sys     0m0.944s

and HDD

real    0m14.249s
user    0m0.752s
sys     0m6.284s
  • I have a non-ssd, RAID10, and my results are: real 0m1.351s - user: 0m0.307s - sys: 0m0.560s – the_nuts Apr 10 '16 at 10:48
  • This is a good answer and it does work across the board. The thing is some HDDs are quite fast and the results can be similar to those of SSDs. Still, this answer provides a good metric. – itoctopus Jun 10 '16 at 4:57
  • 1
    On my VPS without an SSD this provides results like your SSD example. I believe this may be fooled by "hybrid" (SSD cached HDD) setups. – trr Aug 16 '16 at 1:40

The other answers already tell you how to get this information in a number of ways , including /proc. But you must expect all these mechanisms to lie if there's any virtualisation in the way, such as a hybrid SAN array with multiple tiers, or if the Linux machine is a virtual machine (where Linux will probably report the disk as a basic SCSI rotating disk, regardless of what the hardware really is)

  • this may be one of the more important responses... and also within the BIOS, or EFI/UEFI one may need to set the SATA controller mode to AHCI and then also mark each disk as SSD within the bios. My Asrock board on home pc is like this, can't remember if there was a similiar thing on server boards (supermicro) I have at work but i don't use SSD at work. – ron Aug 16 at 17:50

check cat /proc/scsi/scsi. there you should see the exact model of your disk. then you just google the model to find info about it.

  • 1
    dmesg will contain the same info. dmesg | grep -i -e scsi -e ata – Matt Feb 21 '13 at 9:41

This is an old post but I wanted to share another way to do this which I found out by accident:

sg_vpd --page=bdc /dev/sda

This commands fetches the Vital Product Data for the block device characteristics. For a rotating head disk, the output will include: Nominal rotation rate: 7200 rpm For an SSD, it will include: Non-rotating medium (e.g. solid state)

  • +1. nice, but running that on my (aging and soon to be replaced) WD Greens says Medium rotation rate is not reported. hdparm and smartmonctl say the same. I guess WD don't want to tell. – cas Aug 4 '16 at 13:41
lsblk -d -o name,rota | awk '{ if ($2 =="1") print $1 "[HDD]"; else if ($2 =="0") print $1 "[SDD]";}'

the lsblk command witch stand for list block has the ability to detect the disk type : an SSD or a classic Hard Drive , combined with the awk command it's just make the output humain readable and more easy to see on a terminal, rather than playing with 0 and 1 value.

  • 2
    Answers should be as self-contained as possible. This answer would be better if it included some explanation of what this code does, i.e., it provides the same information as in don_crissti's answer by making the output more readable. I wouldn't know what lsblk -d -o name,rota does without reading that answer. – Anthony Geoghegan Apr 27 at 11:38

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.