Wednesday, May 2, 2012

hdparm - get/set hard disk parameters


You need to run the below commands by login as root,  specifying the wrong settings can cause data loss or your maching to hang.

Find the setting for your driver supports

root@tester [~]# hdparm -i /dev/sda

/dev/sda:

 Model=WDC, FwRev=01.01V02, SerialNo=WD-WCAW33126764
 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=50
 BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=off
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=1953525168
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio3 pio4
 DMA modes:  mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: Unspecified:  ATA/ATAPI-1,2,3,4,5,6,7

 * signifies the current active mode

Using hdparm - Speed Test

Before any of your drive's settings are changed a speed test should be done, so we can refer to it later to make sure that the drive's speed has been increased and we are not just wasting our time.

To do this hdparm can perform two benchmarks:

The speed of reading directly from the Linux buffer cache without disk access. (-t option)
The speed of reading through the buffer cache to the disk without any prior caching of data. (-T option)
The first shows us an indication of the throughput of the processor, cache, and memory of the system under test. The second measures how fast the drive can sustain sequential data reads, without any filesystem overhead.It is best to run these tests together as the second results are corrected for the first. It is also as usual to run these a couple of times to get accurate results. Here is the command you need to use:

root@tester [~]# hdparm -Tt /dev/sda

/dev/sda:
 Timing cached reads:   24846 MB in  2.00 seconds = 12442.48 MB/sec
 Timing buffered disk reads:  340 MB in  3.00 seconds = 113.22 MB/sec


To list the current settings being used for your drive use the command:

root@tester [~]# hdparm /dev/sda

/dev/sda:
 multcount     =  0 (off)
 IO_support    =  1 (32-bit)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 121601/255/63, sectors = 1953525168, start = 0

You can change the settings by view the man page of hdparm

eg:  hdparm -X66 -d1 -u1 -m16 -c3 /dev/sda

After each settings made you need to run the speed and performace test for it and the new settings will be activated after every boot.

the -a flag you can get readahead information from the drive:

hdparm -a /dev/sda

/dev/sda:
 readahead     = 256 (on)

hdparm -C /dev/sda

/dev/sda:
 drive state is:  active/idle

You can also check the hard disk size using the hdparm command

syntax:  hdparm -I /dev/sda |grep and hit enter key

root@tester [~]# hdparm -I /dev/sda | grep "device size"
        device size with M = 1024*1024:      953869 MBytes
        device size with M = 1000*1000:     1000204 MBytes (1000 GB)

You can also check the model number and serial number of a hard drive using the hdparm command

root@tester [~]# hdparm -I /dev/sd?|grep -E "Number|/dev"
/dev/sda:
        Model Number:       WDC WD1003FBYX-18Y7B0
        Serial Number:      WD-WCAW33126764
/dev/sdb:
        Model Number:       WDC WD1003FBYX-18Y7B0
        Serial Number:      WD-WCAW33123668





No comments: