HDPARM(8)

๐Ÿ“ฆ
version 9.65 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

๐Ÿ’– NAME ๐Ÿ’–

okay bestie, this is the HDPARM(8) page from the System Manager's Manual, and the command is hdparm โ€” get/set SATA/IDE device parameters. yes, the whole vibe is โ€œtalk to your drive and ask it questions, or tell it what to do.โ€

โœจ SYNOPSIS โœจ

hdparm [options] [device ...]

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

hdparm gives you 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), so they may also work with hdparm. E.g. recent WD โ€œPassportโ€ models and recent NexStar-3 enclosures. Some options may work correctly only with the latest kernels.

๐Ÿ’… OPTIONS ๐Ÿ’…

When no options are given, -acdgkmur is assumed. For โ€œGet/setโ€ options, a query without the optional parameter (e.g. -d) will query (get) the device state, and with a parameter (e.g., -d0) will set the device state.

  • -a โ€” get/set the sector count for filesystem (software) read-ahead. This is used to improve performance in sequential reads of large files by prefetching additional blocks in anticipation of them being needed by the running task. Many IDE drives also have a separate built-in read-ahead function, which augments this filesystem (software) read-ahead function.
  • -A โ€” get/set the IDE drive's read-lookahead feature (usually ON by default). Usage: -A0 (disable) or -A1 (enable).
  • -b โ€” get/set the bus state. short, sweet, bus state.
  • -B โ€” get/set the Advanced Power Management feature, if the drive supports it. A low value means aggressive power management and a high value means better performance. Possible settings range from values 1 through 127 (which permit spin-down), and values 128 through 254 (which do not permit spin-down). The highest degree of power management is attained with a setting of 1, and the highest I/O performance with a setting of 254. A value of 255 tells hdparm to disable Advanced Power Management altogether on the drive (not all drives support disabling it, but most do).
  • -c โ€” get/set (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 options can be used to manipulate the IDE power modes.
  • -d โ€” get/set the โ€œusing_dmaโ€ flag for this drive. This option now works with most combinations of drives and PCI interfaces which support DMA and which are known to the kernel IDE driver. It is also a good idea to use the appropriate -X option in combination with -d1 to ensure that the drive itself is programmed for the correct DMA mode, although most BIOSs should do this for you at boot time. Using DMA nearly always gives the best performance, with fast I/O throughput and low CPU usage. But there are at least a few configurations of chipsets and drives for which DMA does not make much of a difference, or may even slow things down (on really messed up hardware!). Your mileage may vary.
  • --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 DCO settings until after the next power-on reset.
  • --dco-identify โ€” query and dump information regarding drive configuration settings which can be disabled by the vendor or OEM installer. These settings 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_bit addressing on large drives, for compatibility (and loss of capacity) with a specific BIOS. In such cases, --dco-identify will show that the drive is 48_bit capable, but -I will not show it, and nor will the drive accept 48_bit commands.
  • --dco-restore โ€” reset all drive settings, features, and accessible capacities back to factory defaults and full capabilities. This command will fail if DCO is frozen/locked, or if a -Np maximum size restriction has also been set. This is EXTREMELY DANGEROUS and will very likely cause massive loss of data. DO NOT USE THIS COMMAND.
  • --direct โ€” use the kernel's โ€œO_DIRECTโ€ flag when performing a -t timing test. This bypasses the page cache, causing the reads to go directly from the drive into hdparm's buffers, using so-called โ€œrawโ€ I/O. In many cases, this can produce results that appear much faster than the usual page cache method, giving a better indication of raw device and driver performance.
  • --drq-hsm-error โ€” VERY DANGEROUS, DON'T EVEN THINK ABOUT USING IT. This option causes hdparm to issue an IDENTIFY command to the kernel, but incorrectly 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 in testing and fortifying the kernel against similar real-world drive malfunctions. VERY DANGEROUS, DO NOT USE!!
  • -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. Control of this feature via the -D option is not supported for most modern drives since ATA-4; thus this command may fail.
  • -E โ€” set cd/dvd drive 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. This can be useful in some cases, though, to smooth out DVD video playback.
  • -f โ€” sync and flush the buffer cache for the device on exit. This operation is also performed internally as part of the -t and -T timings and other options.
  • --fallocate โ€” this option currently works only on ext4 and xfs filesystem types. When used, this must be the only option given. It requires two parameters: the desired file size in kilo-bytes (byte count divided by 1024), followed by the pathname for the new file. It will create a new file of the specified size, but without actually having to write any data to the file. This will normally complete very quickly, and without thrashing the storage device.

E.g. Create a 10KByte file:

hdparm --fallocate 10 temp_file
  • --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 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 a variety of purposes, such as examining the degree of fragmenation of larger files, or determining appropriate sectors to deliberately corrupt 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 a sync() is done before using this option.

  • --fwdownload โ€” when used, this should be the only option given. It requires a file path immediately after the option, indicating where the new drive firmware should be read from. The contents of this file will be sent to the drive using the (S)ATA DOWNLOAD MICROCODE 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 USE THIS COMMAND. The --fwdownload-mode3, --fwdownload-mode3-max, and --fwdownload-mode7 variations on basic --fwdownload allow overriding automatic protocol detection in favour of forcing hdparm to use a specific transfer protocol, for testing purposes only.
  • -F โ€” flush the on-drive write cache buffer (older drives may not implement this).
  • -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 terse usage information (help). lil help moment.
  • -H โ€” read the temperature from some (mostly Hitachi) drives. Also reports if the temperature is within operating condition range (this may not be reliable). Does not cause the drive to spin up if idle.
  • -i โ€” display the identification info which the kernel drivers (IDE, libata) have stored from boot/configuration time. This may differ from the current information obtainable directly from the drive itself with the -I option. The data returned may or may not be current, depending on activity since booting the system. For a more detailed interpretation of the identification info, refer to AT Attachment Interface for Disk Drives, ANSI ASC X3T9.2 working draft, revision 4a, April 19/93, and later editions.
  • --idle-immediate โ€” sends an ATA IDLE_IMMEDIATE command so the drive dips into a lower power state. Heads up tho: usually the device stays spun-up, so don't expect it to nap-nap. ๐Ÿ’ค
  • --idle-unload โ€” fires off an ATA IDLE_IMMEDIATE_WITH_UNLOAD command: heads get unloaded/parked and the drive goes into a lower power state. Again, usually the device remains spun-up. It's giving "resting but not sleeping" energy โœจ
  • -I โ€” asks the drive for its identification info directly, and shows it in a brand-new expanded format with considerably more detail than the old -i option ever gave you. Glow-up, honestly. ๐Ÿ’…
  • --Iraw <pathname> โ€” dumps the drive's identify data in raw binary straight into the file you name. Raw. Binary. No formatting, no filter. ๐Ÿซถ
  • --Istdin โ€” the special sister variation of -I ๐Ÿงš: instead of pulling from a /dev/hd* parameter, it takes a drive identification block from standard input. The format of that block has to be exactly the same as what you'd find in the /proc/ide/*/hd*/identify "files", or what --Istdout spits out (described right below, iykyk). This one's designed for working with collected "libraries" of drive identification info, and it also works on ATAPI drives that might throw media errors with the standard mechanism. โš ๏ธ Big rule: when you use --Istdin, it must be the only parameter given. And note that some info will be incomplete โ€” the drive LOG PAGES just aren't available when --Istdin is in play. ๐Ÿ˜ญ
  • --Istdout โ€” dumps the drive's identify data in hex to stdout, formatted kinda like what /proc/ide/*/identify gives you, so you can feed it back later into --Istdin. Save it, reuse it, slay. ๐ŸŽ€
  • -J โ€” get/set the Western Digital (WD) Green Drive's "idle3" timeout value. This timeout controls how often the drive parks its heads and dips into low power consumption. The factory default is eight (8) seconds, which is genuinely a terrible choice for Linux โ€” leaving it there means hundreds of thousands of head load/unload cycles in a very short amount of time. The drive mechanism is only rated for 300,000 to 1,000,000 cycles, so leaving it at default could cause premature failure, plus the performance hit of the drive constantly having to wake up before doing routine I/O. ๐Ÿ’€

WD ships a WDIDLE3.EXE DOS utility for tweaking this, and bestie, you should use that program instead of hdparm if you possibly can. The reverse-engineered implementation in hdparm is not as complete as the original official program, even though it does seem to work on at least a few drives. And no matter which program you use to tweak things, a full power cycle is required for any change in setting to take effect. ๐Ÿ”Œ

A setting of 30 seconds is recommended for Linux use. Permitted values are from 8 to 12 seconds, and from 30 to 300 seconds in 30-second increments. Specify a value of zero (0) to disable the WD idle3 timer completely โ€” but that's (NOT RECOMMENDED!) ๐Ÿ™ˆ

  • -k โ€” get/set the "keep_settings_over_reset" flag for the drive. When it's set, the drive preserves the -dmu settings over a soft reset (the kind that happens during the error recovery sequence). This option defaults to off, and that's on purpose โ€” it prevents drive reset loops that combinations of -dmu settings could cause. So like, only set -k after you've built confidence that your chosen config actually works right. In practice, all you typically need to test a configuration (before using -k) is to verify the drive can be read/written and that no error logs (kernel messages) get generated in the process โ€” check /var/log/messages on most systems. โญ
  • -K โ€” sets the drive's "keep_features_over_reset" flag. Setting it lets the drive retain the settings for -APSWXZ over a soft reset (as done during the error recovery sequence). Heads up: not all drives support this feature, bestie. ๐Ÿคทโ€โ™€๏ธ
  • -L โ€” sets the drive's doorlock flag. Setting it to 1 locks the door mechanism on some removable hard drives (e.g. Syquest, ZIP, Jazz..), and setting it to 0 unlocks the door mechanism. Normally Linux maintains the door locking automatically based on drive usage (locked whenever a filesystem is mounted). But on system shutdown this can be a nuisance if your root partition lives on a removable disk, since the root partition is left mounted (read-only) after shutdown. So: use this command to unlock the door after the root filesystem is remounted read-only, and then you can pop the cartridge out after shutdown. ๐Ÿšชโœจ
  • -m โ€” get/set the sector count for multiple sector I/O on the drive. A setting of 0 disables the feature. Multiple sector mode (aka IDE Block Mode) is a feature of most modern IDE hard drives โ€” it lets multiple sectors transfer per I/O interrupt instead of the usual one sector per interrupt. When enabled, it typically cuts OS overhead for disk I/O by 30-50%, and on many systems it also boosts data throughput anywhere from 5% to 50%. Some drives, though (most notably the WD Caviar series), seem to run slower with multiple mode enabled. Your mileage may vary, fr fr. ๐ŸŒธ

Most drives support the minimum settings of 2, 4, 8, or 16 (sectors). Larger settings may also be possible depending on the drive; 16 or 32 seems optimal on many systems. Western Digital recommends lower settings of 4 to 8 on many of their drives, due to tiny (32kB) drive buffers and non-optimized buffering algorithms. The -i option can find the maximum setting an installed drive supports โ€” look for MaxMultSect in the output. Some drives claim to support multiple mode but lose data at some settings, and under rare circumstances those failures can result in massive filesystem corruption. ๐Ÿซ 

  • --make-bad-sector โ€” deliberately creates a bad sector (aka "media error") on the disk. EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!! ๐Ÿ’€๐Ÿ”ฅ For real for real. It can be useful for testing device/RAID error recovery mechanisms, which is the only reason it exists. The sector number is given as a (base10) parameter after the option.

Depending on the device, hdparm picks one of two possible ATA commands for corrupting the sector. WRITE_LONG works on most drives, but only up to the 28-bit sector boundary. Some very recent drives (2008) may support the new WRITE_UNCORRECTABLE_EXT command, which works for any LBA48 sector โ€” and if it's available, hdparm will use it in preference to WRITE_LONG.

WRITE_UNCORRECTABLE_EXT itself presents a choice of how the new bad sector should behave. By default it looks like any other bad sector, and the drive may take some time to retry and fail on subsequent READs of that sector. But if a single letter f is prepended immediately in front of the first digit of the sector number parameter, hdparm issues a "flagged" WRITE_UNCORRECTABLE_EXT โ€” the drive merely flags the sector as bad (rather than genuinely corrupting it), and subsequent READs of the sector fail immediately rather than after several retries. โšก Also note: the --repair-sector option can restore (any) bad sectors when they're no longer needed, including sectors that were genuinely bad โ€” the drive will likely remap those to a fresh area on the media. ๐Ÿฉน

  • -M โ€” get/set the Automatic Acoustic Management (AAM) setting. Most modern harddisk drives can speed down head movements to reduce their noise output. Possible values are between 0 and 254. 128 is the most quiet (and therefore slowest) setting, and 254 is 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 โ€” and those 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. Like, actually read it. ๐Ÿง โš ๏ธ
  • -N โ€” get/set the max visible number of sectors, aka the Host Protected Area setting ๐Ÿ’…

With no parameter, -N shows you the current setting, and it reports two values: the first is the current max sectors setting, the second is the native (real) hardware limit for the disk. The gap between those two numbers tells you how many sectors of the disk are currently hidden from the operating system as a Host Protected Area (HPA). Computer makers love using this area to stash diagnostic software and/or a copy of the originally provided operating system for recovery purposes. Another possible use: hiding the true capacity of a very large disk from a BIOS/system that can't normally cope with drives 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). Sneaky โœจ

To change the current max โ€” VERY DANGEROUS, DATA LOSS IS EXTREMELY LIKELY ๐Ÿ˜ญ โ€” hand over a new value in base10 immediately after the -N option. That value is a count of sectors, not the "max sector address" of the drive. Drives have this whole concept of a temporary (volatile) setting that gets lost on the next hardware reset, plus a more permanent (non-volatile) value that survives resets and power cycles. By default -N only touches the temporary (volatile) setting. Wanna 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, so a hardware reset (or power cycle) is required before another permanent -N operation can succeed.

Heads up: any attempt to set this value may fail if the disk is being accessed by other software at the same time. Why? Because setting the value requires a pair of back-to-back drive commands, and there's no way to stop the kernel from inserting some other command between them ๐Ÿ™ˆ So if it fails initially, just try again. Also, 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 hardware ๐Ÿซถ

  • --offset โ€” offsets to the given number of GiB (1024*1024*1024) when doing -t timings of device reads. Speed changes (about twice) along many mechanical drives โ€” usually the max is at the beginning, but not always. Solid-state drives (SSDs) should show similar timings regardless of offset ๐ŸŒ€
  • -p โ€” attempt to reprogram the IDE interface chipset for the specified PIO mode, or attempt to auto-tune for the "best" PIO mode supported by the drive. This feature is supported in the kernel for only a few "known" chipsets, and even then the support is iffy at best ๐Ÿ’€ Some IDE chipsets can't alter the PIO mode for a single drive, in which case this option may cause the PIO mode for both drives to be set. Many IDE chipsets support either fewer or more than the standard six (0 to 5) PIO modes, so the exact speed setting that's actually implemented will vary by chipset/driver sophistication.
Use with extreme caution! This feature includes zero protection for the unwary, and an unsuccessful outcome may result in severe filesystem corruption! ๐Ÿ˜ฑ
  • -P โ€” set the maximum sector count for the drive's internal prefetch mechanism. Not all drives support this feature, and it was dropped from the official spec as of ATA-4.
  • --prefer-ata12 โ€” when using the SAT (SCSI ATA Translation) protocol, hdparm normally prefers the 16-byte command format whenever possible. But some USB drive enclosures just don't work correctly with 16-byte commands ๐Ÿ˜ค This option forces use of the smaller 12-byte command format with such drives. hdparm will still revert to 16-byte commands for things that can't be done with the 12-byte format (e.g. sector accesses beyond 28-bits).
  • -q โ€” handle the next option quietly, suppressing normal output (but not error messages). Useful for reducing screen clutter when running from system startup scripts. Not applicable to the -i or -v or -t or -T options ๐Ÿคซ
  • -Q โ€” get or set the device's command queue_depth, if supported by the hardware. Only works with 2.6.xx (or later) kernels, and only with device and driver combinations that support changing the queue_depth. For SATA disks, this is the Native Command Queuing (NCQ) queue depth ๐Ÿ‘‘
  • -r โ€” get/set the read-only flag for the device. When set, Linux disallows write operations on the device ๐Ÿ”’
  • -R โ€” get/set the Write-Read-Verify feature, if the drive supports it. Usage: -R0 (disable) or -R1 (enable). This feature is meant to have the drive firmware automatically read back any data that's written by software, to verify the data was successfully written. It's generally overkill, and can slow down disk writes by as much as a factor of two (or more) ๐ŸŒ
  • --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 mechanisms) 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 ๐Ÿ”
  • --repair-sector โ€” this is an alias for the --write-sector option. VERY DANGEROUS ๐Ÿ’€
  • -s โ€” enable/disable the power-on in standby feature, if supported by the drive. VERY DANGEROUS. Do not use unless you're absolutely certain that both the system BIOS (or firmware) and the operating system kernel (Linux >= 2.6.22) support probing for drives that use this feature. When enabled, the drive is powered up in standby mode so the controller can sequence the spin-up of devices, reducing the instantaneous current draw burden when many drives share a power supply. Primarily for use in large RAID setups. This feature is usually disabled and the drive is powered up in active mode (see -C above). Note that a drive may also allow enabling this feature by a jumper. Some SATA drives support controlling this feature by pin 11 of the SATA power connector โ€” in those cases, this command may be unsupported or may have no effect โšก
  • -S โ€” put the drive into idle (low-power) mode, and also set the standby (spindown) timeout for the drive. The drive uses that timeout value to decide how long to wait (with no disk activity) before killing 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... a little peculiar, ngl. Here's the tea:

  • A value of 0 means "timeouts are disabled": the device will not automatically enter standby mode.
  • Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes.
  • Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours.
  • A value of 252 signifies a timeout of 21 minutes.
  • A value of 253 sets a vendor-defined timeout period between 8 and 12 hours, and the value 254 is reserved.
  • 255 is interpreted as 21 minutes plus 15 seconds.

