Introduction
In the world of Linux system management, knowing the performance and parameters of storage devices is essential for optimizing the performance of servers and workstations. One of the most powerful and versatile tools for this purpose ishdparm. This command allows you to read and modify attributes of hard drives and solid state units (SSD) connected by ATA / SATA interfaces, providing detailed information on the transfer mode, cache, energy saving features and, above all, sequential reading speed. In this article we will explore what ishdparm, how to install it, the most useful parameters and how to use it to measure the speed of your disk safely.
What is hdparm?
hdparm (Hard Disk Parameter) is a command line utility that directly interacts with the ATA controller of the block devices. Its main function is to consult and change parameters such as the transfer mode (PIO, DMA, UDMA), the cache block size, the activation or deactivation of the write-caching, the noise level and the waiting time before entering the suspension mode. Although its name suggests that it only works with mechanical hard drives, it also works with SSD and hybrid units, provided that the controller exposes them through the ATA interface.
Installation and requirements
In most Linux distributions, hdparm comes pre-installed or is available in official repositories. To install it in Debian / Ubuntu runs:
sudo apt-get update & sudo apt-get install hdparm
In Red Hat / CentOS / Fedora:
sudo dnf install hdparm
Once installed, just open a terminal and runhdparm -I /dev/sdX(replacing sdX with your disk identifier) to see the detailed device information. Root privileges are required for most operations, so it is recommended to usesudoor log in as root.
More useful parameters
-I: Disk identification information (model, serial number, capabilities, supported modes).-t: Conduct a sequential reading test and show speed in MB / s.-T: Evaluates the speed of the disk cache (reading from the buffer).-c: Obtains or establishes the 32-bit transfer mode.-d: Activates or disables the use of DMA.-a: Read or set the number of sectors to be read in advance (read-ahad).-S: Define the waiting time before entering suspension mode (in 5-second units).-W: Activates or disables the write-caching.-M: Obtains or sets the level of acoustic noise (0-254 value).
Measure disk speed
The most common way to use hdparm for benchmarking is to combine the options-Tand-t. The test-Tmeasures cache speed by reading data already stored in the disk buffer, while-tperform a direct sequential reading from the physical environment, avoiding cache. A typical example would be:
sudo hdparm -Tt / dev / sda
The output will show something like:
/ dev / sda: Timing cached reads: 1234 MB in 2.00 seconds = 617.5 MB / sec Timing buffet disk reads: 567 MB in 3.01 seconds = 188.45 MB / sec
The first number corresponds to the cache (generally higher) and the second to the direct reading of the disc, which is the most representative metric of sustained performance. To achieve more reliable results, it is recommended to run the test several times and measure the values, making sure that the system is not under intense load during the measurement.
Practical examples
Suppose you want to activate the UDMA 6 mode on a disk that supports it. First check the modes supported withhdparm -I /dev/sdb | grep 'UDMA'. Then, to set the mode, use:
sudo hdparm -c1 -d1 / dev / sdb
The Flag-c1activates the 32 bit mode and-d1active DMA. If your driver and disk allow, this can significantly improve the transfer speed.
Another useful case is to reduce energy consumption in a laptop. You can set a shorter suspension time with:
sudo hdparm -S24 / dev / sdc
Where the value 24 equals 24 × 5 seconds = 2 minutes. After this period of inactivity, the disc will enter suspension mode, saving battery.
Finally, if you notice that your disk has a high noise level, you can try to lower it:
sudo hdparm -M 128 / dev / sdd
Lower values reduce noise but can slightly increase access time; it is a commitment that depends on the use environment.
Precautions and good practices
Although hdparm is powerful, its abuse can cause instability or data loss. Some key recommendations:
- Always back up critical data before modifying parameters that affect the transfer mode or the write-caching.
- Test changes in a non-productive environment or a test disk before applying them to production servers.
- Avoid disabling the write-caching on disks that do not have energy protection (such as UPS) as it could cause data loss in an unexpected power cut.
- After changing a parameter, check that the disk is still properly recognized with
hdparm -Iand that no errors appear indmesgor in the system logs. - Remember that some parameters, such as the UDMA mode, are limited by the controller and the cable; trying to force an unsupported mode can cause detection failures.
Conclusion
hdparm remains an indispensable tool for any system manager who needs to inspect and adjust the behavior of Linux storage devices. Its ability to consult detailed information, modify transfer modes, manage cache and measure performance makes it an ally for both performance optimization and energy saving. With the knowledge of its most important parameters and following the good practices described above, you can make the most of your hard drives and SSD, ensuring a balance between speed, reliability and resource consumption. We invite you to experiment with hdparm in your own environment and share your findings in the Linux community.


