diff --git a/README.md b/README.md index d2fb47b..f44c02d 100644 --- a/README.md +++ b/README.md @@ -1,177 +1,171 @@ -# disktest - Tester for Solid State Disks (SSDs), Non-Volatile Memory Storage (NVMe), Hard Disks (HDDs), USB Sticks, SD-Cards, etc. +# disktest - Storage Media Tester -[Homepage](https://bues.ch/h/disktest) +[Homepage](https://bues.ch/h/disktest) | [crates.io site](https://crates.io/crates/disktest) | [Github repository](https://github.com/mbuesch/disktest) -[crates.io site](https://crates.io/crates/disktest) +**Disktest** is a tool to check Solid State Disks (SSDs), Non-Volatile Memory Storage (NVMe), Hard Disks (HDDs), USB sticks, SD cards, or other storage media for errors. -[Github repository](https://github.com/mbuesch/disktest) - -Disktest is a tool to check Solid State Disks, Non-Volatile Memory Storage, Hard Disks, USB sticks, SD cards or other storage media for errors. - -It does so by writing a pseudo-random sequence to the device and then reading it back and verifying it against the same pseudo-random sequence. +## Why use disktest? This tool can be used to: -- Check disks for hardware errors (e.g. platter errors, flash errors, etc.). -- Overwrite storage media with a cryptographically-strong pseudo-random stream. This can either be used to delete existing data on the disk, or to prepare the disk for encryption. -- Test for tampered media that pretend to have more storage area than they physically have. Sometimes such media are sold by fraudulent sellers at cheap prices. -- Measure read and write speed. -- ... probably lots of other tasks. - -The pseudo-random number stream is generated by the following algorithm: - -``` -OUTPUT_DATA := CHACHA20(PBKDF2(SEED | THREAD_ID | ROUND_ID)) -``` - -If more than one thread is used, then each thread generates such a stream, and the streams are interleaved in an alternating pattern. +- **Detect Hardware Errors**: Check disks for platter errors, flash memory degradation, or other hardware failures. +- **Secure Data Wipe**: Overwrite storage media with a cryptographically-strong pseudo-random stream. This is ideal for securely deleting existing data or preparing a disk for encryption. +- **Uncover Fake Capacity Storage**: Test for tampered media that pretend to have more storage area than they physically possess (common with cheap, fraudulent SD cards or USB drives). +- **Benchmark Performance**: Measure the raw read and write speed of your storage devices. +- ... and lots of other storage-related tasks. +## Comparison with F3 -# Security +While tools like `f3` (Fight Flash Fraud) or `h2testw` are also used to test storage media, **disktest** is designed with several advantages: +- **Generally Faster**: Disktest is typically much faster. +- **Realistic Full-Disk Workload**: It ensures that every piece of data can be retrieved accurately after writing the disk to full capacity, mimicking heavy real-world usage. +- **Unfakable Verification**: Because every single byte is part of an unpredictable pseudo-random sequence, disk controllers cannot cheat the test using transparent data compression or deduplication. Every byte must be physically stored and correctly retrieved. -The default algorithm [ChaCha20](https://en.wikipedia.org/wiki/Salsa20) is a cryptographically strong random number generator. That means if the seed is kept secret, the pseudo-random sequence cannot be predicted or reconstructed by anybody else. +## Quick Start Example -See option `--seed` under `--help` for more details. +*WARNING*: These commands will irrevocably overwrite all data on the target storage device! Be absolutely certain that the device path is correct before starting. Your data will not be recoverable. +### Linux -# Linux example - -The following disktest invocation will write a secure sequence to the disk device `/dev/sdc` and subsequently read back and verify the sequence. +Write a secure pseudo-random sequence to the disk and immediately verify it: ```sh +# For a standard block device disktest --write --verify -j0 /dev/sdc -``` -For NVMe: - -```sh +# For an NVMe drive disktest --write --verify -j0 /dev/nvme0n1 -``` - -For SD / MMC: -```sh +# For an SD / MMC card disktest --write --verify -j0 /dev/mmcblk0 ``` +*(Note: You usually need `root` permissions to write to raw disk devices).* -*WARNING*: This will irrevocably overwrite all data on the storage device! Be absolutely certain that the device path is correct before starting the command. Your data will not be recoverable. - -You probably need `root` permissions to write to raw disk devices (`/dev/sdX`, `/dev/nvmeXn1` or `/dev/mmcblkX`). +### Windows -The target `device` does not have to be an actual hardware device node. It can be any file path on any file system. For example you can mount an USB stick file system and write to a file on that file system. However, please note that this leaves a couple of minor untested spots in the USB stick's memory, which are reserved for the file system. Also see the `Windows` section below. - - -# Windows example - -On Windows disktest can write to any file on any mounted storage media or raw disks. - -If your storage media under test is drive E, then the following command would write a test file on drive E and verify it: +Write a test file to a mounted drive `E:` and verify it: ```cmd disktest --write --verify -j0 E:\testfile.img ``` +*(See the [Detailed Usage](#detailed-usage) section for testing raw drives on Windows).* -But note that testing on the filesystem level, as shown above, does not test the full device. -It will omit the disk areas that the filesystem uses internally. -Therefore, you may want to write to the raw disk E using the Windows raw drive notation, as follows: - -```cmd -disktest --write --verify -j0 \\.\E: -``` +--- -or +## Installation -```cmd -disktest --write --verify -j0 \\.\PhysicalDrive2 +### From crates.io (Recommended) +Download the latest version of disktest and install it to `$HOME/.cargo/bin`: +```sh +cargo install disktest ``` -Doing so will completely wipe all data (including the filesystem) on this disk. - -Always make sure that you selected the correct drive. -Especially in the `\\\\.\PhysicalDriveX` notation, it is extremely easy to overwrite the wrong drive by accident. -Therefore, the `\\\\.\X:` (where X is the drive letter) notation is preferred. - +### From Source +Build and install from the source package: +```sh +cd path/to/source/package +cargo install --path . +``` +Or run in-place without installing: +```sh +cargo run --release -- DISKTEST_OPTIONS_HERE +``` -# Dependencies +--- -- [Rust 1.85.0](https://www.rust-lang.org/) or later. -- Crate dependencies are automatically downloaded by Cargo. +## Detailed Usage +The target `device` does not have to be an actual hardware device node. It can be any file path on any file system. However, testing on the filesystem level leaves minor spots untested (those reserved for the filesystem itself). To test the *entire* device, you must target the raw device. -# Installing from crates.io +### Windows Raw Drives +To test an entire drive on Windows, use the raw drive notation. The `\\.\X:` (where X is the drive letter) notation is preferred to avoid accidental overwrites: -Download the latest version of disktest from [crates.io](https://crates.io/) and install it to `$HOME/.cargo/bin`: +```cmd +disktest --write --verify -j0 \\.\E: +``` +Alternatively: +```cmd +disktest --write --verify -j0 \\.\PhysicalDrive2 +``` +### Command Line Options +To see all available command-line options: ```sh -cargo install disktest +disktest --help +# or if running from source: cargo run --release -- --help ``` +### Power Cycle Tests -# Installing from source package - -Build disktest and install it to `$HOME/.cargo/bin`: +It is recommended to test a device's data retention capabilities in a powered-down state. You can achieve this by splitting the write and verify passes. Note that you **must** supply the same `--seed` for both runs, so `disktest` knows the exact pseudo-random sequence to expect during verification. +**1. Write the sequence:** ```sh -cd path/to/source/package -cargo install --path . +disktest --write --seed -j0 /dev/sdc ``` +**2. Safely remove and power down:** +Safely unmount/eject the device, and physically unplug it. -# Running from source package without installing - -Build and run disktest in place without installing it: - +**3. Reconnect and verify:** ```sh -cd path/to/source/package -cargo run --release -- DISKTEST_OPTIONS_HERE +disktest --verify --seed -j0 /dev/sdc ``` -See below for a description of the available `disktest` options. - +--- -# Disktest command line options +## Security & Algorithm -Please run either of the following commands to show more information about the available command-line options. - -```sh -cargo run --release -- --help -disktest --help +Disktest writes a pseudo-random sequence, reads it back, and verifies it. The stream is generated by: +``` +OUTPUT_DATA := CHACHA20(PBKDF2(SEED | THREAD_ID | ROUND_ID)) ``` +If more than one thread is used, each thread generates a stream, and they are interleaved in an alternating pattern. +The default algorithm [ChaCha20](https://en.wikipedia.org/wiki/Salsa20) is a cryptographically strong random number generator. If the seed is kept secret, the sequence cannot be predicted or reconstructed by anybody else. See `--seed` in the `--help` output for more details. -# Speed +--- -The following table shows some example speed measurements of disktest in various operation modes on different hardware. +## Speed Measurements -These speed tests don't write to an actual disk, but only to the `/dev/null` device, which is a device that does nothing. So these speed test results do not include the speed limits of any physical disk hardware. +The following table shows example speed measurements using different algorithms and hardware. -| Command | Algorithm | Hardware | Data rate written | -| ------------------------------------- | --------- | ------------------------------- | ----------------- | -| disktest -j12 -ACHACHA20 -w /dev/null | ChaCha20 | AMD Ryzen 5 5500U; 6x2 cores | 8.4 GiB/s | -| disktest -j12 -ACHACHA12 -w /dev/null | ChaCha12 | AMD Ryzen 5 5500U; 6x2 cores | 8.7 GiB/s | -| disktest -j12 -ACHACHA8 -w /dev/null | ChaCha8 | AMD Ryzen 5 5500U; 6x2 cores | 8.7 GiB/s | -| disktest -j12 -ACRC -w /dev/null | CRC | AMD Ryzen 5 5500U; 6x2 cores | 8.8 GiB/s | -| disktest -j4 -ACHACHA20 -w /dev/null | ChaCha20 | Intel i5-3320M; 2x2 cores | 2.1 GiB/s | -| disktest -j4 -ACHACHA12 -w /dev/null | ChaCha12 | Intel i5-3320M; 2x2 cores | 3.3 GiB/s | -| disktest -j4 -ACHACHA8 -w /dev/null | ChaCha8 | Intel i5-3320M; 2x2 cores | 4.5 GiB/s | -| disktest -j4 -ACRC -w /dev/null | CRC | Intel i5-3320M; 2x2 cores | 8.2 GiB/s | -| disktest -j4 -ACHACHA20 -w /dev/null | ChaCha20 | Raspberry Pi 4; 4 cores 1.5 GHz | 455 MiB/s | -| disktest -j4 -ACHACHA12 -w /dev/null | ChaCha12 | Raspberry Pi 4; 4 cores 1.5 GHz | 720 MiB/s | -| disktest -j4 -ACHACHA8 -w /dev/null | ChaCha8 | Raspberry Pi 4; 4 cores 1.5 GHz | 990 MiB/s | -| disktest -j4 -ACRC -w /dev/null | CRC | Raspberry Pi 4; 4 cores 1.5 GHz | 3.1 GiB/s | +| Algorithm | Hardware | Threads (`-j`) | Data rate written | +| --------- | ------------------------------- | -------------- | ----------------- | +| ChaCha20 | AMD Ryzen 5 5500U; 6x2 cores | 12 | 8.4 GiB/s | +| ChaCha12 | AMD Ryzen 5 5500U; 6x2 cores | 12 | 8.7 GiB/s | +| ChaCha8 | AMD Ryzen 5 5500U; 6x2 cores | 12 | 8.7 GiB/s | +| CRC | AMD Ryzen 5 5500U; 6x2 cores | 12 | 8.8 GiB/s | +| ChaCha20 | Intel i5-3320M; 2x2 cores | 4 | 2.1 GiB/s | +| ChaCha12 | Intel i5-3320M; 2x2 cores | 4 | 3.3 GiB/s | +| ChaCha8 | Intel i5-3320M; 2x2 cores | 4 | 4.5 GiB/s | +| CRC | Intel i5-3320M; 2x2 cores | 4 | 8.2 GiB/s | +| ChaCha20 | Raspberry Pi 4; 4 cores 1.5 GHz | 4 | 455 MiB/s | +| ChaCha12 | Raspberry Pi 4; 4 cores 1.5 GHz | 4 | 720 MiB/s | +| ChaCha8 | Raspberry Pi 4; 4 cores 1.5 GHz | 4 | 990 MiB/s | +| CRC | Raspberry Pi 4; 4 cores 1.5 GHz | 4 | 3.1 GiB/s | -The read data rates are similar because the algorithm used is exactly the same. +To reproduce these metrics, use the following command format: +```sh +disktest -j -A -w /dev/null +``` + +* Tests were performed writing to `/dev/null` to measure raw generation speed, independent of physical disk bottlenecks. +* Read data rates are similar as the generation algorithm is identical. +--- -# CPU native optimization +## Build Notes & Dependencies -Note that the default [cargo configuration](.cargo/config.toml) supplied with this package sets the Rust compiler option `-Ctarget-cpu=native` to optimize for the best performance on your CPU. +- Requires **[Rust 1.85.0](https://www.rust-lang.org/) or later**. +- Crate dependencies are automatically downloaded by Cargo. -But this means that binaries compiled with this optimizations are non-portable to older CPUs. -If you want portable binaries, then you probably want to remove this optimization option. +### CPU Native Optimization +The default [cargo configuration](.cargo/config.toml) supplied with this package sets the Rust compiler option `-Ctarget-cpu=native` to optimize for the best performance on your CPU. This means compiled binaries are non-portable to older CPUs. Remove this optimization option if you need portable binaries. +--- -# License +## License Copyright (c) 2020-2026 Michael Büsch and contributors