How to Check Disk Read and Write Speed in Linux with HDPARM Utility

Checking the disk read and write speed is essential to understand the performance of your system and useful to determine the performance of your storage device, especially when it comes to disk read/write speeds. This is crucial for tasks such as server management, where the speed of data transfer can significantly impact performance.

Whether you’re using a dedicated server, a VPS server, or cloud hosting, knowing how to check disk read/write speed in Linux is a valuable skill. In Linux, there are various tools available to check disk read and write speed.

In this tutorial, we will be focusing on how to use hdparm, a command-line utility that serves as a powerful tool for checking disk read/write speed in Linux.

hdparm is a Linux utility used to set and view hardware parameters of hard disk drives. It can also perform several types of disk performance measurements, such as reading disk sectors into the operating system’s page cache and measuring the speed of reading through the cache to the processor.

I will explain how to check disk read and write speed using the hdparm and dd commands. This guide will be useful for those who want to test disk speed in Linux, specifically check disk read/write speed.

Step 1: Install hdparm

Before we can use hdparm, we need to ensure it’s installed on our system. On most Linux distributions, hdparm comes pre-installed. However, if it’s not, you can install it using the package manager of your Linux distribution.

For Debian-based systems like Ubuntu, use the following command:

sudo apt-get install hdparm

For Red Hat-based systems like CentOS, use the following command:

sudo yum install hdparm

For example:

[root@server ~]# yum install hdparm -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * Webmin: download.webmin.com
 * base: mirror.upsi.edu.my
 * epel: ftp.cuhk.edu.hk
 * extras: mirror.upsi.edu.my
 * updates: centos.mirror.secureax.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package hdparm.x86_64 0:9.43-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch                  Version                      Repository           Size
====================================================================================================
Installing:
 hdparm                x86_64                9.43-4.el6                   base                 81 k

Transaction Summary
====================================================================================================
Install       1 Package(s)

Total download size: 81 k
Installed size: 150 k
Downloading Packages:
hdparm-9.43-4.el6.x86_64.rpm                                                 |  81 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : hdparm-9.43-4.el6.x86_64                                                         1/1
  Verifying  : hdparm-9.43-4.el6.x86_64                                                         1/1

Installed:
  hdparm.x86_64 0:9.43-4.el6

Complete!

Step 2: Check Disk Read Speed

To check the disk read speed using hdparm, run the following command:

sudo hdparm -t /dev/sda

Replace /dev/sda with the actual device name of your storage device. This command will test the sequential read speed of your storage device and display the result in megabytes per second (MB/s).

[root@centos63 ~]# hdparm -tT /dev/sda

/dev/sda:
 Timing cached reads:   4128 MB in  2.00 seconds = 2065.62 MB/sec
 Timing buffered disk reads:  276 MB in  3.06 seconds =  90.30 MB/sec
[root@centos63 ~]# hdparm -tT /dev/sdb

/dev/sdb:
 Timing cached reads:   3410 MB in  2.00 seconds = 1705.84 MB/sec
 Timing buffered disk reads:  364 MB in  3.00 seconds = 121.29 MB/sec

Step 3: Check Disk Write Speed

To check the disk write speed, we will use the dd command. Run the following command:

sudo dd if=/dev/zero of=test bs=1G count=1 oflag=direct

This command will create a test file named test with a size of 1 gigabyte (GB) and write it to your storage device. The oflag=direct option tells dd to bypass the file system cache and write directly to the disk. The bs option specifies the block size.

See also  How to Find Big Files Size on Linux RHEL/CentOS

After the test file is created, dd will display the write speed in bytes per second (B/s).

Step 4: Clean Up

After you have finished testing the disk read and write speed, you can delete the test file by running the following command:

sudo rm test

Commands Mentioned:

  • sudo apt-get install hdparm – Install hdparm
  • sudo hdparm -t /dev/sda – Check disk read speed
  • sudo dd if=/dev/zero of=test bs=1G count=1 oflag=direct – Check disk write speed
  • sudo rm test – Clean up

hdparm Usage Options

[root@centos63 ~]# hdparm

hdparm - get/set hard disk parameters - version v9.16

Usage:  hdparm  [options] [device] ..

