Is there any way of detecting if a drive is a SSD?

前端 未结 9 2022
面向向阳花
面向向阳花 2020-11-30 03:02

I\'m getting ready to release a tool that is only effective with regular hard drives, not SSD (solid state drive). In fact, it shouldn\'t be used with SSD\'s because it will

相关标签:
9条回答
  • 2020-11-30 03:33

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

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

    0 讨论(0)
  • 2020-11-30 03:34

    I wrote the following javascript code. I needed to determine if machine was ussing SSD drive and if it was boot drive. The 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();
    
    0 讨论(0)
  • 2020-11-30 03:36

    My two cents to answering this old but very important question... If a disk is accessed via SCSI, then you will (potentially) be able to use SCSI INQUIRY command to request its rotational rate. VPD (Vital Product Data) page for that is called Block Device Characteristics and has a number 0xB1. Bytes 4 and 5 of this page contain 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 0001h in this field. The T10.org document about this page can be found here.

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

    0 讨论(0)
  • 2020-11-30 03:36

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

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

    0 讨论(0)
  • 2020-11-30 03:39

    You could get lucky by running

    smartctl -i sda
    

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

    0 讨论(0)
  • 2020-11-30 03:54

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

    NAME ROTA
    sda     1
    sdb     0
    
    0 讨论(0)
提交回复
热议问题