zoukankan      html  css  js  c++  java
  • Linux下判断磁盘是SSD还是HDD的几种方法

    环境介绍

    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

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

    方法三

    可以通过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

  • 相关阅读:
    基于spark-streaming实时推荐系统
    xgb
    FM算法解析及Python实现
    FM算法
    计算广告
    转发推荐系统文章
    【spark】dataframe常见操作
    VS Code WSL 2 配置 Spring Boot 2
    Makefile
    Paper English
  • 原文地址:https://www.cnblogs.com/shihuvini/p/9558908.html
Copyright © 2011-2022 走看看