hdparm

get/set SATA/IDE device parameters

sudo hdparm [options] [device]

Default -acdgkmur Display some settings:

  1. a sector count for filesystem (software) read-ahead.
  2. c 32 bit
  3. d using DMA
  4. g geometry
  5. k keep_settings_over_reset
  6. m count for multiple sector I/O
  7. u interrupt-unmask
  8. r read-only
For "Get/set" options: Directly get or set low level disk features read-lookahead...

Examples from raspberry pi Zero W with ??? SD card (many are invalid)

 sudo hdparm  /dev/mmcblk0

/dev/mmcblk0:
 HDIO_DRIVE_CMD(identify) failed: Invalid argument
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 973968/4/16, sectors = 62333952, start = 0
Not all commands are accepted by all drives

Commands listed as EXTREMELY DANGEROUS are omitted!
This document is tersified and you should read the man page for additional details.

ATA Security: DANGEROUS
-v Display basic settings, similar to -acdgkmur default when no options are specified.
-H Read the temperature
-i identification info the kernel drivers (IDE, libata) have stored from boot/configuration time.
-I identification info directly from the drive,
-g Display geometry (cylinders, heads, sectors), size (in sectors) and the starting offset (in sectors) from the beginning of the drive.
 geometry      = 973968/4/16, sectors = 62333952, start = 0 
