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-
# dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
Output should be like this-
# dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 11.9635 s, 89.8 MB/s
#
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=fdatasyn : This 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-
# 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 –
# hdparm -W0 /dev/sda
The output should be like this –
# 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 –
# 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!