Block device read-write test utility written in bash
disk-test [-a|--actions actions] [-b|--block-size blockSize] [-c|--count-bytes numberOfBytes] [-s|--skip-bytes numberOfBytes] [--] deviceOrFile disk-test [--help]
Tests if a device can write and correctly read arbitrary data over its entire reported size, or over a specified range.
In particular, performs an arbitrary sequence of actions on the device or on a range thereof. The desired sequence is given as a string of characters. Available actions are:
Terminates with exit code 2 if the data being read is not identical to the data that has been written before (in case of "v"), or if a device-related error occurs.
The pseudo-random data varies for each "w" action and is generated by encrypting a stream of zeros with 256-bit AES in CTR mode, which should be reasonably fast and usually outperforms /dev/urandom.
The primary use case is to assess data storage mediums' correct operation with the goal of preventing data loss. To give some examples, the utility may be used to
Apart from preventing data loss, identifying faulty devices well ahead of a warranty's or defects liability's deadline may avoid unnecessary expenses.
Used data storage mediums should be wiped before they are sold; using disk-test on them is one way to achieve this within reasonable time while on the same occasion indicating damaged mediums that should not be put up for sale.
The utility may also be used to estimate devices' bulk read and particularly write speeds of incompressible data, notably of mediums that traditionally struggle with data writing throughput such as USB thumb drives, SD cards and low-capacity solid state disks.
Testing, then zeroing a new 500 GB Kingston A2000 M.2 NVMe PCIe SSD (SA2000M8/500G):
[user@system ~]$ su -c 'disk-test --actions wvwvz -- /dev/nvme0n1' root Password: INFO Testing block device or file: "/dev/nvme0n1" INFO Performing 5 action(s): "wvwvz" INFO Action 1/5 (w) on device "/dev/nvme0n1": Wvwvz INFO Writing pseudo-random: 465GiB 0:27:50 [ 285MiB/s] [==================>] 100% INFO Action 2/5 (v) on device "/dev/nvme0n1": wVwvz INFO Reading and comparing: 465GiB 0:14:00 [ 567MiB/s] [==================>] 100% INFO Action 3/5 (w) on device "/dev/nvme0n1": wvWvz INFO Writing pseudo-random: 465GiB 0:26:12 [ 303MiB/s] [==================>] 100% INFO Action 4/5 (v) on device "/dev/nvme0n1": wvwVz INFO Reading and comparing: 465GiB 0:13:47 [ 576MiB/s] [==================>] 100% INFO Action 5/5 (z) on device "/dev/nvme0n1": wvwvZ INFO Writing zeros: 465GiB 0:24:54 [ 319MiB/s] [==========================>] 100% INFO Finished, no errors: "/dev/nvme0n1" [user@system ~]$
Testing, then zeroing a new 18 TB Toshiba MG09 series Enterprise Capacity SATA HDD (MG09ACA18TE), which took about 5 days:
[root@system ~]# disk-test --block-size 32M --actions wvzv -- /dev/sdc INFO Testing block device or file: "/dev/sdc" INFO Performing 4 action(s): "wvzv" INFO Using custom block size "32M" INFO Action 1/4 (w) on device "/dev/sdc": Wvzv INFO Writing pseudo-random: 16.4TiB 38:54:19 [ 122MiB/s] [=================>] 100% INFO Action 2/4 (v) on device "/dev/sdc": wVzv INFO Reading and comparing: 16.4TiB 22:39:22 [ 210MiB/s] [=================>] 100% INFO Action 3/4 (z) on device "/dev/sdc": wvZv INFO Writing zeros: 16.4TiB 35:13:42 [ 135MiB/s] [=========================>] 100% INFO Action 4/4 (v) on device "/dev/sdc": wvzV INFO Reading and comparing: 16.4TiB 22:39:20 [ 210MiB/s] [=================>] 100% INFO Finished, no errors: "/dev/sdc" [root@system ~]#
A fake 32 GB microSD card was found to only have 7.5 GiB of actual storage space:
[user@system ~]$ sudo disk-test --actions wvz /dev/sdb Password: INFO Testing block device or file: "/dev/sdb" INFO Performing 3 action(s): "wvz" INFO Action 1/3 (w) on device "/dev/sdb": Wvz INFO Writing pseudo-random: 31.2GiB 0:26:35 [20.1MiB/s] [==================>] 100% INFO Action 2/3 (v) on device "/dev/sdb": wVz INFO Reading and comparing: 7.50GiB 0:06:51 [18.7MiB/s] [====> ] 23% error writing output file ERROR Reading and comparing pseudo-random data failed with return value 1 [user@system ~]$
When testing devices that support SMART error reporting, as do virtually all SATA devices and many USB-connected HDDs and SSDs, it is a good idea to retrieve and store a SMART error report before testing. After testing it can be compared against a new SMART report to see whether certain telltale attribute values have deteriorated.
If the RAW_VALUE of these attributes has increased the device's reliability might be compromised (this list is incomplete):
SMART reports can be retrieved with the "smartctl -a <device>" command; smartctl is part of smartmontools.
SMART-capable devices usually support running self-tests, typically a superficial one ("short") and a complete scan ("long"). HDDs often also offer a "conveyance" test.
It is a good idea to run the complete/long SMART self-test on the device in addition to disk-test. A device can be told to run this self-test with the command "smartctl -t long <device>"
This self-test is faster than disk-test but still takes some time; as a ballpark figure for HDDs assume about 1 hour per TB.
After completion the test results will be shown in the SMART report in the respective section.
Also, before and after the complete/long self-test look out for these SMART attributes; they are typically only updated during such a self-test. If their RAW_VALUE has increased the device might have reliability problems (list also incomplete):
GNU General Public License version 3
These source files of the latest tag can be viewed in the browser:
15 February 2020 (2020-02-15 00:10:44 UTC)
15 February 2020 (2020-02-15 00:01:03 UTC)
disk-test-0.2.4.tar.gz SHA256 checksum SHA384 checksum PGP signature
disk-test_0.2.4-1-ubuntu-20.04-focal_all.deb SHA256 checksum SHA384 checksum PGP signature
disk-test_0.2.4-1-ubuntu-22.04-jammy_all.deb SHA256 checksum SHA384 checksum PGP signature
disk-test_0.2.4-1-debian-11-bullseye_all.deb SHA256 checksum SHA384 checksum PGP signature
03 November 2019 (2019-11-03 16:19:28 UTC)
disk-test-0.2.3.tar.gz SHA256 checksum SHA384 checksum PGP signature
26 September 2019 (2019-09-26 20:16:50 UTC)
disk-test-0.2.2.tar.gz SHA256 checksum SHA384 checksum PGP signature
25 September 2019 (2019-09-25 18:19:40 UTC)
disk-test-0.2.1.tar.gz SHA256 checksum SHA384 checksum PGP signature
24 September 2019 (2019-09-24 16:53:18 UTC)
disk-test-0.2.0.tar.gz SHA256 checksum SHA384 checksum PGP signature
01 October 2018 (2018-10-01 21:10:44 UTC)
disk-test-0.1.1.tar.gz SHA256 checksum SHA384 checksum PGP signature
30 April 2018 (2018-04-30 22:10:28 UTC)
disk-test-0.1.0.tar.gz SHA256 checksum SHA384 checksum PGP signature