Note that some older drives may have very different interpretations of these values ๐ŸŽ€

  • --set-sector-size โ€” for drives that support reconfiguring the Logical Sector Size, this flag lets you specify the new desired sector size in bytes. VERY DANGEROUS. This most likely will scramble all data on the drive ๐Ÿ˜ญ The specified size must be one of 512, 520, 528, 4096, 4160, or 4224. Very few drives support values other than 512 and 4096.

Eg.

hdparm --set-sector-size 4096 /dev/sdb
  • -t โ€” perform timings of device reads for benchmark and comparison purposes. For meaningful results, repeat this operation 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. It's an indication of how fast the drive can sustain sequential data reads under Linux, without any filesystem overhead. To ensure accurate measurements, the buffer cache is flushed during the processing of -t using the BLKFLSBUF ioctl โฑ๏ธ
  • -T โ€” perform timings of cache reads for benchmark and comparison purposes. For meaningful results, repeat this operation 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. It's essentially an indication of the throughput of the processor, cache, and memory of the system under test ๐Ÿ”ฅ
  • --trim-sector-ranges โ€” for Solid State Drives (SSDs). EXCEPTIONALLY DANGEROUS. DO NOT USE THIS OPTION!! ๐Ÿ’€๐Ÿ’€ It tells the drive firmware to discard unneeded data sectors, destroying any data that may have been present within them. This makes those sectors available for immediate 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 sector 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
  • --trim-sector-ranges-stdin โ€” literally the same vibe as --trim-sector-ranges, except the lba:count pairs come in from stdin instead of the command line ๐Ÿ’Œ. Why? Because command lines get stupid long and this dodges that whole mess, bestie. Bonus: it lets you batch way more sector ranges into a single command to the drive, up to the transfer limit that's currently configured (max_sectors_kb). Slay. โœจ
  • -u โ€” get/set the interrupt-unmask flag for the drive. Set it to 1 and the driver gets to unmask other interrupts while it's busy handling a disk interrupt, which highkey does wonders for Linux's responsiveness and kills those "serial port overrun" errors. ๐Ÿฆ‹ But use this one with caution, fr fr: some drive/controller combos absolutely do not tolerate the increased I/O latencies that come with it, and the result is massive filesystem corruption ๐Ÿ˜ญ. Specifically, CMD-640B and RZ1000 (E)IDE interfaces can be unreliable (hardware flaw, not their fault bestie) when you use this option with kernel versions earlier than 2.0.13. The safe fix for those old kernels: disable the IDE prefetch feature on those interfaces (usually a BIOS/CMOS setting).
  • -v โ€” shows you some basic settings, kind of like -acdgkmur for IDE. Also the default behavior when you give it no options at all. Iconic default, honestly. ๐Ÿ‘‘
  • -V โ€” display the program version and dip immediately. ๐ŸŽ€
  • --verbose โ€” spills extra diagnostics from some commands. Not me wanting all the tea โ˜•.
  • -w โ€” perform a device reset (DANGEROUS). Do NOT use this option. ๐Ÿ’€ It exists for those unlikely situations where you'd otherwise have to reboot just to get a confused drive back into a useable state.
  • --write-sector โ€” writes zeros to the sector number you specify. VERY DANGEROUS. ๐Ÿ™ˆ The sector number must be given (base10) after this option. hdparm issues a low-level write โ€” completely bypassing the usual block layer read/write mechanisms, no cap โ€” to that sector. Handy for forcing a drive to repair a bad sector (media error). ๐Ÿซถ
  • -W โ€” get/set the IDE/SATA drive's write-caching feature. ๐ŸŒธ
  • -X โ€” set the IDE transfer mode for (E)IDE/ATA drives. Typically you pair this with -d1 when you're enabling DMA to/from a drive on a supported interface chipset: -X mdma2 selects multiword DMA mode2 transfers, and -X sdma1 selects simple mode 1 DMA transfers โœจ. On systems that support UltraDMA burst timings, -X udma2 selects UltraDMA mode2 transfers (you'll need to prep the chipset for UltraDMA beforehand, bestie). Other than that, you'll seldom need this option, since most/all modern IDE drives just default to their fastest PIO transfer mode at power-on. Fiddling with it can be both needless and risky. ๐Ÿ˜ฌ On drives that support alternate transfer modes, -X can switch the mode of the drive only. Before you change the transfer mode, the IDE interface should be jumpered or programmed (see the -p option) for the new mode setting, otherwise: loss and/or corruption of data. Use this with extreme caution! ๐Ÿ”ฅ

