I generally use hdparm to test the speed of disks in Linux. The command I use is:
hdparm -tT /dev/sda
This quickly tests the throughput, but I thought I’d share another method which actually puts more strain on the disk.
Simply using dd you can run this command to see the write speed:
dd if=/dev/zero of=test bs=1048576 count=2048
and then this command to check the read speed:
dd if=test of=/dev/null bs=1048576
What this does is write 2G of zeros to a file in the first command, and then reads that file in the second command.
Pretty basic, simple, yet useful.
#1 by abbakus on May 25, 2011 - 8:06 am
Simple and useful!
“dd” and “netcat” are great instruments, always good to talk about.
Always remember people that “dd” stands for “disk destroyer” :-)
If you run as root and miss the of= parameter you are in big big trouble.
#2 by Paul Jakubik on August 23, 2013 - 11:09 am
Sometimes I see impossibly fast numbers when using /dev/zero as an input source. I get more realistic numbers with /dev/urandom, or otherwise using source data that can’t be represented by a file hole.
#3 by Eduardo on November 10, 2013 - 3:52 pm
According to the manual page, if you omit the “of” parameter then it will write to stdout which is connected to the terminal, why you say it’ll destroy the disk?
#4 by Chris on November 15, 2013 - 1:15 am
I tried you method but ran into a problem. I wanted to test the speeds of a usb connected 2.5 HD.
The first command to write the file worked perfectly:
#:/media/chris/Storage$ dd if=/dev/zero of=test bs=1048576 count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 29.9929 s, 71.6 MB/s
But when I tried to read the file using the second command I got this:
#:/media/chris/Storage$ dd if=test of=/dev/null bs=1048576
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 0.407218 s, 5.3 GB/s
Obviously my little usb HD is not capable of 5.3 GB/s. So I had another file already on the disk that was 3.4GB that I could use as the if:
dd if=en_windows_server_8_beta_x64_dvd_810648.iso of=/dev/null bs=1048576
3423+1 records in
3423+1 records out
3589316608 bytes (3.6 GB) copied, 104.624 s, 34.3 MB/s
That number made much more sense. Just pointing that out for others. I’m not sure what you would do if you did not have another file already or exactly what caused the super speeds. Probably cache I imagine.
Thanks for the commands they did work in the end!
#5 by jg3 on December 3, 2013 - 4:06 pm
Thanks, I always forget the dd syntax.
@Chris – in your 5.3 GB/s test you said of=/dev/null which means the output was to the bit bucket, rather than your test disk. Had you used of=/midea/chris/Storage/test-file you would have written to the test-file disk as intended. Also, you’ll want to use if=/dev/zero or if=/dev/urandom as the source for that output.
tl;dr you got whacky results because you ran dd before reading `man dd`
#6 by mitchell on January 7, 2014 - 10:00 pm
For a noob friendly version of this you can find it at http://vpstip.com/how-to-check-disk-speed-easily-in-linux/
Thanks for the write up !
#7 by Malcolm on February 13, 2014 - 4:04 pm
/dev/zero and /dev/null are handled by the system’s file manager and have nothing to do with the backing storage…
#8 by jw on March 12, 2014 - 2:58 am
Pro tip: bs=1G count=2
Much easier to read for example :)
or bs=1M count=2048
#9 by steve on March 12, 2014 - 8:34 pm
Ah yes that is true. Thanks for mentioning that on the page.
I always type it out like that when I actually run the tests. Not sure what I was thinking (years ago) when I originally wrote this.