Linux and Unix Test Disk I/O Performance with DD Command


Do you know how to check the performance of a hard drive like checking the read and write speed on your Linux operating systems? then, this article is for you!! which is basically created to provide you an overview of DD command, which is geared towards better guidance to new users and as an exploration tour for getting started to the Linux world.

What is DD Command?

DD is a command-line utility for Unix and Unix-like operating systems where the primary purpose is to copy a file and converting the format of the data during the process.

How to Test Hard Disk using DD Command?

Open your Linux root terminal and add the following command-

$ sudo dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync

Output should be like this-

tp@linux:~$ sudo dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
[sudo] password for tp:
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.9635 s, 89.8 MB/s
tp@linux:~$

Please note that, 1GB is copied during the test and 89.8 MB/second is served throughout fthe test.

Understanding DD Command

Chunks of DD command should be like this –

if=/dev/zero (if=/dev/input.file)Indicates the input file that you want to read using the DD command.
of=/tmp/test1.img(of=/path/to/output.file)Indicates the output file that you want to write using the DD command
bs=1G(bs=block-size)Indicates the size of the block that you want DD to use (here I have used 1 GB as a block)
count=1 (count=number-of-blocks)Indicates the number of blocks that you want to use in DD to read the block.
oflag=dsync (oflag=dsync)Indicates the synchronization I/O for data.
conv=fdatasynThis command tells DD to synchronize.

Use DD command on Linux to test read speed

Before testing the first flush caches data, use the following command-

$ echo 3 | sudo tee /proc/sys/vm/drop_caches
time time dd if=/path/to/bigfile of=/dev/null bs=8k

Run the following command to test the data with cache-

tp@linux:~$ dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.4265 s, 94.0 MB/s

The above command copies 1.1GB of data and 94.0 MB/s is served for the test.

To deactivate cache, use the following command –

$ sudo hdparm -W0 /dev/sda

The output should be like this –

tp@linux:~$ sudo hdparm -W0 /dev/sda
/dev/sda:
setting drive write-caching to 0 (off)
write-caching = 0 (off)

Run the following command to test the data without cache -

$ dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct

The output should be like this –

tp@linux:~$ dd if=/dev/zero of=/tmp/laptop.bin bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.5062 s, 93.3 MB/s

The above command copies 1.1GB of data and 93.3 MB/s is served for the test.

Congratulations! Now, you know how to test the disk I/O Performance with DD Command. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 17-Jan-2020

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements