一天一個 Linux 命令(30):hdparm 命令


一、簡介

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM