How to Measure Disk Write Speed in Ubuntu Using dd with Direct I/O

Evaluating raw storage performance on Ubuntu servers, desktop NVMe drives, and USB flash storage is essential when configuring database hosts, tuning hypervisors, or validating solid-state drive health. While many users attempt benchmarking using standard file copy commands or basic dd transfers, operating system caching mechanisms buffer written data in RAM, resulting in artificially inflated speed figures (often exceeding several gigabytes per second). To measure genuine physical disk write throughput, you must configure dd with direct I/O flags to bypass the Linux page cache.

Understanding Linux Disk Caching vs Direct I/O

When a process writes data in Linux, the kernel writes the bytes to volatile system memory (the page cache) first and synchronises them to physical disk sectors asynchronously later. A standard command like dd if=/dev/zero of=testfile bs=1G count=1 measures RAM speed rather than storage throughput. To force synchronous write operations directly onto the underlying physical NAND flash or magnetic platters, you must instruct dd to use oflag=direct or perform an explicit conv=fdatasync flush.

Measuring Sequential Write Speed with Direct I/O

To run an accurate write benchmark, create a temporary benchmark file on your target partition using direct output flags. Open your terminal (Ctrl + Alt + T) and execute:

dd if=/dev/zero of=./test_write.tmp bs=1M count=1024 oflag=direct status=progress

Command breakdown:

  • if=/dev/zero: Sources an endless stream of zero-byte raw characters.
  • of=./test_write.tmp: The destination test file created on your current working storage mount.
  • bs=1M: Writes data in 1 Megabyte block increments, simulating large sequential write operations.
  • count=1024: Transfers 1,024 blocks (totalling exactly 1.07 GB).
  • oflag=direct: Forces direct I/O, completely bypassing the Linux page cache so data writes directly to the storage controller.
  • status=progress: Displays real-time transfer progress and throughput updates.

Upon completion, dd outputs the final benchmark statistics:

1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.84321 s, 583 MB/s

The final value (e.g. 583 MB/s) represents the sustained physical write speed of your storage device.

Measuring Latency with Synchronous Flushing (fdatasync)

On certain external filesystems or virtualised cloud storage volumes where direct hardware flags are restricted, use conv=fdatasync as an alternative. This parameter forces dd to pause and wait until all buffered data is completely committed to non-volatile storage before terminating the benchmark timer:

dd if=/dev/zero of=./test_write.tmp bs=1M count=1024 conv=fdatasync status=progress

Cleaning Up Benchmark Files

Because the test generated a temporary multi-gigabyte file on your local filesystem, remember to delete the dummy file immediately following testing to reclaim your disk space:

rm -f ./test_write.tmp

Running this benchmark periodically provides a dependable baseline for monitoring drive performance degradation over time.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.