这是本节的多页打印视图。 点击此处打印.

返回本页常规视图.

hdparm命令

Linux hdparm 命令

1 - hdparm命令

hdparm 命令用于显示与设定硬盘的参数,还可以测试硬盘的读取速度

介绍

在Linux下可以使用hdparm工具查看硬盘的相关信息或对硬盘进行测速、优化、修改硬盘相关参数设定。

安装

一般 ubutu server 都自带 hdparm 命令,如果没有则通过下面的命令安装:

sudo apt install hdparm

更新,如果遇到 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 错误:

$ sudo hdparm -tT /dev/nvme0n1p1

/dev/nvme0n1p1:
 Timing cached reads:   20218 MB in  1.99 seconds = 10157.69 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 5302 MB in  3.00 seconds = 1767.28 MB/sec

则需要更新 hdparm 的版本,一般 apt 安装的版本是 v9.58:

$ hdparm -V
hdparm v9.58

最新版本下载地址: https://sourceforge.net/projects/hdparm/

目前最新的版本是 v9.65,下载完成后执行:

tar xvf hdparm-9.65.tar.gz
cd hdparm-9.65
make
sudo make install

查看新安装的版本:

$ hdparm -V
hdparm v9.65

这个时候就不会再出现 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 的报错了。

实践案例

查看硬盘的相关设置

sudo hdparm /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 multcount     =  0 (off)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 401023/255/63, sectors = 6442448863, start = 2048

其中 geometry 的参数解释为:

geometry = 401023[柱面数]/ 255[磁头数]/ 63[扇区数], sectors = 6442448863[总扇区数], start = 2048[起始扇区数]

测试硬盘的读取速度

sudo hdparm -t /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 Timing buffered disk reads: 9652 MB in  3.00 seconds = 3217.29 MB/sec

测试硬盘缓存的读取速度

sudo hdparm -T /dev/sdb1

输出为:

/dev/sdb1:
 Timing cached reads:   25838 MB in  1.99 seconds = 12959.95 MB/sec

检测硬盘的电源管理模式

sudo hdparm -C /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 drive state is:  standby

参考资料

2 - sandisk sn520的测试结果

sandisk sn520的测试结果

硬盘型号 sandisk sn520,容量 512G, m2 接口 nvme 协议, pcie 3.0 x4。

技嘉x99 + 10G M2

在技嘉 x99 ud4 主板上,m2 接口为 10G 带宽。

物理机安装 ubuntu 20.04 系统, 5.4 内核。

基本信息

$ lspci | grep disk
05:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 2018/PC SN520 NVMe SSD (rev 01)

磁盘数据:

Disk /dev/nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
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: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme0n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme0n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme0n1p3 839911424 976771071 136859648 65.3G Linux filesystem

分区信息:

sudo hdparm /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 66826/64/32, sectors = 136859648, start = 839911424

速度测试

读取速度测试:

sudo hdparm -t /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 2294 MB in  3.00 seconds = 764.43 MB/sec

缓存读取速度测试:

sudo hdparm -T /dev/nvme0n1p3


/dev/nvme0n1p3:
 Timing cached reads:   20412 MB in  1.99 seconds = 10261.23 MB/sec