【Linux】Linux下判断磁盘是SSD还是HDD的几种方法

【Linux】Linux下判断磁盘是SSD还是HDD的几种方法,第1张

You should get 1 for hard disks and 0 for a SSD.

It will probably not work if your disk is a logical device emulated by hardware (like a RAID controller).

通过判断cat /sys/block/*/queue/rotational的返回值(其中*为你的硬盘设备名称,例如sda等等),如果返回1则表示磁盘旋转,那么就是HDD了;反之,如果返回0,则表示磁盘不可以旋转,那么就有可能是SSD了。

使用lsblk命令进行判断,参数-d表示显示设备名称,参数-o表示仅显示特定的列。

How to know if a disk is an SSD or an HDD

https://unix.stackexchange.com/questions/65595/how-to-know-if-a-disk-is-an-ssd-or-an-hdd

Linux下判断磁盘是SSD还是HDD的几种方法

https://blog.csdn.net/sch0120/article/details/77725658

Linux下如何查看硬盘是固态硬盘SSD还是机械硬盘HDD

https://blog.csdn.net/qq_40586364/article/details/103908967

Which linux filesystem works best with SSD

https://superuser.com/questions/228657/which-linux-filesystem-works-best-with-ssd

您好,方法一

判断cat /sys/block/*/queue/rotational的返回值(其中*为你的硬盘设备名称,例如sda等等),如果返回1 则表示磁盘可旋转,那么就是HDD了;

如果返回0,则表示磁盘不可以旋转,那么就是SSD了。

[pythontab@pythontab.com ~]$ cat /sys/block/sda/queue/rotational

[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

这种方法有个问题,那就是/sys/block/下面不只有硬盘,还可能有别的块设备,它们都在干扰你的判断。

方法二

使用lsblk命令进行判断,参数-d表示显示设备名称,参数-o表示仅显示特定的列。

[pythontab@pyhontab.com ~]$ lsblk -d -o name,rota

NAME ROTA

sda 0

sdb 0

sdc 0

sdd 0

这种方法的优势在于它只列出了你要看的内容,结果比较简洁明了。还是那个规则,ROTA是1的表示可以旋转,反之则不能旋转。

方法三

可以通过fdisk命令查看,参数-l表示列出磁盘详情。在输出结果中,以Disk开头的行表示磁盘简介,下面是一些详细参数,我们可以试着在这些参数中寻找一些HDD特有的关键字,比如:”heads”(磁头),”track”(磁道)和”cylinders”(柱面)。

下面分别是HDD和SSD的输出结果

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


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8958425.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-23
下一篇2023-04-23

发表评论

登录后才能评论

评论列表(0条)

    保存