How to use the command 'hdparm' (with examples)
- Linux
- December 17, 2024
hdparm
is a powerful command-line utility used for managing and configuring SATA and IDE hard drives in Linux-based systems. It provides users with the ability to obtain detailed information about their drives, adjust performance options like power management, and even test drive speeds. Due to its capability to tweak low-level drive parameters, hdparm
is widely used by system administrators and power users who need to fine-tune their storage configurations to optimize performance and power efficiency.
Use case 1: Request the identification info of a given device
Code:
sudo hdparm -I /dev/device
Motivation:
Requesting the identification info of a hard drive provides you with important specifications such as the model number, serial number, firmware revision, and supported features of the drive. This is crucial for verifying the hardware configuration, inventory management, and ensuring that firmware versions are up-to-date. Understanding your drive’s capabilities can help in planning upgrades, troubleshooting, or validating compatibility with other hardware components.
Explanation:
sudo
: This command requires superuser privileges as it accesses hardware-level information.hdparm
: The command used to get and set hard drive parameters.-I
: This option requests the identification information of the drive./dev/device
: The path to the device file representing the hard drive (e.g., /dev/sda).
Example output:
/dev/sda:
ATA device, with non-removable media
Model Number: ST1000DM003-1ER162
Serial Number: Z4Y37B5T
Firmware Revision: CC45
...
Use case 2: Get the Advanced Power Management level
Code:
sudo hdparm -B /dev/device
Motivation:
Retrieving the Advanced Power Management (APM) level of a hard drive allows you to understand how the drive is balancing power consumption with performance. APM settings are especially important for laptops or systems that rely on battery power, as lowering power usage prolongs battery life. System admins might also use APM to reduce heat output in tightly packed data centers or improve the acoustic environment by damping down drive noise.
Explanation:
sudo
: Required to access drive parameters.hdparm
: The command-line utility.-B
: Option to display the current APM level./dev/device
: Path to the specified device.
Example output:
/dev/sda:
APM_level = not supported
Use case 3: Set the Advanced Power Management value
Code:
sudo hdparm -B 1 /dev/device
Motivation:
Setting the APM value to a specific level directly affects the drive’s power management strategy. Values between 1-127 allow drives to spin down during idle periods, effectively conserving power. This is particularly useful for energy-efficient setups or systems with thermal constraints. On the other hand, values between 128-254 prevent spin-downs for better performance, suited for environments where constant drive access is required, such as servers.
Explanation:
sudo
: Runs the command with superuser permissions.hdparm
: Utility to configure drive parameters.-B 1
: Option-B
is followed by1
, setting APM to permit spin-down./dev/device
: Represents the device to be configured.
Example output:
/dev/sda:
setting Advanced Power Management level to 0x01 (1)
APM_level = 1
Use case 4: Display the device’s current power mode status
Code:
sudo hdparm -C /dev/device
Motivation:
Understanding the current power mode status of a hard drive can help diagnose performance or power issues. If a drive is frequently entering standby or idle modes while under load, it may indicate power management misconfigurations. Conversely, never entering low-power states might suggest a need to adjust settings to save energy. Monitoring power modes can thus assist in making data-driven optimizations for both personal and enterprise systems.
Explanation:
sudo
: Necessary for modifying hardware configurations.hdparm
: Command-line tool for managing drive settings.-C
: Option to check the current power mode./dev/device
: Denotes the device being queried.
Example output:
/dev/sda:
drive state is: active/idle
Use case 5: Force a drive to immediately enter standby mode
Code:
sudo hdparm -y /dev/device
Motivation:
Putting a drive into standby mode when it is not required can be a quick way to save energy and reduce wear. This command is particularly helpful when you know a system or drive will be idle for an extended period, such as during off-hours or when temporarily migrating workloads to another device. Manually triggering standby can complement automated power management settings in providing a balanced approach to performance and longevity.
Explanation:
sudo
: Required for authority to alter drive states.hdparm
: Utility for drive adjustment.-y
: Signals the drive to enter standby mode./dev/device
: Drive targeted for the operation.
Example output:
/dev/sda:
issuing standby command
Use case 6: Put the drive into idle mode, setting its standby timeout
Code:
sudo hdparm -S standby_timeout /dev/device
Motivation:
Configuring a hard drive to enter idle mode with a defined standby timeout helps tailor the balance of power-saving and responsiveness. Machines benefiting from this setup include personal computers with varying active periods and network-attached storage devices see sporadic access. Ensuring that disks spin down after custom intervals can also reduce ambient noise levels without impeding performance concerns during peak usage.
Explanation:
sudo
: Superuser privileges to modify drive parameters.hdparm
: Tool for interacting with drive capabilities.-S standby_timeout
: Option to set standby timeout; ‘standby_timeout’ is a placeholder for specific timing./dev/device
: The designated drive.
Example output:
/dev/sda:
setting standby to 48 (4 minutes)
Use case 7: Test the read speed of a specific device
Code:
sudo hdparm -tT /dev/device
Motivation:
Determining the read speed of a hard drive is essential for assessing performance bottlenecks and ensuring that disk throughput meets application requirements. This is a common operation during system benchmarking or after upgrades to confirm improvements. System administrators and tech enthusiasts utilize these results to compare different storage solutions or to troubleshoot underperforming drives.
Explanation:
sudo
: Provides necessary access to test read speeds.hdparm
: Utility for evaluating drive metrics.-tT
: Conducts timings of cache reads and device reads for speed analysis./dev/device
: Drive undergoing the speed test.
Example output:
Timing cached reads: 16316 MB in 2.00 seconds = 8160.08 MB/sec
Timing buffered disk reads: 386 MB in 3.01 seconds = 128.33 MB/sec
Conclusion:
hdparm
is an indispensable tool for Linux users who need to manage and optimize hard drive configurations. Whether accessing detailed drive information, adjusting power settings, or conducting performance tests, this utility provides a suite of commands that support diverse storage needs. Through the use cases presented, users can better understand how to leverage hdparm
for enhancing system efficiency and performance.