hdparm
is a command-line utility in Linux used for displaying and configuring various parameters of hard disks. It is used to get information about the hard disk, such as its model number, firmware version, and serial number, as well as to optimize the hard disk’s performance by setting various parameters.
Overview
The syntax for using hdparm
is as follows:
hdparm [options] [device]
Where options
are the various flags that can be used with hdparm
, and device
is the name of the hard disk device to configure. If no device is specified, hdparm
will display information for all hard disks.
Examples
To display information about the hard disk /dev/sda
, use the following command:
hdparm /dev/sda
To display information about all hard disks, use the following command:
hdparm -I /dev/sd*
To set the Advanced Power Management (APM) level of /dev/sda
to 128, use the following command:
hdparm -B 128 /dev/sda
Specific Use Cases
Some common use cases for hdparm
include:
- Displaying information about the hard disk, such as its model number, firmware version, and serial number.
- Checking the hard disk’s performance and health.
- Optimizing the hard disk’s performance by setting various parameters, such as the Advanced Power Management (APM) level, read-ahead buffer size, and write-caching policy.
- Troubleshooting hard disk issues, such as slow performance or data corruption.
Options
The following table lists the available options for hdparm
:
Option | Description |
---|---|
-a |
Get/set the read-ahead buffer size. |
-A |
Get/set the Advanced Power Management (APM) level. |
-b |
Get/set the bus state (on/off). |
-B |
Get/set the Advanced Power Management (APM) level. |
-c |
Get/set the I/O DMA mode. |
-C |
Check the power mode status. |
-d |
Get/set the I/O DMA mode. |
-D |
Get/set the drive’s DMA mode. |
-E |
Set the drive’s write-caching policy. |
-f |
Flush the drive’s write cache. |
-F |
Flush the drive’s write cache and force an IDE drive to immediately enter standby mode. |
-g |
Display the drive’s geometry. |
-h |
Display the help message. |
-i |
Display the drive’s identification information. |
-I |
Display the drive’s identification information in detail. |
-J |
Get/set the write cache enable/disable flag. |
-k |
Get/set the keep settings over power cycle flag. |
-K |
Set the drive’s keep settings over power cycle flag. |
-L |
Get/set the drive’s door lock state. |
-m |
Get/set the multiple sector count. |
-M |
Get/set the acoustic management (AM) level. |
-n |
Get/set the ignore-write-errors flag. |
-N |
Get/set the max sector count. |
-p |
Get/set the PIO mode. |
-P |
Get/set the drive’s prefetch count. |
-q |
Suppress the output of the command. |
-Q |
Get/set the queue depth. |
-r |
Get/set the read-only flag. |
-R |
Get/set the write-read-verify flag. |
-s |
Get/set the standby (spindown) timer. |
-S |
Put the drive into standby (spindown) mode. |
-t |
Perform device read timings. |
-T |
Perform cache read timings. |
-u |
Get/set the unmaskirq flag. |
-U |
Get/set the security unlock password. |
-v |
Display the version number. |
-V |
Display the vendor-specific log. |
-W |
Get/set the write-caching flag. |
-X |
Set the drive’s transfer mode. |
-y |
Put the drive into sleep mode. |
-Y |
Put the drive into standby (spindown) mode. |
-Z |
Disable the automatic acoustic management (AM) feature. |
-z |
Re-read the partition table. |
Troubleshooting Tips
Some common issues that may arise when using hdparm
include:
- Permission denied errors:
hdparm
requires root privileges to run. Make sure to runhdparm
as root or with sudo privileges. - Incorrect device name: Make sure to specify the correct device name when using
hdparm
. You can use thelsblk
command to list all available block devices and their names. - Unsupported hardware: Some hard disks may not support certain features or parameters, or may have limited functionality. Make sure to check the hard disk’s documentation or specifications before using
hdparm
.
Notes
hdparm
can be a powerful tool for optimizing the performance of your hard disks, but it should be used with caution. Make sure to read the hard disk’s documentation and specifications before usinghdparm
, and always backup your data before making any changes to the hard disk’s configuration.hdparm
may not work with certain types of hard disks, such as solid-state drives (SSDs) or network-attached storage (NAS) devices. Make sure to check the hard disk’s compatibility withhdparm
before using it.