LinuxCommandLibrary

hdparm

Get/set hard disk parameters

TLDR

Request the identification info of a given device

$ sudo hdparm -I [/dev/device]
copy

Get the Advanced Power Management level
$ sudo hdparm -B [/dev/device]
copy

Set the Advanced Power Management value (values 1-127 permit spin-down, and values 128-254 do not)
$ sudo hdparm -B [1] [/dev/device]
copy

Display the device's current power mode status
$ sudo hdparm -C [/dev/device]
copy

Force a drive to immediately enter standby mode (usually causes a drive to spin down)
$ sudo hdparm -y [/dev/device]
copy

Put the drive into idle (low-power) mode, also setting its standby timeout
$ sudo hdparm -S [standby_timeout] [device]
copy

Test the read speed of a specific device
$ sudo hdparm -tT [device]
copy

SYNOPSIS

hdparm [OPTIONS] DEVICE...

PARAMETERS

-a <sectors>
    Get or set the sector count for filesystem read-ahead.

-A <0/1>
    Disable or enable the drive's built-in read-lookahead feature (cache).

-B <level>
    Set the Advanced Power Management (APM) level for the drive (1-254, 255 disables).

-c <0/1/3>
    Get or set the 32-bit I/O support flag. (Mostly deprecated/ignored on modern systems).

-C
    Check the drive's current power mode status (e.g., active, idle, standby).

-d <0/1>
    Disable or enable using DMA (Direct Memory Access). (Usually enabled by default and managed by kernel).

-f
    Flush the buffer cache for the specified device.

-g
    Display drive geometry (cylinders, heads, sectors) and size.

-i
    Display basic identification info from the drive.

-I
    Display detailed identification info, including SMART data and supported features.

-m <sectors>
    Get or set the multiple sector I/O count (the number of sectors per I/O interrupt).

-M <level>
    Set the Automatic Acoustic Management (AAM) level for the drive.

-q
    Suppress most messages during operations (quiet mode).

-S <timeout>
    Set the standby (spindown) timeout for the drive in units of 5 seconds (0=off, 241-251=special).

-t
    Perform device read timings (direct disk reads, bypassing the OS buffer cache).

-T
    Perform cache read timings (reads from the OS buffer cache).

-u <0/1>
    Get or set the interrupt-unmask flag (can improve responsiveness but might cause issues).

-v
    Display all settings for the specified drive in a verbose format.

-w <0/1>
    Get or set the drive's write-caching feature.

-W <0/1>
    Disable or enable the drive's write-caching feature.

-y
    Force the drive immediately into standby mode.

-Y
    Force the drive immediately into sleep mode.

-z
    Tell the kernel to re-read the partition table for the specified device.

-Z
    Disable write-caching for all ATA devices. USE WITH EXTREME CAUTION!

DESCRIPTION

hdparm is a command-line utility used for manipulating various hardware parameters of ATA/SATA hard disk drives. It allows users to query settings, optimize performance, manage power consumption, and control security features directly at the device level.

Common uses include testing disk read speeds (cached and uncached), enabling or disabling write caching, adjusting Advanced Power Management (APM) levels, and setting standby timeouts. Because hdparm interacts directly with the device driver, it requires root privileges to execute most operations. While highly effective for fine-tuning, misuse can potentially lead to data loss or system instability, especially when modifying write-caching or security parameters. On modern systems, some of its performance-tuning options might be less critical or even deprecated compared to its historical importance, but it remains a valuable tool for diagnostics and power management.

CAVEATS

hdparm requires root privileges to operate. Incorrect usage, particularly with options that modify write-caching (-W) or security features, can lead to significant performance degradation, data corruption, or render the drive inaccessible. Many of the older performance-tuning options (e.g., -c, -d, PIO modes) are less relevant or ignored by modern Linux kernels and hardware, as the kernel typically manages these optimally. Always exercise caution and consult the man page when modifying drive parameters.

PERFORMANCE DIAGNOSTICS

The command hdparm -tT /dev/sdX is commonly used for quick performance tests. -T measures cached reads (from the OS buffer), while -t measures direct device reads (from the physical disk), providing insight into both buffer and disk performance.

POWER MANAGEMENT

Options such as -S (standby timeout), -y (force standby), -Y (force sleep), and -B (Advanced Power Management) are critical for managing drive power consumption and noise, particularly in laptops or energy-efficient systems.

ATA SECURITY FEATURES

hdparm can interact with ATA security features built into drives. Options like --security-freeze-lock and --user-master (with --pass) allow for setting user/master passwords, locking, and securely erasing drives (via security-erase commands). These features provide hardware-level data protection and secure erasure capabilities.

HISTORY

hdparm has been a fundamental utility in the Linux ecosystem since its early days, primarily developed to optimize performance and manage power for IDE/ATA hard drives. In the era of PIO (Programmed Input/Output) versus DMA (Direct Memory Access), hdparm was crucial for enabling faster DMA transfers. While its role in raw performance tuning has diminished with the advent of SATA and NVMe drives and more sophisticated kernel I/O schedulers, it remains indispensable for fine-tuning power management, accessing low-level device information, and managing ATA security features. Its evolution mirrors the advancements in storage technology within Linux.

SEE ALSO

smartctl(8), blockdev(8), lsblk(8), fdisk(8)

Copied to clipboard