The hdparm Utility: Tune Your Disk

Do you want to get the most out of your hard drive or SSD? hdparm is your tool. Developed by Mark Lord in 2005, this Linux utility allows you to diagnose and optimize your disk, control its speed, manage power saving, and even securely erase SSDs.

Installation and Basic Usage

Most Linux distributions already include hdparm. To start, open a terminal and run:

 hdparm -I /dev/sda | more

This command will show you all the available information about your disk, including the model and firmware version.

Measuring Disk Speed

To know the data transfer speed of your disk, use:

 hdparm -t /dev/sda

Repeat the measurement several times to get an average. If you want to measure the pure speed of the disk, without the effect of the system buffer, use hdparm -t --direct /dev/sda. You can also specify an offset with hdparm -t --direct --offset 500 /dev/sda to test different areas of the disk.

Optimizing Data Transmission

To improve data transmission, hdparm allows you to adjust the number of sectors read at once with the command:

hdparm -m16 /dev/sda

This command configures the simultaneous reading of 16 sectors. Additionally, you can activate the “read-ahead” function with hdparm -a256 /dev/sda, which causes the disk to preemptively read 256 sectors.

Controlling 32-Bit Mode and Disk Noise

With hdparm -c /dev/sda, you can check if your disk is operating in 32-bit mode, and force this mode with -c3. If your disk is noisy, you can reduce the noise by activating the “acoustic mode” with hdparm -M 128 /dev/sda, or maximize speed with `hdparm -M 254 /dev/sda​​​​.

Managing Write Cache

The command hdparm -W /dev/sda allows you to activate or deactivate the write cache, which can speed up data writing but at the risk of data loss in case of power cuts.

Setting Power Saving Mode

You can manage the disk’s power saving with hdparm -B255 /dev/sda to deactivate it, or use values between 1 and 254 for different levels of saving and performance. With hdparm -S 128 /dev/sda, you set the idle time before the disk enters sleep mode.

Cleaning SSDs

SSDs can accumulate residual data blocks. To clean them, use the script /dev/sda, but with caution, as it can lead to data loss.

Secure Erasure in SSDs

For securely erasing an SSD, hdparm offers the “secure erase” function with

hdparm --user-master u --security-erase 123456 /dev/sdb

This process completely removes data, but requires caution as it can render the SSD unusable in some cases.

Handling Old IDE Disks

For IDE disks, it is important to check and configure DMA with hdparm -d1 /dev/hda to improve data transfer. If you encounter problems, deactivate it with `hdparm -d0 /dev/hda​​.

Maintaining Changes After Restarting

To ensure that changes made with hdparm persist after restarting, you must add them to the system startup scripts or, in Debian-based systems, in the /etc/hdparm.conf file.
Remember that this is a powerful tool and should be used with knowledge. Always make backups before making significant changes and consult specific documentation.

Leave a Reply