Skip to content

tool to completely fill a drive with random data and ensure it can be entirely correctly read back

Notifications You must be signed in to change notification settings

rentzsch/stressdrive

Repository files navigation

About

stressdrive is a macOS and Linux command-line tool meant to verify correct operation of a drive. It does so by filling a drive up with random data and ensuring all the data can be correctly read back.

It was written to verify correct operation of de-duping SSDs, but it can be used with normal HDDs or any rewritable block storage device.

DANGER: stressdrive will overwrite, without warning, all data on the given drive. Be sure to double-check the drive you're aiming it at (diskutil list or Disk Utility.app > Select Drive > Info > Disk Identifier).

Usage

sudo ./stressdrive /dev/rdiskN

Run Only Against Entire, Unmounted, Physical Devices

stressdrive should always be run against entire unmounted physical devices.

Practically: your device path should always be in the form of /dev/rdiskX (not /dev/rdiskXsX). stressdrive's results can only be trusted if it was allowed to fill the entire device to the device's advertised information-theoretic maximum.

Imagine pointing stressdrive at just a logical partition. If the drive failed during the test it's possible to get back a clean read of the random data just written, while a block outside the device's partition is no longer correct. That would not be an accurate test result.

Sample Run

Here's stressdrive running against a 2 GB USB Flash drive:

$ sudo ./stressdrive /dev/rdisk999
Password:
disk block size: 512
disk block count: 3948424
buffer size: 8388608
succesfully created no idle assertion
writing random data to /dev/rdisk999
writing 100.0% (3948424 of 3948424) 00:03:54
6519594c7bf64d5e4e087cfbc5ba6324d25e8c0d <= SHA-1 of written data
verifying written data
reading 100.0% (3948424 of 3948424) 00:01:24
6519594c7bf64d5e4e087cfbc5ba6324d25e8c0d <= SHA-1 of read data
SUCCESS
succesfully released no idle assertion

Installing

macOS

using macports

This will probably need sudo:

port install stressdrive

Building

macOS

using homebrew

First, you'll need OpenSSL, which you should install via homebrew:

brew install openssl

Then you can just:

xcodebuild

Or compile it directly:

gcc stressdrive.c -o stressdrive -lcrypto -framework IOKit -framework CoreServices -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

using macports

Same commands for macports:

port install openssl

xcodebuild PREFIX=/opt/local SEARCH_PREFIX=/opt/local

gcc stressdrive.c -o stressdrive -lcrypto -framework IOKit -framework CoreServices -I/opt/local/include -L/opt/local/lib

Ubuntu

sudo apt-get install libssl-dev # You will need openssl headers

gcc stressdrive.c -o stressdrive -std=c99 -lcrypto

FAQ

"How is this better than Disk Utility's 'Zero Out Data'?"

Some SSD's de-duplicate stored blocks. For these "filling" it with zeros if actually just modifying one or two actual mapping blocks over and over again. It's not a real test of the SSD's hardware.

"How is this better than Disk Utility's '7-Pass Erase'?"

stressdrive only overwrites the drive with data once (so it's 7x faster) and then verifies all the data is correctly read back (which Disk Utility doesn't do at all).

Jens Ayton informs me 7-Pass Erase uses fixed patterns, so de-duping may be an issue there as well.

"Pshaw! I could do this with dd, /dev/random & shasum!"

Indeed you could. I prefer a minimal focused tool whose operation is fixed, its source simple+readable and offers good built-in progress reporting.

When I list my disks I do not see "rdiskX", I only see "diskX"

When you list the disks on your computer you are shown the Block Devices. When you access Block Devices via "diskX", reads and writes are buffered through the OS.

Unix systems also allow direct and unbuffered access to the Raw Devices using the format "rdiskX". stressdrive requires raw access to ensure fast, precise, and predictable disk operations.

Once you've identified the top-level (physical, not synthesized) drive identifier that looks like 'diskX', simply add an 'r' for use by the app. For example, if your diskutil list shows /dev/disk4 as your target, use /dev/rdisk4 in your command.

Version History

v1.4: 2023-11-23 download

  • [NEW] Store a checksum every 1GB, allowing faster reporting of drive failure. It requires 20 bytes per gigabyte, so 80K for a 4TB drive. (Ivan Kuchin)

  • [NEW] Apply an exclusive advisory lock on device after opening, making running two instances on the same drive impossible (Ivan Kuchin)

  • [DOC] Add instructions for installing using macports (Ivan Kuchin)

  • [FIX] Include sys/file.h missing at least on ubuntu (Ivan Kuchin)

  • [FIX] Upgrade checkCount to uint64_t to avoid precision loss warning (rentzsch)

  • [DEV] Refactor xcode project to allow different prefix, update instructions for macOS (Ivan Kuchin)

  • [DEV] Mention sleep in idle assertion message and variable name (Ivan Kuchin)

  • [FIX] Xcode v12.5, Homebrew on Apple Silicon (rentzsch)

  • [DEV] Xcode 15 bottoms out at 10.13 as a minimum deployment target (rentzsch)

  • [DOC] Use archive.org link for 404 storagemojo.com article (rentzsch)

v1.3.2: 2020-07-05 download

  • [CHANGE] Target oldest supported macOS (10.6). (rentzsch)

v1.3.1: 2020-07-04 download

v1.3: 2018-02-19

  • [NEW] Display speed alongside progress. (Ivan Kuchin)

v1.2.1: 2018-01-04 download

  • [FIX] Statically link libcrypto. (rentzsch)

v1.2: 2018-01-03 download

  • [NEW] Linux support. (Ivan Kuchin)
  • [NEW] Better progress display: elapsed time and ETA. (Ivan Kuchin)
  • [NEW] Use AES 128 CBC with a random key and initialization vector as a much faster source of data sans fixed patterns. (Ivan Kuchin)
  • [NEW] Don't allow the Mac to idle (sleep) while running. (Ivan Kuchin)
  • [NEW] Print version alongside usage. (rentzsch)
  • [CHANGE] Remove speed scaling in favor of a simpler and as fast fixed 8MB copy buffer. (Ivan Kuchin)
  • [FIX] Possible overflow in speedscale. (Doug Russell)
  • [FIX] Xcode project references Homebrew's OpenSSL in a non-version-specific way (so it doesn't break on every update). (rentzsch)

v1.1: 2011-11-17 download

  • [NEW] Speed scaling, which increases the copy buffer to the maximum that's still evenly divisible by the drive's capacity. (rentzsch)

v1.0: 2011-11-16 download

  • Initial release.

About

tool to completely fill a drive with random data and ensure it can be entirely correctly read back

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages