有什么方法可以检测驱动器是否是SSD?
我正准备发布一个仅对普通硬盘有效的工具,对 SSD(固态硬盘)无效。事实上,它不应该与 SSD 一起使用,因为它会导致大量读/写,但没有真正的效果。
有人知道检测给定驱动器是否固态的方法吗?
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 result in a lot of read/writes with no real effectiveness.
Anyone knows of a way of detecting if a given drive is solid-state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
终于有了一个可靠的解决方案!实际上是两个!
检查 /sys/block/sdX/queue/rotational,其中 sdX 是驱动器名称。如果它是 0,则您正在处理 SSD,而 1 则表示普通旧 HDD。
我无法确定它是在哪个 Linux 版本中引入的,但它存在于 Ubuntu 的 Linux 3.2 和 vanilla Linux 3.6 中,但不存在于 vanilla 2.6.38 中。 Oracle 还将其向后移植到其 Unbreakable Enterprise 内核 5.5,这是基于 2.6.32 的。
自 Linux 3.3 起,还有一个 ioctl 用于检查驱动器是否可旋转,由 这个提交。不过,使用 sysfs 通常更方便。
Finally a reliable solution! Two of them, actually!
Check /sys/block/sdX/queue/rotational, where sdX is the drive name. If it's 0, you're dealing with an SSD, and 1 means plain old HDD.
I can't put my finger on the Linux version where it was introduced, but it's present in Ubuntu's Linux 3.2 and in vanilla Linux 3.6 and not present in vanilla 2.6.38. Oracle also backported it to their Unbreakable Enterprise kernel 5.5, which is based on 2.6.32.
There's also an ioctl to check if the drive is rotational since Linux 3.3, introduced by this commit. Using sysfs is usually more convenient, though.
实际上,您可以相当容易地确定旋转延迟——我在大学项目中做过一次。 本报告对此进行了描述。您需要跳到第 7 页,在那里您会看到一些漂亮的延迟图表。它从大约 9.3 毫秒减少到 1.1 毫秒,减少了 8.2 毫秒。这直接对应于
60 s / 8.2 ms = 7317 RPM
。它是用简单的 C 代码完成的——这是测量位置之间的部分临时文件中的
a
和b
。我们使用越来越大的b
值来做到这一点,直到我们一直绕着圆柱体徘徊:You can actually fairly easily determine the rotational latency -- I did this once as part of a university project. It is described in this report. You'll want to skip to page 7 where you see some nice graphs of the latency. It goes from about 9.3 ms to 1.1 ms -- a drop of 8.2 ms. That corresponds directly to
60 s / 8.2 ms = 7317 RPM
.It was done with simple C code -- here's the part that measures the between positions
a
andb
in a scratch file. We did this with larger and largerb
values until we have been wandered all the way around a cylinder:此命令
lsblk -d -o name,rota
列出您的驱动器,如果是旋转磁盘,则 ROTA 为 1;如果是 SSD,则 ROTA 为 0。输出示例:
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 :
检测 SSD 并不像 dseifert 所说的那么不可能。 Linux 的 libata 已经取得了一些进展(http://linux .derkeiler.com/Mailing-Lists/Kernel/2009-04/msg03625.html),虽然看起来并不用户已经准备好。
我绝对理解为什么需要这样做。这基本上是链表和数组之间的区别。对 SSD 进行碎片整理等通常会适得其反。
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.
从 Smartmontools运行可能会很幸运
。几乎所有的SSD在Model字段中都有SSD。但不能保证。
You could get lucky by running
from Smartmontools. Almost all SSDs has SSD in the Model field. No guarantee though.
我的两分钱回答这个古老但非常重要的问题...如果通过 SCSI 访问磁盘,那么您将(可能)能够使用 SCSI INQUIRY 命令来请求其旋转速率。 VPD(重要产品数据)页面称为
块设备特性
,编号为0xB1
。本页的字节 4 和 5 包含一个数字,其含义为:rpm) (例如,7 200 rpm = 1C20h、10 000 rpm = 2710h、15 000 rpm = 3A98h)"
因此,SSD 在此字段中必须有
0001h
。T10.org
关于此页面的文档可以找到此处但是,我不清楚该标准的实施情况 。 。
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 number0xB1
. Bytes 4 and 5 of this page contain a number with meaning:rpm) (e.g., 7 200 rpm = 1C20h, 10 000 rpm = 2710h, and 15 000 rpm = 3A98h)"
So, SSD must have
0001h
in this field. TheT10.org
document about this page can be found here.However, the implementation status of this standard is not clear to me.
我编写了以下 JavaScript 代码。我需要确定机器是否使用 SSD 驱动器以及是否是启动驱动器。该解决方案使用 MSFT_PhysicalDisk WMI 接口。
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.
SSD设备模拟硬盘设备接口,因此它们可以像硬盘一样使用。这也意味着没有通用的方法来检测它们是什么。
您可能可以使用驱动器的某些特征(延迟、速度、大小),尽管这并不适用于所有驱动器。另一种可能性可能是查看 SMART 数据,看看是否可以通过此确定磁盘类型(通过型号名称、某些值),但是除非您保留所有驱动器的数据库,否则这不会是 100%准确。
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.
写入文本文件
读取文本文件
重复 10000 次...
SSD 的
10000/elapsed
会高得多,python3:
write text file
read text file
repeat 10000 times...
10000/elapsed
for an ssd will be much higher, python3: