How to Use ‘hdparm’ to Measure the Speed of Data Reads/Writes on Storage Devices in Linux

Estimated reading: 3 minutes 335 views

In Linux, hdparm is a powerful command-line tool that provides a plethora of functionalities for hard disk drives, including the ability to measure the speed of data reads/writes. This is crucial for webmasters and system administrators who wish to gauge the performance of their storage devices.

The actual real read/write speed of your hard drive will be slightly slower and dependent on the file system you decide to format it with. In any case, the hdparm tool should provide you with a solid overview of your hard drive’s speed.

In this tutorial, we will show how to use hdparm to measure storage I/O performance on Linux.

Installing hdparm

Before you can use hdparm, you need to ensure it’s installed on your system:

To install hdparm on Debian/Ubuntu:

apt update
apt install hdparm

For CentOS, AlmaLinux:

yum install hdparm

After it’s installed, check out the examples below to see how to run the hdparm command.

Identifying the Storage Device

To measure the speed of a specific storage device, you first need to identify it. Use the following command:

lsblk

This command will list all the storage devices on your system. Note the device name you wish to test, e.g., /dev/sda or /dev/vda.

Testing Data Read Speed

To measure the read speed of your storage device, use the following command:

hdparm -t /dev/vda

Replace /dev/vda with the name of your device. This command will provide the speed of data reads in MB/s

Adding the –direct option to our command syntax will perform another transfer rate, but this time bypassing the hard drive’s buffer cache memory, and thus reading directly from the disk.

hdparm -t --direct /dev/vda

Add the -v option to your command to increase verbosity and gain some more helpful output from hdparm.

hdparm -tv /dev/vda

In the next example, we will instruct hdparm to read data from the second half of the disk. In our case, the hard drive size is 30GB, meaning we will instruct hdparm to read data starting at 15GB.

hdparm --offset 15 -t /dev/vda

To obtain cached reads, run the following command

hdparm --offset 15 -T /dev/vda

Testing Cache Read Speed

To measure the speed of reads from the drive’s cache buffer, use:

hdparm -T /dev/vda

Replace /dev/vda with your device name. This command gives an idea of how fast the drive can transfer data from its built-in cache.

You can combine both tests to get a comprehensive view of your drive’s performance:

hdparm -Tt /dev/vda

Display drive geometry

hdparm -g /dev/vda

Getting help

Read man page:

 hdparm -help

Conclusion

In this tutorial, we saw how to measure the speed of a hard drive or other type of storage device in Linux. This is easily done using the hdparm command, which gives us a quick and easy way to determine the speed of any connected storage device. We hope this article will be useful for you. Good luck!

Share this Doc

How to Use ‘hdparm’ to Measure the Speed of Data Reads/Writes on Storage Devices in Linux

Or copy link

CONTENTS