Disk speed in Linux affects how quickly large files can be read or written. Sequential read and write tests measure that speed using a verified device and a temporary file on its mounted filesystem.
The read test uses hdparm on the block device backing the chosen filesystem, while dd writes through that filesystem. These short sequential tests provide a baseline for HDDs and SSDs, rather than measuring random I/O or application latency.
Benchmarks compete with applications for I/O, so a quiet system gives more consistent results. A 1 GiB write also needs free space and can fit inside an SSD's fast write cache; compression and thin provisioning can make zero-filled data faster to write than ordinary files.
Requires hdparm. On Ubuntu and Debian, the package is also named hdparm.
Related: How to show disk information in Linux
Related: How to check disk health in Linux
Related: How to show disk activity on Linux
Steps to test disk read and write speed in Linux:
- Check which device holds the directory to test and how much space is free. Example output:
$ df -h /mnt/data Filesystem Size Used Avail Use% Mounted on /dev/loop0 3.9G 1.1M 3.7G 1% /mnt/data
The path /mnt/data stands for a writable directory on the disk to test. The Filesystem column is the device for the read tests, and Avail needs at least 2 GiB for the 1 GiB write test. A network share or tmpfs has no block device for hdparm to read. The examples use a virtual disk, so physical disk rates will differ.
Benchmarking increases live I/O and flushes the device's buffer cache, which can slow other workloads. A quiet period on the device limits this disruption.
- Measure cached and buffered read timing on the device. Example output:
$ sudo hdparm -Tt /dev/loop0 /dev/loop0: Timing cached reads: 13984 MB in 2.00 seconds = 7000.76 MB/sec Timing buffered disk reads: 674 MB in 3.01 seconds = 224.00 MB/sec
Timing buffered disk reads is the sequential device read rate through the buffer cache, with previously cached data flushed before testing. Timing cached reads measures CPU, cache, and memory throughput rather than disk speed.
- Measure direct read timing when a baseline that bypasses the page cache is needed. Example output:
$ sudo hdparm -t --direct /dev/loop0 /dev/loop0: Timing O_DIRECT disk reads: 1898 MB in 3.01 seconds = 630.08 MB/sec
--direct makes hdparm use O_DIRECT for the -t test. Direct and buffered results use different I/O paths and need separate comparisons.
- Write a 1 GiB test file to measure sequential write speed.
Writing to a block device with dd overwrites disk data. The of= target must be a regular file such as /mnt/data/disk-benchmark.img, not a device such as /dev/sda.
$ dd if=/dev/zero of=/mnt/data/disk-benchmark.img bs=64M count=16 oflag=direct status=progress ##### snipped ##### 16+0 records in 16+0 records out 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.23725 s, 148 MB/s
The last value on the final line is the write speed. oflag=direct bypasses the kernel page cache. If the filesystem rejects direct I/O with Invalid argument, rerun the test with conv=fdatasync in place of oflag=direct so dd flushes the file before it exits, and compare that result only with other conv=fdatasync runs. Two or three runs with the same directory and system load give a more useful comparison than one.
Related: How to check dd progress in Linux - Remove the test file.
$ rm /mnt/data/disk-benchmark.img