Home > Article > System Tutorial > How to determine whether a Linux disk is a solid state drive or a mechanical hard drive
Three ways to determine whether a Linux disk is a solid state drive or a mechanical hard drive:
Determine the return value of cat /sys/block/*/queue/rotational (where * is the name of your hard disk device, such as sda, etc.). If it returns 1, it means that the disk can be rotated, then it is an HDD;
If it returns 0, it means the disk cannot be rotated, then it is an SSD.
[pythontab@pythontab.com ~]$ cat /sys/block/sda/queue/rotational 0 [pythontab@pythontab.com ~]$ grep ^ /sys/block/*/queue/rotational /sys/block/ram0/queue/rotational:1 /sys/block/sda/queue/rotational:0 /sys/block/sdb/queue/rotational:0 /sys/block/sdc/queue/rotational:0 /sys/block/sdd/queue/rotational:0
There is a problem with this method, that is, there are not only hard disks under /sys/block/, but also other block devices, which are all interfering with your judgment.
Use the lsblk command to judge. The parameter -d means to display the device name, and the parameter -o means to display only specific columns.
[pythontab@pyhontab.com ~]$ lsblk -d -o name,rota NAME ROTA sda 0 sdb 0 sdc 0 sdd 0
The advantage of this method is that it only lists the content you want to see, and the result is relatively concise and clear. Still the same rule, if ROTA is 1, it means it can be rotated, otherwise it cannot be rotated.
You can view it through the fdisk command. The parameter -l means to list the disk details. In the output results, the line starting with Disk represents the disk introduction. Below are some detailed parameters. We can try to find some HDD-specific keywords in these parameters, such as: "heads" (head), "track" (track) ) and "cylinders".
The following are the output results of HDD and SSD respectively
Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00074f7d [pythontab@pyhontab.com ~]$ sudo fdisk -l Disk /dev/nvme0n1: 238.5 GiB, 256060514304 bytes, 500118192 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xad91c214 ......
You can use third-party tools to judge, such as smartctl. The results of these tools are more intuitive, but they need to be installed separately.
The above is the detailed content of How to determine whether a Linux disk is a solid state drive or a mechanical hard drive. For more information, please follow other related articles on the PHP Chinese website!