Ubuntu: testing disk performance from the command line

Ubuntu

In this tutorial, I'll explain how to test the read and write performance of a disk on Ubuntu using the command line.

To give you some points of comparison, I ran the tests on two servers: the first with NVMe drives and the second with a mechanical drive.

To run the tests, we’ll use two commands:

  • hdparm: which will let us test the read speed
  • dd: which will let us test the write speed by creating an 839 MB file

Testing Read Speed

To run the read speed test with hdparm, we’ll pass it two parameters:

  • -T, which tests the cache read speed
  • -t, which tests the disk’s read speed

First, you need to know which disk you’re going to test.

Enter the commanddfto list the drives.

/dev/sda1For the computer with the NVMe drive, I’ll test that drive.

To test the read speed, enter the following command:

sudo hdparm -T -t /dev/sda1

The result is displayed below the command; you can see that the read speed ratio between the two types of drives is nearly 10x.

Testing write speed

To test the write speed, we’ll use the commandddto create an 800MiB file; to do this, we’ll pass it four parameters:

  • if=/dev/zero : specify to fill the file with 0s
  • of=/tmp/output : the output location and filename
  • bs=8k : block size
  • count=100k : number of blocks to write

To test the write speed, enter the following command:

sudo dd if=/dev/zero of=/tmp/output bs=8k count=100k; sudo rm -f /tmp/output

The command returns the time it took to create the file along with the speed; here, too, the difference between the two types of drives is nearly a factor of 10.


You now know how to test a drive’s read and write speeds on Linux.

Romain Drouche
Romain Drouche
System Architect | MCSE: Core Infrastructure
IT infrastructure expert with over 15 years of field experience. Currently a Systems and Networks Project Manager and Information Systems Security (ISS) expert, I use my expertise to ensure the reliability and security of technological environments.

Leave a Comment