[ACCEPTED]-Is there any way of detecting if a drive is a SSD?-solid-state-drive

Accepted answer
Score: 40

Finally a reliable solution! Two of them, actually!

Check /sys/block/sdX/queue/rotational, where 11 sdX is the drive name. If it's 0, you're dealing 10 with an SSD, and 1 means plain old HDD.

I 9 can't put my finger on the Linux version 8 where it was introduced, but it's present 7 in Ubuntu's Linux 3.2 and in vanilla Linux 6 3.6 and not present in vanilla 2.6.38. Oracle 5 also backported it to their Unbreakable Enterprise 4 kernel 5.5, which is based on 2.6.32.

There's 3 also an ioctl to check if the drive is rotational 2 since Linux 3.3, introduced by this commit. Using sysfs 1 is usually more convenient, though.

Score: 9

You can actually fairly easily determine 11 the rotational latency -- I did this once 10 as part of a university project. It is described 9 in this report. You'll want to skip to page 7 where 8 you see some nice graphs of the latency. It 7 goes from about 9.3 ms to 1.1 ms -- a drop 6 of 8.2 ms. That corresponds directly to 5 60 s / 8.2 ms = 7317 RPM.

It was done with simple C code -- here's the part that measures 4 the between positions aand b in a scratch 3 file. We did this with larger and larger 2 b values until we have been wandered all 1 the way around a cylinder:

/* Measure the difference in access time between a and b.  The result
 * is measured in nanoseconds. */
int measure_latency(off_t a, off_t b) {
  cycles_t ta, tb;

  overflow_disk_buffer();

  lseek(work_file, a, SEEK_SET);
  read(work_file, buf, KiB/2);

  ta = get_cycles();
  lseek(work_file, b, SEEK_SET);
  read(work_file, buf, KiB/2);
  tb = get_cycles();

  int diff = (tb - ta)/cycles_per_ns;
  fprintf(stderr, "%i KiB to %i KiB: %i nsec\n", a / KiB, b / KiB, diff);
  return diff;
}
Score: 5

This command lsblk -d -o name,rota lists your drives and has 2 a 1 at ROTA if it's a rotational disk and 1 a 0 if it's an SSD. Example output :

NAME ROTA
sda     1
sdb     0
Score: 4

Detecting SSDs is not as impossible as dseifert 7 makes out. There is already some progress 6 in linux's libata (http://linux.derkeiler.com/Mailing-Lists/Kernel/2009-04/msg03625.html), though it doesn't 5 seem user-ready yet.

And I definitely understand 4 why this needs to be done. It's basically 3 the difference between a linked list and 2 an array. Defragmentation and such is usually 1 counter-productive on a SSD.

Score: 3

You could get lucky by running

smartctl -i sda

from Smartmontools. Almost 2 all SSDs has SSD in the Model field. No 1 guarantee though.

Score: 2

My two cents to answering this old but very 11 important question... If a disk is accessed 10 via SCSI, then you will (potentially) be 9 able to use SCSI INQUIRY command to request 8 its rotational rate. VPD (Vital Product 7 Data) page for that is called Block Device Characteristics and has a 6 number 0xB1. Bytes 4 and 5 of this page contain 5 a number with meaning:

  • 0000h "Medium rotation rate is not reported"
  • 0001h "Non-rotating medium (e.g., solid state)"
  • 0002h - 0400h "Reserved"
  • 0401h - FFFEh "Nominal medium rotation rate in rotations per minute (i.e., rpm) (e.g., 7 200 rpm = 1C20h, 10 000 rpm = 2710h, and 15 000 rpm = 3A98h)"
  • FFFFh "Reserved"

So, SSD must have 4 0001h in this field. The T10.org document about this 3 page can be found here.

However, the implementation 2 status of this standard is not clear to 1 me.

Score: 1

I wrote the following javascript code. I 3 needed to determine if machine was ussing 2 SSD drive and if it was boot drive. The 1 solution uses MSFT_PhysicalDisk WMI interface.

function main()
{
    var retval= false;
    // MediaType - 0 Unknown, 3 HDD, 4 SSD
    // SpindleSpeed - -1 has rotational speed, 0 has no rotational speed (SSD)
    // DeviceID - 0 boot device
    var objWMIService = GetObject("winmgmts:\\\\.\\root\\Microsoft\\Windows\\Storage");
    var colItems = objWMIService.ExecQuery("select * from MSFT_PhysicalDisk");  
    var enumItems = new Enumerator(colItems);
    for (; !enumItems.atEnd(); enumItems.moveNext()) 
    {
        var objItem = enumItems.item();
        if (objItem.MediaType == 4 && objItem.SpindleSpeed == 0)
        {
            if (objItem.DeviceID ==0)
            {
                retval=true;
            }
        }
    }
    if (retval)
    {
        WScript.Echo("You have SSD Drive and it is your boot drive.");
    }
    else
    {
        WScript.Echo("You do not have SSD Drive");
    }
    return retval;
}
main();
Score: 0

SSD devices emulate a hard disk device interface, so 11 they can just be used like hard disks. This 10 also means that there is no general way 9 to detect what they are.

You probably could 8 use some characteristics of the drive (latency, speed, size), though 7 this won't be accurate for all drives. Another 6 possibility may be to look at the S.M.A.R.T. data 5 and see whether you can determine the type 4 of disk through this (by model name, certain 3 values), however unless you keep a database 2 of all drives out there, this is not gonna 1 be 100% accurate either.

More Related questions