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.
Whether you’re running a web server, or simply want to optimize your personal computer, understanding your storage I/O performance can make a significant difference.
In this tutorial I will show how to use hdparm to measure storage I/O performance on a Linux machine.
Before diving into the tutorial, it’s essential to have a basic understanding of different web servers like Apache, Nginx, and LiteSpeed. Additionally, knowledge about various hosting types such as dedicated server, VPS server, cloud hosting, and shared hosting can be beneficial.
Let’s get started.
Step 1: Installing hdparm
Before you can use hdparm, you need to ensure it’s installed on your system:
sudo apt-get update sudo apt-get install hdparm
Step 2: Identifying the Storage Device
To measure the speed of a specific storage device, you first need to identify it. Use the following command:
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.
root@geeks:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 368K 0 rom vda 252:0 0 220G 0 disk ├─vda1 252:1 0 219.9G 0 part / ├─vda14 252:14 0 4M 0 part └─vda15 252:15 0 106M 0 part /boot/efi root@geeks:~#
Step 3: Testing Data Read Speed
To measure the read speed of your storage device, use the following command:
sudo hdparm -t /dev/sda
root@geeks:~# sudo hdparm -t /dev/vda /dev/vda: Timing buffered disk reads: 1230 MB in 3.00 seconds = 409.94 MB/sec root@geeks:~#
Replace /dev/vda with the name of your device. This command will provide the speed of data reads in MB/s.
Step 4: Testing Cache Read Speed
To measure the speed of reads from the drive’s cache buffer, use:
sudo hdparm -T /dev/sda
root@geeks:~# sudo hdparm -T /dev/vda /dev/vda: Timing cached reads: 19436 MB in 2.00 seconds = 9730.59 MB/sec root@geeks:~#
Again, 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.
Step 5: Combining Both Tests
You can combine both tests to get a comprehensive view of your drive’s performance:
sudo hdparm -Tt /dev/sda
root@geeks:~# sudo hdparm -Tt /dev/vda /dev/vda: Timing cached reads: 21486 MB in 2.00 seconds = 10758.31 MB/sec Timing buffered disk reads: 1450 MB in 3.00 seconds = 482.69 MB/sec root@geeks:~#
Additional Useful Tests with hdparm
Beyond the basic read/write speed tests, hdparm offers a range of functionalities that can help you understand more about your storage device’s performance and characteristics. Here are some additional tests and commands you can use with hdparm:
1. Displaying Drive Information
To get detailed information about your drive, including its model number, serial number, and supported features:
sudo hdparm -I /dev/sda
2. Checking for Advanced Power Management
Advanced Power Management (APM) can influence the performance and power usage of your drive. To check the APM level:
sudo hdparm -B /dev/sda
3. Setting Advanced Power Management Level
If you want to set the APM level (values can range from 1-255, with 1 being the most aggressive power saving mode):
sudo hdparm -B 127 /dev/sda
4. Checking Drive’s Power Mode
To determine if your drive is active, in standby, or sleeping:
sudo hdparm -C /dev/sda
5. Setting Drive to Standby Mode
If you wish to manually set your drive to standby mode:
sudo hdparm -y /dev/sda
6. Secure Erase
For those looking to securely erase data from a drive (use with caution as this will remove all data):
sudo hdparm --security-erase NULL /dev/sda
7. Displaying Acoustic Management Settings
To check the current acoustic management settings of the drive:
sudo hdparm -M /dev/sda
- sudo apt-get update – Updates the package lists for upgrades and new packages.
- sudo apt-get install hdparm – Installs the hdparm tool.
- lsblk – Lists all storage devices on the system.
- sudo hdparm -t /dev/vda – Measures the read speed of a storage device.
- sudo hdparm -T /dev/vda – Measures the cache read speed of a storage device.
- sudo hdparm -Tt /dev/vda – Combines both the above tests.
- sudo hdparm -I /dev/sda – Displays detailed information about the drive.
- sudo hdparm -B /dev/sda – Checks the APM level of the drive.
- sudo hdparm -B 127 /dev/sda – Sets the APM level of the drive.
- sudo hdparm -C /dev/sda – Checks the drive’s power mode.
- sudo hdparm -y /dev/sda – Sets the drive to standby mode.
- sudo hdparm –security-erase NULL /dev/sda – Securely erases data from the drive.
- sudo hdparm -M /dev/sda – Displays the drive’s acoustic management settings.
- sudo hdparm -M 128 /dev/sda – Sets the acoustic management level of the drive.
What is the primary purpose of hdparm?
Hdparm is a command-line utility in Linux used to set and view hardware parameters of hard disk drives. It can also be used to measure the speed of data reads/writes, among other functionalities.
How accurate is hdparm in measuring storage performance?
Hdparm provides a basic measure of storage performance, especially for sequential data reads. However, for a comprehensive performance analysis, it’s advisable to use specialized benchmarking tools alongside hdparm.
Can hdparm be used on SSDs?
Yes, hdparm can be used on SSDs. However, due to the different nature of SSDs compared to traditional HDDs, some parameters and results might vary.
Is it safe to run hdparm on a mounted drive?
While measuring performance using hdparm is generally safe on a mounted drive, certain operations, especially those that modify drive settings, should be done with caution on mounted drives.
How often should I test my storage device’s performance?
Regularly testing storage device performance can help in early detection of potential issues. However, frequent tests are not necessary unless you suspect a problem or have made changes to your system that might affect performance.
Understanding the performance of your storage devices is crucial, especially for those managing high-traffic websites or critical applications. The hdparm tool offers a straightforward way to gauge the speed of data reads/writes on Linux systems. By following the steps outlined in this tutorial, you can effectively measure the storage I/O performance of your hard drives or SSDs.
While hdparm provides a basic overview of your storage device’s performance, it’s essential to remember that real-world performance can vary based on numerous factors, including system load, other running processes, and the nature of the data being accessed. Therefore, for a more comprehensive analysis, consider using a combination of tools and benchmarking methods.
hdparm is a versatile tool that provides a plethora of functionalities beyond just measuring read/write speeds. By leveraging its capabilities, you can gain deeper insights into your storage device’s performance, power management, and other essential characteristics. Always remember to use caution when altering drive settings and ensure you have backups of critical data before performing operations like secure erase. With the right knowledge and approach, hdparm can be an invaluable asset in optimizing and managing your storage devices on a Linux system.
Regularly test, monitor, and take proactive steps to ensure your storage devices are in top shape, guaranteeing the smooth operation of your systems and applications.