For the PIO (Programmed Input/Output) transfer modes Linux uses, the value is just the desired PIO mode number plus 8. So: 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 is the desired DMA mode number plus 32. For UltraDMA, the value is the desired UltraDMA mode number plus 64. Math but make it disk ๐Ÿ’….

  • -y โ€” force an IDE drive to immediately enter the low power consumption standby mode, which usually makes it spin down. You can check the current power mode status with -C. ๐Ÿ˜ด
  • -Y โ€” force an IDE drive to immediately enter the lowest power consumption sleep mode, shutting it down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver handles issuing a reset automatically if/when it's needed, don't worry). Current power mode status check? -C, same as above. ๐Ÿ’ค
  • -z โ€” force a kernel re-read of the partition table of the specified device(s). ๐Ÿ”„
  • -Z โ€” disable the automatic power-saving function on certain Seagate drives (ST3xxx models?), so they stop idling/spinning-down at the most inconvenient times possible. ๐Ÿ™„

๐Ÿ” ATA Security Feature Set ๐Ÿ”

These switches are DANGEROUS to experiment with, and might not work with some kernels. USE AT YOUR OWN RISK. ๐Ÿ’€
  • --security-help โ€” display terse usage info for all of the --security-* options. Your little cheat sheet ๐ŸŽ€
  • --security-freeze โ€” freezes the drive's security settings. After this, the drive doesn't accept any security commands until the next power-on reset. Pair it with --security-unlock to protect the drive from any attempt to set a new password. Works standalone too ๐Ÿ’…. No other options are permitted on the command line with this one.
  • --security-prompt-for-password โ€” prompt for the --security PWD instead of grabbing it from the command line args. This keeps passwords out of your shell history and out of /proc/self/cmdline during execution. Very main character privacy behavior ๐Ÿ‘‘.
  • --security-unlock PWD โ€” unlock the drive using password PWD. The password is given as an ASCII string and is padded with NULs to reach 32 bytes. Which drive password applies is picked with the --user-master switch (default is the "user" password). No other options are permitted on the command line with this one. ๐Ÿ”“
  • --security-set-pass PWD โ€” lock the drive using password PWD (Set Password) (DANGEROUS). Password is an ASCII string, padded with NULs to reach 32 bytes. Use the special password NULL to set an empty password. The applicable drive password is selected with the --user-master switch (default is "user" password) and the applicable security mode with the --security-mode switch. No other options are permitted on the command line with this one. ๐Ÿ”’
  • --security-disable PWD โ€” disable drive locking using password PWD. ASCII string, padded with NULs to reach 32 bytes. Applicable drive password selected via --user-master (default "user" password). No other options are permitted on the command line with this one. ๐Ÿšช
  • --security-erase PWD โ€” erase the (locked) drive using password PWD (DANGEROUS). ASCII string, padded with NULs to reach 32 bytes. Use the special password NULL to represent an empty password. Applicable drive password selected with --user-master (default "user" password). No other options are permitted on the command line with this one. ๐Ÿงน
  • --security-erase-enhanced PWD โ€” enhanced erase of the (locked) drive using password PWD (DANGEROUS). ASCII string, padded with NULs to reach 32 bytes. Applicable drive password selected with --user-master (default "user" password). No other options are permitted on the command line with this one. โœจ๐Ÿงน
  • --user-master USER โ€” specifies which password (user/master) to select. Defaults to the user password. Only useful in combination 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. Only useful in combination with --security-set-pass.
    • h โ€” high security
    • m โ€” maximum security
