Gathering information and tuning hard drives on Linux


Many Linux distributions include hdparm in the basic installation. It can provide information on drives, measure and tune drives.

Gathering Device Information

# hdparm -I /dev/sda | more

Provides detail information on the sda device (usually the first hard drive).

(add screen capture)

Hdparm can communicate with most (E)IDE, SATA, or SAS interfaces including DVDs and SSDs. USB-to-IDE adapters sometimes do not transmit complete ATA or ATAPI commands to drives. Hdparm is dependent on the device being used.

On newer hard disks, you should check whether Native Command Queuing (NCQ) is to be found under Commands/features. This technology makes it possible for the hard disk to sort queries from the system in such a way that the drive head uses the shortest possible path. SSDs, on the other hand, distribute write accesses more efficiently across storage blocks. Ideally, this leads to an increase in speed. If NCQ is deactivated, check the BIOS to find out whether the drive is running in AHCI mode, which is also necessary for other functions such as energy management.

Device Measurement

To determine how fast a drive processes data

# hdparm -t /dev/sda

(add screen capture)

The Linux kernel uses a buffer when communicating with a hard drive. To disable this buffer and measure the drive and controller performance –

# hdparm -t –direct /dev/sda

Hdparm reads the data directly from the hard drive.

(add screen capture)

Magnetic Hard Drive performance degrades as a hard drive fills with data. To simulate this impact, Hdparm can be told to read data starting at an offset.

# hdparm -t –direct –offset 500 /dev/sda

The 500 stands for the number of gigabytes to skip. On a 1TB hard disk, the command above would therefore deliver data from the middle of the disk. The speed will drops due to the location of data on the hard drive.

Adjusting Drive Settings

Some drive properties can be changed while the device is in operation, most drives allow you to turn power management on and off. The hard drive functions hdparm can change and activate can be seen using:

# hdparm -I /dev/sda

Review the Commands/features section. All functions found there and marked with an asterisk are currently active. Hdparm change or activate these options.

To speed up data transmission, a hard disk can read several sectors at once. Hdparm displays the current (default) setting which is usually optimal (listed after R/W multiple sector transfer: Max =. This value is also be found after Current =.) This setting can be change using –

# hdparm -m16 /dev/sda

This instructs the hard drive to deliver 16 sectors.

Some hard drives run slower with higher values. In such cases, you can reduce the number of sectors again or even turn the function off :

# hdparm -m0 /dev/sda

Newer hard drive have read ahead logic. The amount of read ahead can be set using –

# hdparm -a256 /dev/sda
The read-ahead is set to 256

The current setting is shown using

# hdparm -a /dev/sda

Many drives have an additional read-ahead function. As a rule leave the setting at the default value.

How fast queries from the operating system reach the hard drive controller is reviewed using –

# hdparm -c /dev/sda

Controlling Hard Drive Noise

Some hard drives are able to reduce noise levels by slowing head movement. Doing so increases access times to reduce noise levels. To check if a hard drive has this option –

# hdparm -M /dev/sda

To set the highest head movement speed –

# hdparm -M 254 /dev/sda

Write-Back Caching

With write-back caching, the hard drive first stores the data to be written in a buffer. In this way, it can accept data much faster, which in the end leads to a faster write speed. To review the current setting –

# hdparm -W /dev/sda

Use -W1 to enable the hard drive write-back cache and -W0 to disable.

If hdparm will not allow this change, make sure write-back caching has been activated in the controller BIOS. The Write-back drive cache should NOT be enabled when using software or hardware RAID 1, 5, 6, or 10.

Saving Power

Hard Drives and SSD can automatically enters sleep mode when not in use. This power-saving feature can be influenced with the -B parameter.

# hdparm -B255 /dev/sda

Using -B255 deactivates energy management. Some drives do not allow this.

Instead of 255, values between 1 and 254 are allowed. A higher value means more power is used but also promises higher performance or speed. Values between 1 and 128 allow the drive to shut down whereas values from 129 to 254 forbid that from happening.

The most power can be saved with a value of 1; the highest rate of data transmission (I/O performance) is achieved with 254.

To display the current value –

# hdparm -B /dev/sda

To set the seconds of idleness a hard drive should wait before it sleeps –

# hdparm -S 128 /dev/sda

The value is not in seconds. The hard drive multiplies the setting by a factor to define seconds. A value of 0 will deactivate sleep mode completely. At 251, the waiting period is 5.5 hours. At 253, the value is preset by the manufacturer, usually between eight and 12 hours.

To cause the hard drive to sleep immediately –

# hdparm -y /dev/sda

With a capital Y, the drive will go into an even deeper state of sleep. Depending on the drive, the drive might only wake up from a deep sleep after a reset of the whole system.

DMA (Direct Memory Access)

Using DMA (Direct Memory Access) technology, hard drives are able to deposit data directly into main memory. If the respective flag is 0 (off), it will slow down the data transfer. To activate DMA use the command –

# hdparm -d1 /dev/hda

While hard drives are transferring requested data, the system can complete other tasks but only if an on appears after unmaskirq in the identification info output. The mode can be set ON using the -u1 switch.

DMA mode is not supported well on all servers. After activating it, test by copying large files to the drives. If problems arise, deactivate the DMA mode and re-test.

To deactivate DMA mode, use the command –

hdparm -d0 /dev/hda

Saving hdparm values about OS boot

After restarting the system, all changes made with hdparm are lost. To activate them permanently, the respective hdparm commands must be entered in the start scripts. How this is done depends on the distribution you are running, but usually the entry is made in/etc/rc.local.

Debian-based systems read the /etc/hdparm.conf configuration file on system startup. Update the section for each hard drive with the following format:

/dev/sda {
  ...
}

Linux distros now randomly allocate device names (sda, sdb). To assign the hdparm settings to a specific drive permanently, use its specific UUID:

/dev/disk/by-id/ata-SAMSUNG_HD103SJ_S246J1RZB00034 {...}

Acoustic management is set to the value of 128 with:

acoustic_management = 128

Which name belongs to which hdparm parameter is revealed by the comments at the top of the file.

Leave a comment