Linux "hdparm" Command Line Options and Examples
get/set SATA/IDE device parameters

hdparm provides a command line interface to various kernel interfaces supported by the Linux SATA/PATA/SAS "libata" subsystem and the older IDE driver subsystem. Many newer (2008 and later) USB drive enclosures now also support "SAT" (SCSI-ATA Command Translation) and therefore may also work with hdparm. E.


Usage:

hdparm [options] [device ...]




Command Line Options:

-A
Get/set the IDE drive´s read-lookahead feature (usually ON by default). Usage: -A0 (disable) or -A1 (enable).
hdparm -A ...
-b
Get/set bus state.
hdparm -b ...
--dco-freeze
DCO stands for Device Configuration Overlay, a way for vendors to selectively disable certain features of a drive. The --dco-freeze option will freeze/lock the current drive configuration, thereby preventing software (or malware) from changing any DCOsettings until after the next power-on reset.
hdparm --dco-freeze ...
--dco-identify
Query and dump information regarding drive configuration settings which can be disabled by the vendor or OEM installer. Thesesettings show capabilities of the drive 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_bitaddressing on large drives, for compatibility (and loss of capacity) with a specific BIOS. In such cases, --dco-identify willshow that the drive is 48_bit capable, but -I will not show it, and nor will the drive accept 48_bit commands.
hdparm --dco-identify ...
--dco-restore
Reset all drive settings, features, and accessible capacities back to factory defaults and full capabilities. This commandwill fail if DCO is frozen/locked, or if a -Np maximum size restriction has also been set. This is EXTREMELY DANGEROUS andwill very likely cause massive loss of data. DO NOT USE THIS COMMAND.
hdparm --dco-restore ...
--direct
Use the kernel´s "O_DIRECT" flag when performing a -t timing test. This bypasses the page cache, causing the reads to godirectly from the drive into hdparm's buffers, using so-called "raw" I/O. In many cases, this can produce results that appearmuch faster than the usual page cache method, giving a better indication of raw device and driver performance.
hdparm --direct ...
--drq-hsm-error
VERY DANGEROUS, DON'T EVEN THINK ABOUT USING IT. This option causes hdparm to issue an IDENTIFY command to the kernel, butincorrectly marked as a "non-data" command. This results in the drive being left with its DataReQust(DRQ) line "stuck" high.This confuses the kernel drivers, and may crash the system immediately with massive data loss. The option exists to help intesting and fortifying the kernel against similar real-world drive malfunctions. VERY DANGEROUS, DO NOT USE!!
hdparm --drq-hsm-error ...
--fallocate
This option currently works only on ext4 and xfs filesystem types. When used, this must be the only option given. Itrequires two parameters: the desired file size in kilo-bytes (byte count divided by 1024), followed by the pathname for thenew file. It will create a new file of the specified size, but without actually having to write any data to the file. Thiswill normally complete very quickly, and without thrashing the storage device.E.g. Create a 10KByte file: hdparm --fallocate 10 temp_file
hdparm --fallocate ...
--fibmap
When used, this must be the only option given. It requires a file path as a parameter, and will print out a list of the blockextents (sector ranges) occupied by that file on disk. Sector numbers are given as absolute LBA numbers, referenced from sec‐tor 0 of the physical device rather than from the partition or filesystem. This information can then be used for a variety ofpurposes, such as examining the degree of fragmenation of larger files, or determining appropriate sectors to deliberatelycorrupt during fault-injection testing procedures.This option uses the new FIEMAP (file extent map) ioctl() when available, and falls back to the older FIBMAP (file block map)ioctl() otherwise. Note that FIBMAP suffers from a 32-bit block-number interface, and thus not work beyond 8TB or 16TB.FIBMAP is also very slow, and does not deal well with preallocated uncommitted extents in ext4/xfs filesystems, unless async() is done before using this option.
hdparm --fibmap ...
--fwdownload
When used, this should be the only option given. It requires a file path immediately after the option, indicating where thenew drive firmware should be read from. The contents of this file will be sent to the drive using the (S)ATA DOWNLOADMICROCODE command, using either transfer protocol 7 (entire file at once), or, if the drive supports it, transfer protocol 3(segmented download). This command is EXTREMELY DANGEROUS and could destroy both the drive and all data on it. DO NOT USETHIS COMMAND. The --fwdownload-mode3 , --fwdownload-mode3-max , and --fwdownload-mode7 variations on basic --fwdownload allowoverriding automatic protocol detection in favour of forcing hdparm to use a specific transfer protocol, for testing purposesonly.
hdparm --fwdownload ...
-F
Flush the on-drive write cache buffer (older drives may not implement this).
hdparm -F ...
-h
Display terse usage information (help).
hdparm -h ...
--idle-immediate
Issue an ATA IDLE_IMMEDIATE command, to put the drive into a lower power state. Usually the device remains spun-up.
hdparm --idle-immediate ...
--idle-unload
Issue an ATA IDLE_IMMEDIATE_WITH_UNLOAD command, to unload or park the heads and put the drive into a lower power state. Usu‐ally the device remains spun-up.
hdparm --idle-unload ...
--Istdin
This is a special variation on the -I option, which accepts a drive identification block as standard input instead of using a/dev/hd* parameter. The format of this block must be exactly the same as that found in the /proc/ide/*/hd*/identify "files",or that produced by the --Istdout option described below. This variation is designed for use with collected "libraries" ofdrive identification information, and can also be used on ATAPI drives which may give media errors with the standard mecha‐nism. When --Istdin is used, it must be the *only* parameter given.
hdparm --Istdin ...
--Istdout
This option dumps the drive's identify data in hex to stdout, in a format similar to that from /proc/ide/*/identify, and suit‐able for later use with the --Istdin option.
hdparm --Istdout ...
--make-bad-sector
Deliberately create a bad sector (aka. "media error") on the disk. EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!! Thiscan be useful for testing of device/RAID error recovery mechanisms. The sector number is given as a (base10) parameter afterthe option. Depending on the device, hdparm will choose one of two possible ATA commands for corrupting the sector. TheWRITE_LONG works on most drives, but only up to the 28-bit sector boundary. Some very recent drives (2008) may support thenew WRITE_UNCORRECTABLE_EXT command, which works for any LBA48 sector. If available, hdparm will use that in preference toWRITE_LONG. The WRITE_UNCORRECTABLE_EXT command itself presents a choice of how the new bad sector should behave. Bydefault, it will look like any other bad sector, and the drive may take some time to retry and fail on subsequent READs of thesector. However, if a single letter f is prepended immediately in front of the first digit of the sector number parameter,then hdparm will issue a "flagged" WRITE_UNCORRECTABLE_EXT, which causes the drive to merely flag the sector as bad (ratherthan genuinely corrupt it), and subsequent READs of the sector will fail immediately (rather than after several retries).Note also that the --repair-sector option can be used to restore (any) bad sectors when they are no longer needed, includingsectors that were genuinely bad (the drive will likely remap those to a fresh area on the media).
hdparm --make-bad-sector ...
-n
Get or set the "ignore_write_errors" flag in the driver. Do NOT play with this without grokking the driver source code first.
hdparm -n ...
--offset
Offsets to given number of GiB (1024*1024*1024) when performing -t timings of device reads. Speed changes (about twice) alongmany mechanical drives. Usually the maximum is at the beginning, but not always. Solid-state drives (SSDs) should show simi‐lar timings regardless of offset.
hdparm --offset ...
--prefer-ata12
When using the SAT (SCSI ATA Translation) protocol, hdparm normally prefers to use the 16-byte command format whenever possi‐ble. But some USB drive enclosures don't work correctly with 16-byte commands. This option can be used to force use of thesmaller 12-byte command format with such drives. hdparm will still revert to 16-byte commands for things that cannot be donewith the 12-byte format (e.g. sector accesses beyond 28-bits).
hdparm --prefer-ata12 ...
-r
Get/set read-only flag for the device. When set, Linux disallows write operations on the device.
hdparm -r ...
--read-sector
Reads from the specified sector number, and dumps the contents in hex to standard output. The sector number must be given(base10) after this option. hdparm will issue a low-level read (completely bypassing the usual block layer read/write mecha‐nisms) for the specified sector. This can be used to definitively check whether a given sector is bad (media error) or not(doing so through the usual mechanisms can sometimes give false positives).
hdparm --read-sector ...
--repair-sector
This is an alias for the --write-sector option. VERY DANGEROUS.
hdparm --repair-sector ...
--trim-sector-ranges
For Solid State Drives (SSDs). EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!! Tells the drive firmware to discardunneeded data sectors, destroying any data that may have been present within them. This makes those sectors available forimmediate use by the firmware's garbage collection mechanism, to improve scheduling for wear-leveling of the flash media.This option expects one or more sector range pairs immediately after the option: an LBA starting address, a colon, and a sec‐tor count (max 65535), with no intervening spaces. EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!!E.g. hdparm --trim-sector-ranges 1000:4 7894:16 /dev/sdz
hdparm --trim-sector-ranges ...
--trim-sector-ranges-stdin
Identical to --trim-sector-ranges above, except the list of lba:count pairs is read from stdin rather than being specified onthe command line. This can be used to avoid problems with excessively long command lines. It also permits batching of manymore sector ranges into single commands to the drive, up to the currently configured transfer limit (max_sectors_kb).
hdparm --trim-sector-ranges-stdin ...
-v
Display some basic settings, similar to -acdgkmur for IDE. This is also the default behaviour when no options are specified.
hdparm -v ...
-V
Display program version and exit immediately.
hdparm -V ...
--verbose
Display extra diagnostics from some commands.
hdparm --verbose ...
--write-sector
Writes zeros to the specified sector number. VERY DANGEROUS. The sector number must be given (base10) after this option.hdparm will issue a low-level write (completely bypassing the usual block layer read/write mechanisms) to the specified sec‐tor. This can be used to force a drive to repair a bad sector (media error).
hdparm --write-sector ...
-W
Get/set the IDE/SATA drive´s write-caching feature.
hdparm -W ...
-z
Force a kernel re-read of the partition table of the specified device(s).
hdparm -z ...
--security-help
Display terse usage info for all of the --security-* options.
hdparm --security-help ...
--security-freeze
Freeze the drive´s security settings. The drive does not accept any security commands until next power-on reset. Use thisfunction in combination with --security-unlock to protect drive from any attempt to set a new password. Can be used stand‐alone, too. No other options are permitted on the command line with this one.
hdparm --security-freeze ...
--security-prompt-for-password
Prompt for the --security PWD rather than getting from the command line args. This avoids having passwords show up in shellhistory or in /proc/self/cmdline during execution.
hdparm --security-prompt-for-password ...
--security-unlock
Unlock the drive, using password PWD. Password is given as an ASCII string and is padded with NULs to reach 32 bytes. Theapplicable drive password is selected with the --user-master switch (default is "user" password). No other options are per‐mitted on the command line with this one.
hdparm --security-unlock ...
--security-set-pass
Lock the drive, using password PWD (Set Password) (DANGEROUS). Password is given as an ASCII string and is padded with NULsto reach 32 bytes. Use the special password NULL to set an empty password. The applicable drive password is selected withthe --user-master switch (default is "user" password) and the applicable security mode with the --security-mode switch. Noother options are permitted on the command line with this one.
hdparm --security-set-pass ...
--security-disable
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 arepermitted on the command line with this one.
hdparm --security-disable ...
--security-erase
Erase (locked) drive, using password PWD (DANGEROUS). Password is given as an ASCII string and is padded with NULs to reach32 bytes. Use the special password NULL to represent an empty password. The applicable drive password is selected with the
hdparm --security-erase ...
--user-master
switch (default is "user" password). No other options are permitted on the command line with this one.
hdparm --user-master ...
--security-erase-enhanced
Enhanced erase (locked) drive, using password PWD (DANGEROUS). Password is given as an ASCII string and is padded with NULsto reach 32 bytes. The applicable drive password is selected with the --user-master switch (default is "user" password). Noother options are permitted on the command line with this one.
hdparm --security-erase-enhanced ...
--security-mode
Specifies which security mode (high/maximum) to set. Defaults to high. Only useful in combination with --security-set-pass.h high securitym maximum securityTHIS FEATURE IS EXPERIMENTAL AND NOT WELL TESTED. USE AT YOUR OWN RISK.FILES/etc/hdparm.confBUGSAs noted above, the -m sectcount and -u 1 options should be used with caution at first, preferably on a read-only filesystem. Mostdrives work well with these features, but a few drive/controller combinations are not 100% compatible. Filesystem corruption mayresult. 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 per‐mitted) 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 willsegfault and in some cases even panic. The security commands however might indeed have been executed by the drive. This poor kernelbehaviour 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 willnot succeed on a locked drive because the second command will not be issued after the segfault. See the code for hints how patch itto work around this problem. Despite the segfault it is often still possible to run two instances of hdparm consecutively and issuethe two necessary commands that way.AUTHORhdparm has been written by Mark Lord <mlord@pobox.com>, 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.The disable Seagate auto-powersaving code is courtesy of Tomi Leppikangas(tomilepp@paju.oulu.fi).Security freeze command by Benjamin Benz, 2005.PIO data out security commands by Leonard den Ottolander, 2005. Some other parts by Benjamin Benz and others.
hdparm --security-mode ...