本文为joshua317原创文章,转载请注明:转载自joshua317博客 一天一个 Linux 命令(30):hdparm 命令 - joshua317的博客
Linux下的hdparm(英文全称:hard disk parameters)命令,主要用来查看硬盘的相关信息或对硬盘进行测速、优化、修改硬盘相关参数设定。它提供了一个命令行的接口用于读取和设置IDE或SCSI硬盘参数。
若没有安装hdparm ,可以通过sudo yum install hdparm
来安装。
hdparm [options] ...[device]...
hdparm [参数]...[设备]...
Options:
-a Get/set fs readahead
-A Get/set the drive look-ahead flag (0/1)
-b Get/set bus state (0 == off, 1 == on, 2 == tristate)
-B Set Advanced Power Management setting (1-255)
-c Get/set IDE 32-bit IO setting
-C Check drive power mode status
-d Get/set using_dma flag
-D Enable/disable drive defect management
-E Set cd/dvd drive speed
-f Flush buffer cache for device on exit
-F Flush drive write cache
-g Display drive geometry
-h Display terse usage information
-H Read temperature from drive (Hitachi only)
-i Display drive identification
-I Detailed/current information directly from drive
-J Get/set Western DIgital "Idle3" timeout for a WDC "Green" drive (DANGEROUS)
-k Get/set keep_settings_over_reset flag (0/1)
-K Set drive keep_features_over_reset flag (0/1)
-L Set drive doorlock (0/1) (removable harddisks only)
-m Get/set multiple sector count
-M Get/set acoustic management (0-254, 128: quiet, 254: fast)
-n Get/set ignore-write-errors flag (0/1)
-N Get/set max visible number of sectors (HPA) (VERY DANGEROUS)
-p Set PIO mode on IDE interface chipset (0,1,2,3,4,...)
-P Set drive prefetch count
-q Change next setting quietly
-Q Get/set DMA queue_depth (if supported)
-r Get/set device readonly flag (DANGEROUS to set)
-R Get/set device write-read-verify flag
-s Set power-up in standby flag (0/1) (DANGEROUS)
-S Set standby (spindown) timeout
-t Perform device read timings
-T Perform cache read timings
-u Get/set unmaskirq flag (0/1)
-U Obsolete
-v Use defaults; same as -acdgkmur for IDE drives
-V Display program version and exit immediately
-w Perform device reset (DANGEROUS)
-W Get/set drive write-caching flag (0/1)
-x Obsolete
-X Set IDE xfer mode (DANGEROUS)
-y Put drive in standby mode
-Y Put drive to sleep
-z Re-read partition table
-Z Disable Seagate auto-powersaving mode
--dco-freeze Freeze/lock current device configuration until next power cycle
--dco-identify Read/dump device configuration identify data
--dco-restore Reset device configuration back to factory defaults
--direct Use O_DIRECT to bypass page cache for timings
--drq-hsm-error Crash system with a "stuck DRQ" error (VERY DANGEROUS)
--fallocate Create a file without writing data to disk
--fibmap Show device extents (and fragmentation) for a file
--fwdownload Download firmware file to drive (EXTREMELY DANGEROUS)
--fwdownload-mode3 Download firmware using min-size segments (EXTREMELY DANGEROUS)
--fwdownload-mode3-max Download firmware using max-size segments (EXTREMELY DANGEROUS)
--fwdownload-mode7 Download firmware using a single segment (EXTREMELY DANGEROUS)
--idle-immediate Idle drive immediately
--idle-unload Idle immediately and unload heads
--Istdin Read identify data from stdin as ASCII hex
--Istdout Write identify data to stdout as ASCII hex
--make-bad-sector Deliberately corrupt a sector directly on the media (VERY DANGEROUS)
--offset use with -t, to begin timings at given offset (in GiB) from start of drive
--prefer-ata12 Use 12-byte (instead of 16-byte) SAT commands when possible
--read-sector Read and dump (in hex) a sector directly from the media
--repair-sector Alias for the --write-sector option (VERY DANGEROUS)
--security-help Display help for ATA security commands
--trim-sector-ranges Tell SSD firmware to discard unneeded data sectors: lba:count ..
--trim-sector-ranges-stdin Same as above, but reads lba:count pairs from stdin
--verbose Display extra diagnostics from some commands
--write-sector Repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS)
-a<快取分区>:设定读取文件时,预先存入块区的分区数,若不加上<快取分区>选项,则显示目前的设定;
-A<0或1>:启动或关闭读取文件时的快取功能;
-c<I/O模式>:设定IDE32位I/O模式;
-C:检测IDE硬盘的电源管理模式;
-d<0或1>:设定磁盘的DMA模式;
-f:将内存缓冲区的数据写入硬盘,并清除缓冲区;
-g:显示硬盘的磁轨,磁头,磁区等参数;
-h:显示帮助;
-i:显示硬盘的硬件规格信息,这些信息是在开机时由硬盘本身所提供;
-I:直接读取硬盘所提供的硬件规格信息;
-k<0或1>:重设硬盘时,保留-dmu参数的设定;
-K<0或1>:重设硬盘时,保留-APSWXZ参数的设定;
-m<磁区数>:设定硬盘多重分区存取的分区数;
-n<0或1>:忽略硬盘写入时所发生的错误;
-p<PIO模式>:设定硬盘的PIO模式;
-P<磁区数>:设定硬盘内部快取的分区数;
-q:在执行后续的参数时,不在屏幕上显示任何信息;
-r<0或1>:设定硬盘的读写模式;
-S<时间>:设定硬盘进入省电模式前的等待时间;
-t;评估硬盘的读取效率;
-T:评估硬盘缓存的读取速度;
-u<0或1>:在硬盘存取时,允许其他中断要求同时执行;
-v:显示硬盘的相关设定;
-w<0或1>:设定硬盘的写入快取;
-X<传输模式>:设定硬盘的传输模式;
-y:使IDE硬盘进入省电模式;
-Y:使IDE硬盘进入睡眠模式;
-Z:关闭某些Seagate硬盘的自动省电功能。
用来查看硬盘的相关信息或对硬盘进行测速、优化、修改硬盘相关参数设定。
5.1 显示硬盘的相关设置
# hdparm /dev/vda
/dev/vda:
HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
readonly = 0 (off)
readahead = 8192 (on)
geometry = 104025/16/63, sectors = 104857600, start = 0
5.2 显示硬盘的柱面、磁头、扇区数
# hdparm -g /dev/vda
/dev/vda:
geometry = 104025/16/63, sectors = 104857600, start = 0
#其中:
geometry = 104025[柱面数]/16[磁头数]/63[扇区数], sectors = 104857600[总扇区数], start = 0[起始扇区数]
5.3 评估硬盘的读取效率
# hdparm -t /dev/vda
/dev/vda:
Timing buffered disk reads: 290 MB in 3.15 seconds = 92.08 MB/sec
5.4 评估硬盘缓存的读取速度
# hdparm -T /dev/vda
/dev/vda:
Timing cached reads: 20508 MB in 2.00 seconds = 10267.18 MB/sec
5.5 检测硬盘的电源管理模式
# hdparm -C /dev/vda
/dev/vda:
drive state is: unknown
5.6 查看并设置硬盘多重扇区存取的扇区数,以增进硬盘的存取效率
#查看
# hdparm -m /dev/vda
#设置
# hdparm -m 8 /dev/vda
5.7 读取硬盘所提供的硬件规格信息
#hdparm -I /dev/vda
5.8 将内存缓冲区的数据写入硬盘,并清空缓冲区
# hdparm -f /dev/vda
本文为joshua317原创文章,转载请注明:转载自joshua317博客 一天一个 Linux 命令(30):hdparm 命令 - joshua317的博客