This guide introduced the Linux command
hdparm
, a tool for viewing and changing hard drive parameters. It covered the history ofhdparm
, when and why to use it, how to use it, the commonly used parameters, the full list of supported parameters, some common use cases, and some advanced skills. It also highlighted the need for caution when using this tool due to its potential for data loss or drive damage. This guide is intended to provide a comprehensive overview for new users, buthdparm
has a lot more to offer for those who wish to explore further.
Instructions
This article is designed to provide an extensive understanding of the Linux command hdparm
. By following through this tutorial, you will learn about the command's history, reasons for its usage, and how to effectively utilize it. The guide will also cover commonly used parameters, other supported parameters, common use cases, tricky skills, important points to note, and a final conclusion.
History
hdparm
is a Linux command line utility that allows users to view and change the SATA/IDE device parameters. Introduced in the early Linux versions, the hdparm
command, which stands for "Hard Disk Parameters," has become a fundamental tool for managing hard drives on a Linux system.
When and why to use it
hdparm
provides a way to set and view hard disk parameters, making it extremely valuable for optimizing and diagnosing hard drives. It offers the ability to tune hard disk parameters to maximize its performance, longevity and efficiency. It also comes in handy when you need to benchmark drive performance or securely erase data from a drive.
How to use it
The basic usage of hdparm
involves specifying flags (options) followed by the device. For example, to view detailed information about a device (say /dev/sda
), you would use the -I
flag like so:
$ hdparm -I /dev/sda
The command above will print a detailed report about the drive’s capabilities and settings.
The commonly used parameters
There are numerous parameters or flags that can be used with hdparm
to control different aspects of your hard drive. Here are a few commonly used ones:
-a
or--readahead
Get/set sector count for filesystem read-ahead.
$ hdparm -a /dev/sda
This command will show you the current read-ahead value for the device /dev/sda
.
-b
or--set-sector-size
Set physical/logical sector size.
$ hdparm -b /dev/sda
This command will display the physical and logical sector size of the device /dev/sda
.
Other supported parameters
Apart from the commonly used parameters, hdparm
supports numerous other parameters. A few notable ones include:
-A
or-write-read-lookahead
: Enable/disable the IDE drive's read-lookahead feature (usually ON by default)-B
or-acoustic
: Reduce the acoustic noise (at the cost of reduced disk performance)-c
or-io32bit
: Enable/disable 32-bit I/O support-C
or-check-power-mode
: Check the power mode of your drive-d
or-dma
: Enable/disable the use of DMA-D
or-defects
: Manage defect lists-f
or-flushbuf
: Flush the on-drive write buffer-g
or-geometry
: Display the physical and logical geometry of a drive
Most common use cases
Some of the most common use cases of hdparm
include checking the speed of your disk drive, measuring the read speed of a drive, and spinning down a hard drive. Here is how you would measure the read speed of a drive:
$ hdparm -t /dev/sda
This command will perform timing buffer-cache reads on device /dev/sda
and display the read speed.
The tricky skills
While hdparm
is an essential utility for managing hard drives, it also includes some features that are less commonly known, but can be very useful.
One such feature is the secure erase function. This completely wipes the drive of all data, including what would normally be left behind after formatting.
$ hdparm --security-set-pass PASS /dev/sda
$ hdparm --security-erase PASS /dev/sda
The first command sets a password on the drive, which is required for the second command to execute. The second command will then securely erase all data on the drive.
What needs to be noted
One thing to bear in mind is that hdparm
should be used with caution. Incorrect use of some options can result in loss of data or even physical damage to your drive. Always make sure you understand what a command does before you run it.
Conclusion
The hdparm
command is a powerful and versatile tool for managing hard drives in Linux. Its various options allow for extensive customization and control of your drives, but this power also comes with responsibility. Remember to always use hdparm
with care to avoid data loss or damage to your drives.