LLI Wiki — My Digital Knowledge Base

Testing disk speed and integrity on Linux

Quickly measure disk read and write speed on Linux, and detect a faulty disk or memory with checksums.

This article lists a few quick commands to check the read and write speed of a disk on Linux, and a simple repeatable test to detect a faulty disk or memory. Run these tests on a machine you can afford to load, and make sure there is enough free space for the test files.

Read speed

hdparm measures buffered and cached read speed of a block device. --direct bypasses the cache for the timed read, and -t -T runs the timed-read and cached-read tests:

sudo hdparm --direct -t -T /dev/sda

Replace /dev/sda with the device to test.

Write speed

Write a 512 KB file with synchronous writes, then remove it:

dd if=/dev/zero of=/tmp/test2.img bs=512 count=1000 oflag=dsync
rm -v -i /tmp/test2.img

To write to a specific filesystem, run the test from a directory on that filesystem with a 4 KB block size:

dd if=/dev/zero of=./test2.img bs=4096 count=1000 oflag=dsync
rm -v -i ./test2.img

oflag=dsync makes each write wait until the data reaches the disk, so the result reflects the disk rather than the page cache.

Integrity test

Write a 1 GB file, then read it back five times and compare the checksums:

dd if=/dev/zero of=/tmp/test.file bs=1M count=1000
for i in {1..5}; do md5sum /tmp/test.file; done

All checksums should be identical. Different checksums for the same file point to a faulty disk or faulty memory. The duration depends on the hardware. Delete /tmp/test.file afterwards.

Notes

Mastodon LLIMastodon SocialFosstodon