This tutorial explains Linux “hdparm” command, options and its usage with examples.
hdparm is a command line utility for the Linux to set and view ATA hard disk drive hardware parameters. It can set parameters such as drive caches, sleep mode, power management, acoustic management, and DMA settings. GParted and Parted Magic both include hdparm.
Changing hardware parameters from suboptimal conservative defaults to their optimal settings can improve performance greatly. For example, turning on DMA can, in some instances, double or triple data throughput. Unfortunately at present there is no reliable method for determining the optimal settings for a given controller/drive combination, except careful trial and error; nor is there yet any central database that collects and shares the combined experience of hdparm users.
hdparm has a more serious drawback: it can crash a computer and make data on its disk inaccessible if certain parameters are misused. Out of approximately sixty-seven parameters, several are dangerous and could result in “massive filesystem corruption” when used indiscriminately.
Usage :
hdparm [ flags ] [device] ..
OPTIONS
When no flags are given, -acdgkmnru is assumed.
-a
Get/set sector count for filesystem read-ahead.
-A
Disable/enable the IDE drive’s read-lookahead feature (usually ON by default).
-b
Get/set bus state.
-B
Set Advanced Power Management feature, if the drive supports it. A low value means aggressive power management and a high value means better performance. A value of 255 will disable apm on the drive.
-c
Query/enable (E)IDE 32-bit I/O support. A numeric parameter can be used to enable/disable 32-bit I/O support: Currently supported values include 0 to disable 32-bit I/O support, 1 to enable 32-bit data transfers, and 3 to enable 32-bit data transfers with a special sync sequence required by many chipsets. The value 3 works with nearly all 32-bit IDE chipsets, but incurs slightly more overhead. Note that “32-bit” refers to data transfers across a PCI or VLB bus to the interface card only; all (E)IDE drives still have only a 16-bit connection over the ribbon cable from the interface card.
-C
Check the current IDE power mode status, which will always be one of unknown (drive does not support this command), active/idle (normal operation), standby (low power mode, drive has spun down), or sleeping (lowest power mode, drive is completely shut down). The -S, -y, -Y, and -Z flags can be used to manipulate the IDE power modes.
-d
Disable/enable the “using_dma” flag for this drive.
-D
Enable/disable the on-drive defect management feature, whereby the drive firmware tries to automatically manage defective sectors by relocating them to “spare” sectors reserved by the factory for such.
-E
Set cdrom speed. This is NOT necessary for regular operation, as the drive will automatically switch speeds on its own. But if you want to play with it, just supply a speed number after the option, usually a number like 2 or 4.
-f
Sync and flush the buffer cache for the device on exit. This operation is also performed as part of the -t and -T timings.
-g
Display the drive geometry (cylinders, heads, sectors), the size (in sectors) of the device, and the starting offset (in sectors) of the device from the beginning of the drive.
-h
Display the usage information (help).
-i
Display the identification info that was obtained from the drive at boot time, if available.
-I
Request identification info directly from the drive, which is displayed in a new expanded format with considerably more detail than with the older -i flag.
-k
Get/set the keep_settings_over_reset flag for the drive. When this flag is set, the driver will preserve the -dmu options over a soft reset, (as done during the error recovery sequence). This flag defaults to off, to prevent drive reset loops which could be caused by combinations of -dmu settings.
-K
Set the drive’s keep_features_over_reset flag. Setting this enables the drive to retain the settings for -APSWXZ over a soft reset (as done during the error recovery sequence). Not all drives support this feature.
-m
Get/set sector count for multiple sector I/O on the drive. A setting of 0 disables this feature.
-M
Get/set Automatic Acoustic Management (AAM) setting. Most modern harddisk drives have the ability to speed down the head movements to reduce their noise output. The possible values are between 0 and 254. 128 is the most quiet (and therefore slowest) setting and 254 the fastest (and loudest). Some drives have ownly two levels (quiet / fast), while others may have different levels between 128 and 254. THIS FEATURE IS EXPERIMENTAL AND NOT WELL TESTED. USE AT YOUR OWN RISK.
-n
Get or set the “ignore write errors” flag in the driver. Do NOT play with this without grokking the driver source code first.
-r
Get/set read-only flag for device. When set, write operations are not permitted on the device.
-S
Set the standby (spindown) timeout for the drive. This value is used by the drive to determine how long to wait (with no disk activity) before turning off the spindle motor to save power. Under such circumstances, the drive may take as long as 30 seconds to respond to a subsequent disk access, though most drives are much quicker. The encoding of the timeout value is somewhat peculiar. A value of zero means “off”. Values from 1 to 240 specify multiples of 5 seconds, for timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, for timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes, 253 sets a vendor-defined timeout, and 255 is interpreted as 21 minutes plus 15 seconds.
-T
Perform timings of cache reads for benchmark and comparison purposes. For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active processes) with at least a couple of megabytes of free memory. This displays the speed of reading directly from the Linux buffer cache without disk access. This measurement is essentially an indication of the throughput of the processor, cache, and memory of the system under test. If the -t flag is also specified, then a correction factor based on the outcome of -T will be incorporated into the result reported for the -t operation.
-t
Perform timings of device reads for benchmark and comparison purposes. For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active processes) with at least a couple of megabytes of free memory. This displays the speed of reading through the buffer cache to the disk without any prior caching of data. This measurement is an indication of how fast the drive can sustain sequential data reads under Linux, without any filesystem overhead. To ensure accurate measurments, the buffer cache is flushed during the processing of -t. If the -T flag is also specified, then a correction factor based on the outcome of -T will be incorporated into the result reported for the -t operation.
-u
Get/set interrupt-unmask flag for the drive. A setting of 1 permits the driver to unmask other interrupts during processing of a disk interrupt, which greatly improves Linux’s responsiveness and eliminates “serial port overrun” errors. Use this feature with caution: some drive/controller combinations do not tolerate the increased I/O latencies possible when this feature is enabled, resulting in massive filesystem corruption.
-v
Display all settings, except -i (same as -acdgkmnru for IDE, -gr for SCSI or -adgr for XT). This is also the default behaviour when no flags are specified.
-w
Perform a device reset (DANGEROUS). Do NOT use this option. It exists for unlikely situations where a reboot might otherwise be required to get a confused drive back into a useable state.
-W
Disable/enable the IDE drive’s write-caching feature (default state is undeterminable; manufacturer/model specific).
-y
Force an IDE drive to immediately enter the low power consumption standby mode, usually causing it to spin down. The current power mode status can be checked using the -C flag.
-Y
Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shut down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver will automatically handle issuing a reset if/when needed). The current power mode status can be checked using the -C flag.
-z
Force a kernel re-read of the partition table of the specified device(s).
-Z
Disable the automatic power-saving function of certain Seagate drives (ST3xxx models?), to prevent them from idling/spinning-down at inconvenient times.
Examples :
1. To benchmark drive, run the following:
# hdparm -tT /dev/sda1 /dev/sda1: Timing cached reads: 2408 MB in 2.00 seconds = 1201.84 MB/sec Timing buffered disk reads: 260 MB in 3.03 seconds = 85.95 MB/sec
Note: Check, that no other program stresses the drive.
2. Display information of the hard drive:
# hdparm -I /dev/sda /dev/sda: 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 ATA device, with non-removable media Standards: Likely used: 1 Configuration: Logical max current cylinders 0 0 heads 0 0 sectors/track 510 0 -- Logical/Physical Sector size: 512 bytes device size with M = 1024*1024: 0 MBytes device size with M = 1000*1000: 0 MBytes cache/buffer size = unknown Capabilities: IORDY not likely Cannot perform double-word IO R/W multiple sector transfer: not supported DMA: not supported PIO: pio0
3. Enable read-ahead:
# hdparm -A 1 /dev/sda
4. If the disk is constantly too noisy, you can change its acoustic management at the cost of read/write performance:
# hdparm -M 128 /dev/sda
5. If the disk synchronisation intervals are too short, then even small amounts of data will be written to disk which can have severe consequences for its lifespan. The better way would be to collect small data onto bigger chunks and write until the chunk is big enough to be written to disk.
Current web browsers like Chrome write regularly small chunks when browsing in order not to lose any important data when the application crashes. However, this lets the disk spin very often as the drive repeatedly needs to unleash and then park its heads. The generated noises can be thus regarded as distracting by the user. To circumvent this issue, you can switch the drive to the lowest degree of power management (next value, 255, turns power management off):
# hdparm -B 254 /dev/sda
6. To get current settings:
# hdparm -d /dev/sdX
7. To set DMA on for a device:
# hdparm -d1 /dev/hda
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Check Linux Books
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship