11

Is there a quick way to understand a type of the "storage" on Linux? Is it a HDD or SSD (or NVMe)? It's already known that the host is a physical machine and not a VM. The first thing I though about was rotational flag under /sys/block/<device>/queue/ directory. But in my experience even for SSD devices it may contain "1" value. The second way and more realistic and truthful was a latency. It's a bit harder to measure (some work with /proc/diskstats), but looks more preferable.

Is there any other ways? It's important to mention that I don't need to know exact model of the "storage", just its type.

lesovsky
  • 143
  • 7
  • 1
    Measuring latency is not a good answer as some rotational disks come with huge caches which may or may not be easy to distinguish from full capacity solid state devices. – anx Jan 21 '19 at 11:03
  • 2
    Along with `smartctl` mentioned here, other utilities such as `lshw` and `lsblk` report the same information. See also https://askubuntu.com/q/792814/295286 – Sergiy Kolodyazhnyy Jan 21 '19 at 15:47
  • 1
    what would you use this info for? In other words, if I give you program called isHDDorSSD what will you do with it – aaaaa says reinstate Monica Jan 21 '19 at 18:18
  • Bonnie++ can show SSD vs HDD based on IOPS (as can dd) – warren Jan 21 '19 at 18:19
  • @Sergiy Kolodyazhnyy, I've not found such info in `lshw`. Also `lsblk` relies on `rotational` flag in sysfs directory hence I can't trust it. `smartctl` uses ioctl call and asks inforamtion directly from device. – lesovsky Jan 21 '19 at 19:32

1 Answers1

13

How about something like sudo smartctl -a /dev/<device> | grep Rotation -- if this returns Rotation Rate: Solid State Device, then that's an SSD. Not sure if this bullet-proof method, either.

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
  • 1
    Looks good, it works even with drives attached through RAID cards. – lesovsky Jan 21 '19 at 06:56
  • @lesovsky, I wouldn't count on it working through a RAID card. I don't have any SSDs attached to RAID that I can test with, but it shows incorrect rotational rates for the spinning disks (every disk in the array shows up as 10k, when they're all actually 7.2k). – Mark Jan 22 '19 at 00:07