How To Find Hard Disk Data Transfer Speed In Linux
This guide will teach you how to find hard disk data transfer speed in Linux. In other words, we are going to identify how fast your drive delivers data. We are also going to talk about other useful things like how many sectors can a HDD read at once, read ahead feature, acoustic mode, write-back caching and bench-marking hdd etc. In our previous tutorial, we talked how to find hdd details using hdparm command line utility. Now we will use the same utility to measure the hard disk transmission speed.
A word of caution
Even though hdparm offers significant advantages to increase disk performance, it is also EXTREMELY DANGEROUS. It will very likely lead to massive data loss when some parameters are misused. The hdparm documentation suggests that YOU SHOULD NOT USE SOME COMMANDS AT ANY CIRCUMSTANCES. So I’ve excluded such dangerous commands in this guide. More importantly, It is always recommended to backup your hard drive before testing hdparm on your Linux system.
Find Hard Disk Data Transfer Speed In Linux
To check the HDD data transfer speed in Linux, run “hdparm” command with -t flag like below:
$ sudo hdparm -t /dev/sda
/dev/sda: Timing buffered disk reads: 246 MB in 3.00 seconds = 81.97 MB/sec
As you can see, the data transfer rate is 81.97 MB per second. Make sure no other programs are running in the background. Run this command at least two or three times and calculate the average data transfer speed of your drive from the results.
As you can see in the above output, the Linux kernel puts the data retrieved from HDD into a buffer when transferring data. If you want to measure more accurate data transfer rate, use:
$ sudo hdparm -t --direct /dev/sda
/dev/sda: Timing O_DIRECT disk reads: 242 MB in 3.02 seconds = 80.21 MB/sec
Now, the hdparm program will not use buffer and will read the data directly from the hdd. As you noticed in the above output, the transfer rate has decreased without the buffer.
Hdparm will always read the data from the beginning of the storage devices. If you want hdparm to read data from other area of the storage device, you can use the “offset” parameter like below.
$ sudo hdparm -t --direct --offset 10 /dev/sda
Here, 10 stands for number of Gigabytes to skip. As per the above command, the first 10 GB will be skipped while reading data from the disk. On a 20GB disk, the above command would deliver data from the middle of the disk.
dev/sda: Timing O_DIRECT disk reads (offset 10 GB): 244 MB in 3.01 seconds = 81.15 MB/sec
Compare the hdd transfer rate with and without offset values. When we used the “offset” parameter in the second command, the transfer rate has decreased. Hence, It seems that hard disks delivers data little bit slower from outer areas of the disks.
Find how many sectors a hard disk reads
Usually, a hard disk will read several sectors at the same time to speed up the data transmission. You can find this value by running:
$ sudo hdparm -I /dev/sda
Under the “Capabilities” section, you will see an output like below.
[...] Capabilities: LBA, IORDY(can be disabled) Queue depth: 32 Standby timer values: spec'd by Standard, no device specific minimum R/W multiple sector transfer: Max = 16 Current = 16 Advanced power management level: 254 Recommended acoustic management value: 208, current value: 208 DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 [...]
As per the above output, my hdd reads 16 sectors at a time.
Some modern HDDs can retrieve sectors in advance. This feature is called “read ahead”. You can find this value using “-a” flag like below:
$ sudo hdparm -a /dev/sda
/dev/sda: readahead = 256 (on)
As you see in the above output, the hdd can read 256 sectors in advance.
Put HDD in quiet mode to increase access time
We can slow down the head movement in some modern hard disks. Slowing down head movement will decrease the noise level and increase access times. To check if your HDD supports this “acoustic mode” feature, run:
$ sudo hdparm -M /dev/sda
If your drive supports acoustic mode, you should an output like below.
/dev/sda: acoustic = 208 (128=quiet ... 254=fast)
The current acoustic mode value is 208 in my system. The acoustic mode values can be set between 128 to 254.
To put the HDD in quiet mode, run:
$ sudo hdparm -M 128 /dev/sda
To put the head movement in high speed, run:
$ sudo hdparm -M 254 /dev/sda
Please note that your operating system should support this feature.
If doesn’t support this feature, you will see this:
dev/sda: acoustic = not supported
When the Write-back caching mode is enabled, the hdd will put the data to be written in a buffer. This way the hdd can able to write faster.
To verify if write-back caching mode is enabled, use “-W” flag.
$ sudo hdparm -W /dev/sda
/dev/sda: write-caching = 1 (on)
If the output value is 1, the write-back caching feature is enabled. If it is 0, the write-back caching is disabled. You can enable it using command:
$ sudo hdparm -W1 /dev/sda
If hdparm can not enable this feature, make sure the write-back caching feature is enabled in your BIOS.
To disable it, simply use:
$ sudo hdparm -W0 /dev/sda
Even though write-caching increases the write speed, it is not recommended in some situations. For instance, when the power is gone suddenly, the data in the buffer would be permanently lost. So you should not enable the write-back caching feature when running database programs like PostgreSQL.
Benchmark Hard disk
To benchmark the HDD and test the readable speed of the drive, use uppercase “T” and lowercase “t” flags together like below.
$ sudo hdparm -Tt /dev/sda
/dev/sda: Timing cached reads: 7232 MB in 1.99 seconds = 3629.42 MB/sec Timing buffered disk reads: 250 MB in 3.01 seconds = 82.99 MB/sec
Repeat this command at least 2-3 times to get the meaningful result.
If you don’t like the command line way, the GNOME Disks GUI program also allows you us to benchmark hard disks.
Open Disks from menu or dash. Select the disk you want to benchmark and click three dots and choose “Benchmark Disk” option.
Click “Start Benchmark” option to start bench-marking:
For more details, check man pages.
$ man hdparm
Hope this helps.