Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way of detecting if a drive is a 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?

like image 925
smartins Avatar asked May 25 '09 21:05

smartins


People also ask

How do I know if my hard drive is SSD or mechanical?

If you look at the “Media Type” section, you can see what type of hard drive you have. If you have an SSD, the tool will list it as “Solid state drive.” If you have a regular mechanical hard drive, it will list it as “Hard disk drive.”


1 Answers

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.

like image 105
Shnatsel Avatar answered Sep 28 '22 18:09

Shnatsel