How to use the command `hdparm` (with examples)
- Linux
- December 25, 2023
The hdparm
command is used to get and set SATA and IDE hard drive parameters. It allows users to retrieve information about a device, control power management settings, and test the read speed of a specific device. This article will provide examples of each of these use cases to demonstrate how the hdparm
command can be utilized.
Use case 1: Request the identification info of a given device
Code:
sudo hdparm -I /dev/device
Motivation: Retrieving the identification information of a device can be useful to obtain specific details about the hard drive, including its model, serial number, firmware version, and supported features.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-I
: This option stands for “identity” and is used to request identification information about the device./dev/device
: The path to the device you want to retrieve the identification info for.
Example output:
/dev/device:
ATA device, with non-removable media
Model Number: ST2000DM008-2FR102
Serial Number: ABC123456789
Firmware Revision: CC26
Transport: Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
Used: unknown (minor revision code 0x0000)
Supported: 10 9 8 7 6 5
Not supported: 4 3 2 1 0
Command set coenabled: NOP
Use case 2: Get the Advanced Power Management level
Code:
sudo hdparm -B /dev/device
Motivation: Checking the Advanced Power Management (APM) level can help identify the current power-saving configuration of the hard drive, enabling users to optimize power consumption if necessary.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-B
: This option stands for “APM” and is used to get the Advanced Power Management level./dev/device
: The path to the device you want to retrieve the APM level for.
Example output:
/dev/device:
Advanced power management level: 128
Use case 3: Set the Advanced Power Management value
Code:
sudo hdparm -B 1 /dev/device
Motivation: By setting the Advanced Power Management value, users can control the power-saving behavior of their hard drives, such as enabling spin-down to reduce power consumption.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-B
: This option stands for “APM” and is used to set the Advanced Power Management value.1
: The desired APM value, where values from 1 to 127 permit spin-down, and values from 128 to 254 prevent spin-down./dev/device
: The path to the device you want to set the APM value for.
Example output:
/dev/device:
apm_level = 1
Use case 4: Display the device’s current power mode status
Code:
sudo hdparm -C /dev/device
Motivation: Checking the power mode status of a device can provide information on whether the hard drive is currently idle, active, or in standby mode.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-C
: This option stands for “Check” and is used to display the device’s current power mode status./dev/device
: The path to the device you want to retrieve the power mode status for.
Example output:
/dev/device:
drive state is: standby
Use case 5: Force a drive to immediately enter standby mode
Code:
sudo hdparm -y /dev/device
Motivation: Forcing a drive to enter standby mode can be useful for power-saving purposes, as it causes the drive to spin down and conserve energy when it is not actively in use.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-y
: This option stands for “immediately Check” and is used to force the drive to enter standby mode./dev/device
: The path to the device you want to force into standby mode.
Example output:
/dev/device:
setting standby to 1 (5 seconds)
Use case 6: Put the drive into idle (low-power) mode, also setting its standby timeout
Code:
sudo hdparm -S standby_timeout device
Motivation: Putting a drive into idle mode and configuring the standby timeout can help optimize power management by specifying how long the drive should remain idle before entering standby mode.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-S
: This option stands for “Standby timeout” and is used to specify the timeout value in 5-second increments.standby_timeout
: The desired standby timeout value.device
: The path to the device you want to put into idle mode.
Example output:
/dev/device:
setting standby to 60 (300 seconds)
Use case 7: Test the read speed of a specific device
Code:
sudo hdparm -tT device
Motivation: Testing the read speed of a device can provide insights into its performance capabilities and help identify any potential bottlenecks in the data transfer rate.
Explanation:
sudo
: This prefix is used to run thehdparm
command with administrative privileges.hdparm
: The command itself.-tT
: This option stands for “test Timing” and is used to perform a read speed test on the device.device
: The path to the device you want to test the read speed for.
Example output:
/dev/device:
Timing buffered disk reads: 400 MB in 3.00 seconds = 133.33 MB/sec
Conclusion:
The hdparm
command is a versatile tool for managing and optimizing the power management settings of SATA and IDE hard drives. With it, users can retrieve identification information, control power-saving behavior, and test the read speed of their devices. By understanding the different use cases and options available with hdparm
, users can effectively monitor and configure their hard drives for optimal performance and power consumption.