Options:
 -a   get/set fs readahead
 -A   get/set the drive look-ahead flag (0/1)
 -b   get/set bus state (0 == off, 1 == on, 2 == tristate)
 -B   set Advanced Power Management setting (1-255)
 -c   get/set IDE 32-bit IO setting
 -C   check drive power mode status
 -d   get/set using_dma flag
 -D   enable/disable drive defect management
 -E   set cd/dvd drive speed
 -f   flush buffer cache for device on exit
 -F   flush drive write cache
 -g   display drive geometry
 -h   display terse usage information
 -H   read temperature from drive (Hitachi only)
 -i   display drive identification
 -I   detailed/current information directly from drive
 -k   get/set keep_settings_over_reset flag (0/1)
 -K   set drive keep_features_over_reset flag (0/1)
 -L   set drive doorlock (0/1) (removable harddisks only)
 -M   get/set acoustic management (0-254, 128: quiet, 254: fast)
 -m   get/set multiple sector count
 -N   get/set max visible number of sectors (HPA) (VERY DANGEROUS)
 -n   get/set ignore-write-errors flag (0/1)
 -p   set PIO mode on IDE interface chipset (0,1,2,3,4,...)
 -P   set drive prefetch count
 -q   change next setting quietly
 -Q   get/set DMA queue_depth (if supported)
 -r   get/set device  readonly flag (DANGEROUS to set)
 -R   obsolete
 -s   set power-up in standby flag (0/1) (DANGEROUS)
 -S   set standby (spindown) timeout
 -t   perform device read timings
 -T   perform cache read timings
 -u   get/set unmaskirq flag (0/1)
 -U   obsolete
 -v   defaults; same as -acdgkmur for IDE drives
 -V   display program version and exit immediately
 -w   perform device reset (DANGEROUS)
 -W   get/set drive write-caching flag (0/1)
 -x   obsolete
 -X   set IDE xfer mode (DANGEROUS)
 -y   put drive in standby mode
 -Y   put drive to sleep
 -Z   disable Seagate auto-powersaving mode
 -z   re-read partition table
 --dco-freeze      freeze/lock current device configuration until next power cycle
 --dco-identify    read/dump device configuration identify data
 --dco-restore     reset device configuration back to factory defaults
 --direct          use O_DIRECT to bypass page cache for timings
 --drq-hsm-error   crash system with a "stuck DRQ" error (VERY DANGEROUS)
 --fibmap          show device extents (and fragmentation) for a file
 --fibmap-sector   show absolute LBA of a specfic sector of a file
 --fwdownload            Download firmware file to drive (EXTREMELY DANGEROUS)
 --fwdownload-mode3      Download firmware using min-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode3-max  Download firmware using max-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode7      Download firmware using a single segment (EXTREMELY DANGEROUS)
 --idle-immediate  idle drive immediately
 --idle-unload     idle immediately and unload heads
 --Istdin          read identify data from stdin as ASCII hex
 --Istdout         write identify data to stdout as ASCII hex
 --make-bad-sector deliberately corrupt a sector directly on the media (VERY DANGEROUS)
 --prefer-ata12    use 12-byte (instead of 16-byte) SAT commands when possible
 --read-sector     read and dump (in hex) a sector directly from the media
 --security-help   display help for ATA security commands
 --trim-sectors    tell SSD firmware to discard unneeded data sectors (lba and count)
 --verbose         display extra diagnostics from some commands
 --write-sector    repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS)

Conclusion

Understanding the performance of your disk drives is crucial in managing and optimizing your Linux system, whether it’s a dedicated server, a VPS server, or a cloud hosting setup. The hdparm utility provides a straightforward and effective way to measure read speeds, while the dd command can be used to test write speeds.

See also  How to Install Vim on CentOS 6.3

However, it’s important to remember that these tools only provide a snapshot of your disk’s performance at a given time. Disk performance can vary based on a variety of factors, including system load, running processes, and hardware health. Therefore, regular monitoring and multiple tests at different times can provide a more comprehensive view of your disk’s performance.

By learning how to check disk read/write speed in Linux, you can better understand your system’s performance and make informed decisions about system optimization, data management, and hardware upgrades. This knowledge is especially valuable for webmasters and website administrators who need to ensure optimal performance for their users.

See also  How to Setup Zimbra Collaboration Suite 7.2.0 Mail Server on CentOS 6.2 x86_64

Remember, the key to effective system management is not only understanding how to perform these tests but also knowing how to interpret the results and apply this knowledge to improve system performance.

If you have any comments or suggestions for improvements, please feel free to share them below.

Comments

2 Comments

  • Avatar Shop Lahore says:

    Nice information, LG LED Tv in lahore valuable and excellent design, online Mobile Store in lahore

    as share good stuff smart tv in lahore with good ideas and concepts, iphone 5S

    lots of great information and LED 3D Tv in Lahore inspiration, both of which I need, Digital Camera

    thanks to offer such a helpful information here

  • Avatar homepage says:

    It’s nearly impossible to find educated people in this partiucular subject, however, you seem
    like you know what you’re talking about! Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *