| title | hdparm - Complete Disk Parameter Management Guide | |||
|---|---|---|---|---|
| description | Complete guide to hdparm - Complete Disk Parameter Management Guide | |||
| category | Storage | |||
| tags |
|
|||
| difficulty | beginner | |||
| last_updated | 2026-06-06 | |||
| related_commands |
- hdparm Overview
- Installation
- Disk Information
- Performance Testing
- Power Management
- Security Features
- Advanced Settings
- Acoustic Management
- Cache Management
- Troubleshooting
hdparm is a Linux command-line utility for getting/setting SATA/IDE device parameters. It provides low-level access to hard drive settings for performance tuning and management.
- Read disk information
- Performance benchmarking
- Power management settings
- Security erase/unlock
- Acoustic noise control
- Write cache enable/disable
- Advanced Power Management (APM)
- DMA mode configuration
- SMART feature control
- Performance optimization
- Power saving configuration
- Secure disk wiping
- Acoustic noise reduction
- Troubleshooting disk issues
- Firmware identification
- Transfer mode optimization
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install hdparm
# RHEL/CentOS/Fedora
sudo yum install hdparm
# Arch Linux
sudo pacman -S hdparm
# Verify installation
hdparm -V
# Output: hdparm v9.58# Check if hdparm is available
which hdparm
# Test basic functionality
sudo hdparm -I /dev/sda | head
# List all block devices
lsblk# Detailed disk information
sudo hdparm -I /dev/sda
# Example output:
/dev/sda:
ATA device, with non-removable media
Model Number: WDC WD10EZEX-08M2NA0
Serial Number: WD-WCC3F7HK3456
Firmware Revision: 01.01A01
Transport: Serial, SATA 3.0
Standards:
Supported: 9 8 7 6 5
Likely used: 9
Configuration:
Logical max current
cylinders 16383 16383
heads 16 16
sectors/track 63 63
--
CHS current addressable sectors: 16514064
LBA user addressable sectors: 268435455
LBA48 user addressable sectors: 1953525168
Logical Sector size: 512 bytes
Physical Sector size: 4096 bytes
device size with M = 1024*1024: 953869 MBytes
device size with M = 1000*1000: 1000204 MBytes (1000 GB)
cache/buffer size = unknown
Nominal Media Rotation Rate: 7200
Capabilities:
LBA, IORDY(can be disabled)
Queue depth: 32
Standby timer values: spec'd by Standard, with device specific minimum
R/W multiple sector transfer: Max = 16 Current = 16
Advanced power management level: 128
DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
Cycle time: min=120ns recommended=120ns
PIO: pio0 pio1 pio2 pio3 pio4
Cycle time: no flow control=120ns IORDY flow control=120ns# Basic device info
sudo hdparm -i /dev/sda
# Example output:
/dev/sda:
Model=WDC WD10EZEX-08M2NA0, FwRev=01.01A01, SerialNo=WD-WCC3F7HK3456
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=50
BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=1953525168
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
AdvancedPM=yes: mode=0x80 (128) WriteCache=enabled
Drive conforms to: unknown: ATA/ATAPI-5,6,7,8,9
* signifies the current active mode# Check supported features
sudo hdparm -I /dev/sda | grep -E "Features|supported"
# SMART support
sudo hdparm -I /dev/sda | grep SMART
# Security features
sudo hdparm -I /dev/sda | grep -i security
# Power management
sudo hdparm -I /dev/sda | grep -i "power management"
# NCQ (Native Command Queuing)
sudo hdparm -I /dev/sda | grep NCQ
# TRIM support (SSD)
sudo hdparm -I /dev/sda | grep TRIM# Get disk geometry
sudo hdparm -g /dev/sda
# Example output:
/dev/sda:
geometry = 121601/255/63, sectors = 1953525168, start = 0
# Sector size
sudo hdparm -I /dev/sda | grep "Sector size"
Logical Sector size: 512 bytes
Physical Sector size: 4096 bytes# Extract specific info
model=$(sudo hdparm -I /dev/sda | grep "Model Number" | awk '{print $3,$4}')
serial=$(sudo hdparm -I /dev/sda | grep "Serial Number" | awk '{print $3}')
firmware=$(sudo hdparm -I /dev/sda | grep "Firmware Revision" | awk '{print $3}')
echo "Model: $model"
echo "Serial: $serial"
echo "Firmware: $firmware"# Buffered disk reads (cached)
sudo hdparm -t /dev/sda
# Example output:
/dev/sda:
Timing buffered disk reads: 450 MB in 3.00 seconds = 150.00 MB/sec
# Multiple runs for average
for i in {1..5}; do
echo "Run $i:"
sudo hdparm -t /dev/sda
sleep 2
done# Cache buffer speed test
sudo hdparm -T /dev/sda
# Example output:
/dev/sda:
Timing cached reads: 12000 MB in 2.00 seconds = 6000.00 MB/sec
# Tests memory/cache speed, not disk# Both tests together
sudo hdparm -tT /dev/sda
# Example output:
/dev/sda:
Timing cached reads: 12000 MB in 2.00 seconds = 6000.00 MB/sec
Timing buffered disk reads: 450 MB in 3.00 seconds = 150.00 MB/sec#!/bin/bash
# /usr/local/bin/disk-performance.sh
echo "=== Disk Performance Test ==="
date
for disk in /dev/sd[a-z]; do
[[ -b "$disk" ]] || continue
echo ""
echo "=== Testing $disk ==="
# Model
model=$(sudo hdparm -I $disk 2>/dev/null | grep "Model Number" | awk '{print $3,$4}')
echo "Model: $model"
# Cache read
echo -n "Cache read: "
sudo hdparm -T $disk | grep "Timing" | awk '{print $4, $5, $6}'
# Disk read
echo -n "Disk read: "
sudo hdparm -t $disk | grep "Timing" | awk '{print $4, $5, $6}'
# Average of 3 runs
echo "Average (3 runs):"
total=0
for i in {1..3}; do
speed=$(sudo hdparm -t $disk 2>/dev/null | grep "MB/sec" | awk '{print $11}')
total=$(echo "$total + $speed" | bc)
sleep 1
done
avg=$(echo "scale=2; $total / 3" | bc)
echo " Avg speed: $avg MB/sec"
done# Use --direct flag for direct I/O
sudo hdparm -t --direct /dev/sda
# Bypasses system cache
# More accurate for actual disk performance# Read specific sector
sudo hdparm --read-sector 0 /dev/sda
# Read multiple sectors
sudo hdparm --read-sector 0:10 /dev/sda
# Use with caution - low-level read# Current power mode
sudo hdparm -C /dev/sda
# Possible states:
# active/idle: Drive is active
# standby: Drive is in standby
# sleeping: Drive is in sleep mode
# unknown: Unable to determine# Set standby timeout
sudo hdparm -S 120 /dev/sda
# Values:
# 0: Disable standby
# 1-240: Multiples of 5 seconds (1=5s, 240=20min)
# 241-251: Multiples of 30 minutes
# 252: 21 minutes
# 253: Vendor specific
# 254: Reserved
# 255: 21 minutes 15 seconds
# Common settings:
sudo hdparm -S 0 /dev/sda # Disable
sudo hdparm -S 60 /dev/sda # 5 minutes
sudo hdparm -S 120 /dev/sda # 10 minutes
sudo hdparm -S 241 /dev/sda # 30 minutes# Force standby mode
sudo hdparm -y /dev/sda
# Force sleep mode
sudo hdparm -Y /dev/sda
# Difference:
# -y (standby): Quick wake-up
# -Y (sleep): Slower wake-up, deeper power save# Set APM level
sudo hdparm -B 128 /dev/sda
# Values (1-255):
# 1-127: Permit spin-down (more aggressive power saving)
# 128-254: Do not permit spin-down (performance mode)
# 255: Disable APM
# Common settings:
sudo hdparm -B 1 /dev/sda # Maximum power saving
sudo hdparm -B 128 /dev/sda # Balanced
sudo hdparm -B 254 /dev/sda # Maximum performance
sudo hdparm -B 255 /dev/sda # Disable APM
# Check current APM level
sudo hdparm -I /dev/sda | grep "Advanced power management level"# Set acoustic level
sudo hdparm -M 128 /dev/sda
# Values:
# 0: Disable AAM
# 128: Quiet mode (slower seeks)
# 254: Fast mode (louder seeks)
# For quiet operation
sudo hdparm -M 128 /dev/sda
# For performance
sudo hdparm -M 254 /dev/sda
# Check support
sudo hdparm -I /dev/sda | grep -i acoustic# Get current read-ahead
sudo hdparm -a /dev/sda
# Set read-ahead (512-byte sectors)
sudo hdparm -a 256 /dev/sda
# Larger values = more aggressive prefetch
# Good for sequential reads
# May waste cache for random reads
# Recommended values:
# Random I/O: 256-1024
# Sequential I/O: 2048-8192# Security feature status
sudo hdparm -I /dev/sda | grep -A 10 "Security:"
# Example output:
Security:
Master password revision code = 65534
supported
not enabled
not locked
not frozen
not expired: security count
supported: enhanced erase
2min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.# Freeze security state
sudo hdparm --security-freeze /dev/sda
# Prevents security commands until next power cycle
# Protects against malicious password setting
# Usually done automatically during boot# Set master password (USE WITH CAUTION)
sudo hdparm --user-master m --security-set-pass Pwd /dev/sda
# --user-master: m (master) or u (user)
# Pwd: Password (case-sensitive)
# WARNING: Setting password locks the drive
# Requires password to unlock# Secure erase (DESTROYS ALL DATA)
# Step 1: Set user password
sudo hdparm --user-master u --security-set-pass Pwd /dev/sda
# Step 2: Verify not frozen
sudo hdparm -I /dev/sda | grep frozen
# Should show "not frozen"
# Step 3: Start erase (cannot be stopped!)
sudo hdparm --user-master u --security-erase Pwd /dev/sda
# This runs in firmware, very thorough
# Preferred over dd for SSD (wipes all cells)
# Monitor progress
watch -n 10 'sudo hdparm -I /dev/sda | grep -A 5 Security'# More thorough than standard erase
sudo hdparm --user-master u --security-erase-enhanced Pwd /dev/sda
# Uses enhanced erase if supported
# Check support first:
sudo hdparm -I /dev/sda | grep "enhanced erase"# Unlock password-protected drive
sudo hdparm --user-master u --security-unlock Pwd /dev/sda
# Must match password set earlier# Disable security features
sudo hdparm --user-master u --security-disable Pwd /dev/sda
# Removes password protection
# Requires current password# Check DMA status
sudo hdparm -d /dev/sda
# Enable DMA
sudo hdparm -d1 /dev/sda
# Disable DMA (not recommended)
sudo hdparm -d0 /dev/sda
# Check current transfer mode
sudo hdparm -I /dev/sda | grep "DMA"# Check write cache status
sudo hdparm -W /dev/sda
# Enable write cache
sudo hdparm -W1 /dev/sda
# Disable write cache
sudo hdparm -W0 /dev/sda
# Note: Disabling may reduce performance
# But safer for data integrity
# Check current status
sudo hdparm -I /dev/sda | grep "Write cache"# Set device read-only
sudo hdparm -r1 /dev/sda
# Set device read-write
sudo hdparm -r0 /dev/sda
# Check status
sudo hdparm -r /dev/sda# Check 32-bit I/O status
sudo hdparm -c /dev/sda
# Enable 32-bit I/O
sudo hdparm -c1 /dev/sda
# Can improve performance
# Supported by most modern systems# Check multi-sector I/O
sudo hdparm -m /dev/sda
# Set count (0-16)
sudo hdparm -m16 /dev/sda
# 0 = disable
# Higher values = more sectors per interrupt
# Can improve sequential performance# Apply settings that survive reset (-K)
sudo hdparm -K1 /dev/sda
# Combined with other flags:
sudo hdparm -K1 -W1 -c1 /dev/sda
# Settings persist until power cycle# Query acoustic setting
sudo hdparm -M /dev/sda
# Set quiet mode (128)
sudo hdparm -M 128 /dev/sda
# Set fast mode (254)
sudo hdparm -M 254 /dev/sda
# Disable acoustic management
sudo hdparm -M 0 /dev/sda
# Check if supported
sudo hdparm -I /dev/sda | grep -i "Recommended acoustic"#!/bin/bash
# Test different acoustic levels
echo "Testing acoustic levels..."
for level in 128 192 254; do
echo ""
echo "Setting level: $level"
sudo hdparm -M $level /dev/sda
echo "Running seek test (listen to noise)..."
sudo hdparm -t /dev/sda
read -p "Press enter for next level..."
done
# Reset to default
sudo hdparm -M 128 /dev/sda# Check write cache
sudo hdparm -I /dev/sda | grep "Write cache"
# Enable
sudo hdparm -W1 /dev/sda
# Disable
sudo hdparm -W0 /dev/sda
# Trade-offs:
# Enabled: Better performance, risk of data loss on power failure
# Disabled: Slower writes, better data integrity# Get current read-ahead (in 512-byte sectors)
sudo hdparm -a /dev/sda
# Set read-ahead
sudo hdparm -a 4096 /dev/sda
# Calculate from KB:
# 2MB read-ahead = 2048KB = 4096 sectors (512-byte)
# Tuning recommendations:
# Database: 256-1024 sectors
# File server: 2048-4096 sectors
# Video server: 8192-16384 sectors# Force write cache flush
sudo hdparm -F /dev/sda
# Also works for SSDs
# Ensures all buffered data is written# Check if DMA enabled
sudo hdparm -d /dev/sda
# Should show: using_dma = 1 (on)
# Check transfer mode
sudo hdparm -I /dev/sda | grep "UDMA modes"
# Should show current mode with *
# Check for errors
dmesg | grep -i "dma\|ata"
# Reset to optimal settings
sudo hdparm -d1 -c1 -m16 -W1 /dev/sda# Check power state
sudo hdparm -C /dev/sda
# If in standby, wake up
sudo hdparm -t /dev/sda > /dev/null
# Reset device (use with caution)
sudo hdparm -w /dev/sda
# Check kernel messages
dmesg | tail -50 | grep sda# Some settings don't survive reboot
# Create systemd service or udev rule
# /etc/udev/rules.d/60-hdparm.rules
ACTION=="add", KERNEL=="sda", RUN+="/sbin/hdparm -B 128 -S 120 /dev/sda"
# Reload udev
sudo udevadm control --reload-rules
sudo udevadm trigger
# Or use /etc/hdparm.conf (if available)
cat >> /etc/hdparm.conf << 'EOF'
/dev/sda {
apm = 128
spindown_time = 120
write_cache = on
}
EOF# Some commands don't work on all drives
# Check error messages
# USB drives often need -d sat flag
sudo hdparm -d sat -I /dev/sdb
# RAID controllers may not support hdparm
# Use controller-specific tools instead
# For NVMe drives, use nvme-cli instead
sudo nvme id-ctrl /dev/nvme0# Consistent benchmarking
#!/bin/bash
echo "Disk Benchmark (5 runs)"
# Drop caches before test
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
total=0
for i in {1..5}; do
speed=$(sudo hdparm -t /dev/sda 2>/dev/null | grep "MB/sec" | awk '{print $11}')
echo "Run $i: $speed MB/sec"
total=$(echo "$total + $speed" | bc)
sleep 2
done
avg=$(echo "scale=2; $total / 5" | bc)
echo "Average: $avg MB/sec"This comprehensive guide covers all major hdparm operations for disk parameter management, performance tuning, and security features.