20. Use Hdparm to Optimize Your Hard Disk
Sometimes your hard drive starts feeling, well, less than speedy. But before you start thinking of shiny new upgrades, it's easy enough to check your hard disk's performance. That way you'll know whether it's a hardware problem or something else entirely. The "hdparm" command lets you check and tweak your hard disk's performance.


IMPORTANT: The tips in this document require the use of command-line commands. For more information about how to read and execute Linux command-line prompts and commands, please check the Linux Clues Linux Cheat Sheet, especially Linux Prompt Basics and Linux Command-Line Nomenclature.


Here's how to put hdparm to use on your computer. Unlike recent tips, for this one you start by logging in as root. Type:

$ su

Type the root password at the prompt. Then type:

# hdparm -tT /dev/hda

If you have more than one hard drive, you'd use hdb (which specifies your second hard drive) to check the performance of the second drive, like this:

# hdparm -tT /dev/hdb

Those commands should display a screen something this:

Timing buffer-cache reads: 128 MB in 0.68 seconds =188.24 MB/sec
Timing buffered disk reads: 64 MB in 1.59 seconds = 40.25 MB/sec

This performance isn't bad, but could be improved by tweaking some settings. Before you jump right in though, be sure to take some precautions. Some tweaks can cause problems, and may even make your hard disk unstable. First check the current settings:

# hdparm /dev/hda

This will return something like:

multcount= 16 (on)
IO_support= 0 (default 16-bit)
unmaskirq= 0 (off)
using_dma= 1 (on)
keepsettings= 0 (off)
readonly= 0 (off)
readahead= 256 (on)
geometry= 65535/16/63, sectors = 60040544256, start = 0

Write down the parameters and their values, so you can set them back to the old values if needed. Next, closely read and please take the advice offered by this Linux Dev Center article, Speeding up Linux Using Hdparm.

At the very least, please back up all the data on your hard disk.

To find additional info about your hard disk, use this command:

# hdparm -i /dev/hda

This set of sample results from the above command shows just how detailed the information will be:

Model=MAXTOR 6L060J3, FwRev=A93.0500, SerialNo=663214157434
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
RawCHS=16383/16/63, TrkSize=32256, SectSize=21298, ECCbytes=4
BuffType=DualPortCache, BuffSize=1819kB, MaxMultSect=16, MultSect=16
CurCHS=4047/16/255, CurSects=16511760, LBA=yes, LBAsects=117266688
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5 udma6
AdvancedPM=no WriteCache=enabled
Drive conforms to: ATA/ATAPI-5 T13 1321D revision 1:

* signifies the current active mode

These are possible settings for your hard disk, and the tweaks you might make. As an example, to set 32-bit I/O support flag to 3, multicount to 16 and DMA (Direct Memory Access) to 1 (= on), you give the following command from root:

# hdparm -c3 -m16 -d1 /dev/hda

Enabling DMA can in some cases lead to serious instability. To disable DMA:

# hdparm -d0 /dev/hda

After making these tweaks, check to see if performance has improved with this command:

# hdparm -tT /dev/hda

Have fun tweaking, (or in the words of Linux Dev Center, "Happy hacking!") but please don't gamble with your data.