-a [n Get/set sector count for filesystem read-ahead
sudo hdparm -a /dev/mmcblk0

/dev/mmcblk0:
 readahead     = 256 (on)
-A [0|1 Get/set the IDE drive's read-lookahead feature (usually ON ). 0:disable or 1:enable.
-b [ Get/set bus state.
 HDIO_GET_BUSSTATE failed: Invalid argument
-B [n Get/set Advanced Power Management feature,
A low value means aggressive power management and a high value means better performance. 1 .. 127 (permit spin-down), and 128.. 254 (do not permit spin-down).
The highest degree of power management with a setting of 1, and the highest I/O performance 254.
255 disables Advanced Power Management
-c [0|1 Get/set (E)IDE 32-bit I/O 0 disable ; 1 enable , and 3 enable transfers with a special sync sequence incurs slightly more overhead.
-C Check the IDE power mode status, returns: unknown (does not support this command), active/idle (normal operation), standby (low power mode, drive has spun down), or sleeping (lowest power mode, drive is shut down).
See -S, -y, -Y, and -Z
-d Get/set "using_dma" use with -X in combination with -d1 to ensure that the drive iis programmed for the correct DMA mode
--dco-freeze Device Configuration Overlay, freeze the configuration, until after the next power-on reset.
--dco-identify Query and dump show capabilities which might be disabled by the vendor for "enhanced compatibility".
When disabled, they are otherwise hidden and will not show in the -I identify output.
For example, system vendors sometimes disable 48_bit addressing on large drives, for compatibility (and loss of capacity) with a specific BIOS. show that the drive is 48_bit capable, but -I will not show it, and nor will the drive accept 48_bit commands.
-D Enable/disable the on-drive defect management feature, whereby the drive manages defective sectors by relocating them to "spare" sectors reserved by the factory
-E n Set CD/DVD speed.
-f Sync and flush the buffer cache on exit. performed as part of -t and -T timings and other options.
--fallocate sizeKB path Create path without actually writing any data. E.g. Create a 10KByte file: hdparm --fallocate 10 temp_file

only on ext4 and xfs filesystems. When used, this must be the only option given.

--fibmap path prints out a list of the block extents (sector ranges) occupied by that file on disk. Sector numbers are given as absolute LBA numbers, referenced from sector 0 of the physical device rather than from the partition or filesystem. This information can then be used for examining the degree of fragmenation of larger files, or determining appropriate sectors to deliberately corrupt during fault-injection testing procedures.

When used, this must be the only option given.

sudo hdparm --fibmap /var/log/04_warn.log

/var/log/04_warn.log:
 filesystem blocksize 4096, begins at LBA 31117312; assuming 512 byte sectors.
 byte_offset  begin_LBA    end_LBA    sectors
           0   33086200   33086207          8
        4096   39065384   39065391          8
-F Flush the on-drive write cache
--Istdin Accepts a drive identification block as standard input instead of using a /dev/hdn . The format of this block must be exactly the same as that found in /proc/ide/*/hd*/identify or that produced by --Istdout .
Use with collected "libraries" of drive identification information, and can also be used on ATAPI drives which may give media errors with the standard mechanism. When used, it must be the *only* parameter
--Istdout Dumps the drive's identify data in hex to stdout, in a format similar to that from /proc/ide/*/identify, and suitable for later use with --Istdin option.
-k [0|1 Get/set keep_settings_over_reset . When this flag is set, the drive preservs the -dmu settings over a soft reset, (as done during the error recovery sequence). defaults to off, Only set after establishing that correct system operation with a chosen set of configuration settings.
-K 0|1 Set keep_features_over_reset enables the drive to retain the settings for -APSWXZ over a soft reset (as done during the error recovery sequence).
-L 0|1 Set doorlock flag. 1 will lock the door mechanism of removable hard drives 0 will unlock it..
Useful on system shutdown, if the root partition is on a removable disk,
-m [0|2|4|8|16 Get/set sector count for multiple sector I/O . 0 disables
. Multiple sector mode (aka IDE Block Mode), permitting the transfer of multiple sectors per I/O interrupt,
-i displays the maximum setting supported (MaxMultSect ).
-M [0..254] Get/set Automatic Acoustic Management (AAM) . 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 only two levels (quiet / fast), while others may have different levels between 128 and 254. At the moment, most drives only support 3 options, off, quiet, and fast. These have been assigned the values 0, 128, and 254 at present, respectively, but integer space has been incorporated for future expansion, should this change.
-n Get or set the "ignore_write_errors" flag in the driver. Do NOT play with this without grokking the driver source code first.
-N Get/set max visible number of sectors, also known as the Host Protected Area setting. Without a parameter, -N displays the current setting, which is reported as two values: the first gives the current max sectors setting, and the second shows the native (real) hardware limit for the disk. The difference between these two values indicates how many sectors of the disk are currently hidden from the operating system, in the form of a Host Protected Area (HPA). This area is often used by computer makers to hold diagnostic software, and/or a copy of the originally provided operating system for recovery purposes. Another possible use is to hide the true capacity of a very large disk from a BIOS/system that cannot normally cope with drives of that size (eg. most current {2010} BIOSs cannot deal with drives larger than 2TB, so an HPA could be used to cause a 3TB drive to report itself as a 2TB drive). To change the current max (VERY DANGEROUS, DATA LOSS IS EXTREMELY LIKELY), a new value should be provided (in base10) immediately following the -N option. This value is spec- ified as a count of sectors, rather than the "max sector address" of the drive. Drives have the concept of a temporary (volatile) setting which is lost on the next hardware reset, as well as a more permanent (non-volatile) value which sur- vives resets and power cycles. By default, -N affects only the temporary (volatile) setting. To change the permanent (non-volatile) value, prepend a leading p character immediately before the first digit of the value. Drives are supposed to allow only a single permanent change per session. A hardware reset (or power cycle) is required before another perma- nent -N operation can succeed. Note that any attempt to set this value may fail if the disk is being accessed by other software at the same time. This is because setting the value requires a pair of back-to-back drive commands, but there is no way to prevent some other command from being inserted between them by the kernel. So if it fails initially, just try again. Kernel support for -N is buggy for many adapter types across many kernel versions, in that an incorrect (too small) max size value is sometimes reported. As of the 2.6.27 kernel, this does finally seem to be working on most hard- ware.
--prefer-ata12 When using the SAT (SCSI ATA Translation) protocol, prefer the 16-byte command format.
-q quiet suppressing normal output (but not error messages). useful when running from startup scripts. Not applicable to -i or -v or -t or -T
-Q [n Get/set command queue_depth
-r [0|1 Get/set read-only
 readonly      =  0 (off)
-R [0|1 Get/set Write-Read-Verify
-W [0|1 Get/set the IDE/SATA drive's write-caching
--read-sector sss.10 dumps the contents in hex to standard output.
--idle-immediate Issue ATA IDLE_IMMEDIATE , to put the drive into a lower power state. Usually the device remains spun-up.
--idle-unload Issue ATA IDLE_IMMEDIATE_WITH_UNLOAD , to unload or park the heads and put the drive into a lower power state. Usually the device remains spun-up.
-S n Put the drive into idle (low-power) mode, and set the standby timeout used to determine how long to wait (with no disk activity) before turning off the spindle motor
zero means "timeouts are disabled": the device will not automatically enter standby mode.
1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes.
241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours.
252 signifies a timeout of 21 minutes.
253 sets a vendordefined timeout period between 8 and 12 hours,
254 is reserved.
255 is interpreted as 21 minutes plus 15 seconds.
-t Perform timings of device reads for benchmark and comparison purposes.
Repeat 2-3 times on an inactive system.
Displays the speed of reading through the buffer cache to the disk without prior caching of data. an indication of how fast the drive can sustain sequential data reads , without filesystem overhead. buffer cache is flushed before testing.
sudo hdparm -t /dev/mmcblk0 
/dev/mmcblk0:
 Timing buffered disk reads:  68 MB in  3.09 seconds =  22.01 MB/sec
Regardless of running of influxdb & RuuviCollector!
--direct Use O_DIRECT when performing -t to bypass cache, causing the reads to go directly from the drive into hdparm's buffers, using "raw" I/O.
 Timing O_DIRECT disk reads:  66 MB in  3.08 seconds =  21.43 MB/sec
--offset Offsets to given number of GiB (1024*1024*1024) when performing -t timings.
-T Perform timings of cache reads for benchmark and comparison purposes.
Should be repeated 2-3 times on an inactive system memory. This displays the speed of reading directly from the system buffer cache without disk access. Measure of the throughput of the processor, cache, and memory.
 sudo hdparm -T /dev/mmcblk0 
/dev/mmcblk0:
 Timing cached reads:   548 MB in  2.00 seconds = 274.04 MB/sec
-X Set the IDE transfer mode for (E)IDE/ATA drives. This is typically used in combination with -d1 when enabling DMA to/from a drive on a supported interface chipset, where -X mdma2 is used to select multiword DMA mode2 transfers and -X sdma1 is used to select simple mode 1 DMA transfers. With systems which support UltraDMA burst timings, -X udma2 is used to select UltraDMA mode2 transfers (you'll need to prepare the chipset for UltraDMA beforehand). Apart from that, use of this option is seldom necessary since most/all modern IDE drives default to their fastest PIO transfer mode at power-on. Fid- dling with this can be both needless and risky. On drives which support alternate transfer modes, -X can be used to switch the mode of the drive only. Prior to changing the transfer mode, the IDE interface should be jumpered or pro- grammed (see -p option) for the new mode setting to prevent loss and/or corruption of data. Use this with extreme cau- tion! For the PIO (Programmed Input/Output) transfer modes used by Linux, this value is simply the desired PIO mode num- ber plus 8. Thus, a value of 09 sets PIO mode1, 10 enables PIO mode2, and 11 selects PIO mode3. Setting 00 restores the drive's "default" PIO mode, and 01 disables IORDY. For multiword DMA, the value used is the desired DMA mode number plus 32. for UltraDMA, the value is the desired UltraDMA mode number plus 64.
-y enter the low power standby mode, usually causing it to spin down. The current power mode status can be checked using the -C option.
-Y shut down . A reset is required before the drive can be accessed
-Z Disable the automatic power-saving
-z re-read the partition table
--security-help usage info for --security-*
--security-freeze Freeze security settings. until next power-on reset.
Use in combination with --security-unlock to protect drive from any attempt to set a new password.
No other options are permitted
--security-prompt-for-password Prompt for the --security PWD rather than getting from the command line args. avoids having passwords in shell history or /proc/self/cmdline
--security-unlock PWD ASCII, with the --user-master switch (default is "user" password).
No other options are permitted
--security-set-pass PWD Lock the drive, using password PWD (DANGEROUS) in ASCII
NULL sets an empty password. Selected with --user-master (default "user" ) and the applicable security mode --security- mode.
No other options are permitted
--security-disable PWD Disable drive locking, using password PWD. Password is given as an ASCII string and is padded with NULs to reach 32 bytes. The applicable drive password is selected with the --user-master switch (default is "user" password). No other options are permitted on the command line with this one.
--security-erase PWD Erase (locked) drive, REALLY! Use NULL to represent an empty password. with the --user-master switch (default is "user" password). No other options are permitted on the command line with this one.
--security-erase-enhanced PWD Enhanced erase (locked) drive, using password PWD (DANGEROUS). Password is given as an ASCII string and is padded with NULs to reach 32 bytes. The applicable drive password is selected with the --user-master switch (default is "user" pass- word). No other options are permitted on the command line with this one.
--user-master USER Specifies which password (user/master) to select. Defaults to user password. with --security- unlock, --security-set-pass, --security-disable, --security-erase or --security-erase-enhanced. u user password m master password
--security-mode MODE Specifies which security mode (high/maximum) to set. Defaults to high. with --security-set-pass. h high security m maximum security THIS FEATURE IS EXPERIMENTAL AND NOT WELL TESTED. USE AT YOUR OWN RISK.
--verbose Display extra diagnostics from some commands.
-V Display program version and exit

FILES

/etc/hdparm.conf Only Quiet is set 5/19/19 Raspberry pi stretch BUGS As noted above, the -m sectcount and -u 1 options should be used with caution at first, preferably on a read-only filesystem. Most drives work well with these features, but a few drive/controller combinations are not 100% compatible. Filesystem corrup- tion may result. Backup everything before experimenting! Some options (e.g. -r for SCSI) may not work with old kernels as necessary ioctl()'s were not supported. Although this utility is intended primarily for use with SATA/IDE hard disk devices, several of the options are also valid (and permitted) for use with SCSI hard disk devices and MFM/RLL hard disks with XT interfaces. The Linux kernel up until 2.6.12 (and probably later) doesn't handle the security unlock and disable commands gracefully and will segfault and in some cases even panic. The security commands however might indeed have been executed by the drive. This poor ker- nel behaviour makes the PIO data security commands rather useless at the moment. Note that the "security erase" and "security disable" commands have been implemented as two consecutive PIO data commands and will not succeed on a locked drive because the second command will not be issued after the segfault. See the code for hints how patch it to work around this problem. Despite the segfault it is often still possible to run two instances of hdparm consecu- tively and issue the two necessary commands that way. AUTHOR hdparm has been written by Mark Lord , the original primary developer and maintainer of the (E)IDE driver for Linux, and current contributor to the libata subsystem, along with suggestions and patches from many netfolk.

SEE

http://www.t13.org/ Technical Committee T13 AT Attachment (ATA/ATAPI) Interface. http://www.serialata.org/ Serial ATA International Organization. http://www.compactflash.org/ CompactFlash Association.