環境介紹
Fedora release 25 (Twenty Five)
判斷方法
方法一
判斷cat /sys/block/*/queue/rotational
的返回值(其中*
為你的硬盤設備名稱,例如sda
等等),如果返回1
則表示磁盤可旋轉,那么就是HDD了;反之,如果返回0
,則表示磁盤不可以旋轉,那么就有可能是SSD了。
[cheshi@cheshi-laptop2 ~]$ cat /sys/block/nvme0n1/queue/rotational
0 [cheshi@cheshi-laptop2 ~]$ grep ^ /sys/block/*/queue/rotational /sys/block/dm-0/queue/rotational:0 /sys/block/dm-1/queue/rotational:0 /sys/block/dm-2/queue/rotational:0 /sys/block/nvme0n1/queue/rotational:0 /sys/block/sda/queue/rotational:1 [cheshi@cheshi-laptop2 ~]$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
這種方法有個問題,那就是/sys/block/
下面不只有硬盤,還可能有別的塊設備,它們都在干擾你的判斷。
方法二
使用lsblk
命令進行判斷,參數-d
表示顯示設備名稱,參數-o
表示僅顯示特定的列。
[cheshi@cheshi-laptop2 ~]$ lsblk -d -o name,rota NAME ROTA nvme0n1 0 [cheshi@cheshi-laptop2 ~]$
- 1
- 2
- 3
- 4
這種方法的優勢在於它只列出了你要看的內容,結果比較簡潔明了。還是那個規則,ROTA
是1
的表示可以旋轉,反之則不能旋轉。
方法三
可以通過fdisk
命令查看,參數-l
表示列出磁盤詳情。在輸出結果中,以Disk
開頭的行表示磁盤簡介,下面是一些詳細參數,我們可以試着在這些參數中尋找一些HDD特有的關鍵字,比如:”heads”(磁頭),”track”(磁道)和”cylinders”(柱面)。
下面分別是HDD和SSD的輸出結果,HDD拷貝自網絡。
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
- 1
- 2
- 3
- 4
- 5
- 6
[cheshi@cheshi-laptop2 ~]$ 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 ...... [cheshi@cheshi-laptop2 ~]$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
其他方法
可以使用第三方工具判斷,比如smartctl
,這些工具的結果展示比較直觀,但是需要單獨安裝。
參考文獻
https://unix.stackexchange.com/questions/65595/how-to-know-if-a-disk-is-an-ssd-or-an-hdd