THIS FEATURE IS EXPERIMENTAL AND NOT WELL TESTED. USE AT YOUR OWN RISK. ๐Ÿ™ˆ

๐Ÿ“ FILES ๐Ÿ“

/etc/hdparm.conf


๐Ÿ’€ BUGS ๐Ÿ’€

Like we said above: the -m sectcount and -u 1 options should be used with caution at first, preferably on a read-only filesystem. Most drives work great with these features, but a few drive/controller combinations are not 100% compatible and filesystem corruption may result. Backup everything before experimenting, bestie, I am begging ๐Ÿ˜ญ.

Some options (e.g. -r for SCSI) may not work with old kernels, since the necessary ioctl()'s weren't supported back then. Old kernel, no vibes.

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. Versatility! ๐ŸŒˆ

The Linux kernel up until 2.6.12 (and probably later) doesn't handle the security unlock and disable commands gracefully โ€” it will segfault and in some cases even panic ๐Ÿ’€. The security commands, however, might actually have been executed by the drive. This poor kernel behavior makes the PIO data security commands rather useless at the moment. Not the drive's fault, smh.

Also note that the "security erase" and "security disable" commands are implemented as two consecutive PIO data commands, and they will not succeed on a locked drive because the second command isn't issued after the segfault. See the code for hints on how to patch it to work around this problem. Despite the segfault, it's often still possible to run two instances of hdparm consecutively and issue the two necessary commands that way. Workaround queen ๐Ÿ‘‘.


๐ŸŒŸ AUTHOR ๐ŸŒŸ

hdparm 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. Legends, all of them. โœจ


๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹


And that's the whole page, bestie, you made it!! ๐ŸŽ‰๐Ÿ’– This is Version 9.65, dated Sep 2022, and it goes out to you from the HDPARM(8) section of the manual ๐Ÿ’…โœจ. Now go back up your data before you touch any of this, ily, bye ๐Ÿซถ๐ŸŽ€

๐Ÿ“ฆ where this page comes from