Git Product home page Git Product logo

stressdrive's Introduction

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.

stressdrive's People

Contributors

aaronmergerequest avatar boredzo avatar everythingsolution avatar rentzsch avatar thunfischbrot avatar toy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

stressdrive's Issues

Add an FAQ explaining 'rdisk' for slightly less technical users

I would have submitted this via the more normal GIT channels but I think this needs editing for accuracy and clarity. Basically, I don't think the concept of "rdisk" is known widely enough to not to confuse some users of this software.

You might consider adding something along these lines to the FAQ section:

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

When you access a disk on your system via "diskX" the OS manages the reads and writes which can include the use of buffers as well as other data management techniques that could cause certain sectors to be used more than others.

Unix systems also allow "raw" access to write data directly to the disk using the format "rdiskX". stressdrive requires raw access to ensure full and controlled reads and writes to the storage modules on SSDs.

Once you've identified the top-level (physical, not synthesized) drive identifier '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.

Compilation warnings

On Xcode 8:

stressdrive.c:178:64: Implicit conversion loses integer precision: 'unsigned long long' to 'uint32_t' (aka 'unsigned int')

stressdrive.c:213:64: Implicit conversion loses integer precision: 'unsigned long long' to 'uint32_t' (aka 'unsigned int')

Failure when partition mounted

I ran the program against an external usb drive with the partition mounted at first and got a failure. Then, immediately afterwards I unmounted the partition and ran again then got a success. Is this to be expected?

With partition mounted:

$ sudo ./stressdrive /dev/rdisk1s2
disk block size: 512
disk block count: 155629664
buffer size: 8388608
succesfully created no idle assertion
writing random data to /dev/rdisk1s2
writing 100.0% (155629664 of 155629664) 00:50:18
656829fb4f79cb1bef8d385cef0ddea3823fcfd6 <= SHA-1 of written data
verifying written data
reading 100.0% (155629664 of 155629664) 00:41:28
0077823543e6e416847c36d120c7dbb03416a01c <= SHA-1 of read data
FAILURE
succesfully released no idle assertion

With partition unmounted:

$ sudo ./stressdrive /dev/rdisk1s2
Password:
disk block size: 512
disk block count: 155629664
buffer size: 8388608
succesfully created no idle assertion
writing random data to /dev/rdisk1s2
writing 100.0% (155629664 of 155629664) 00:50:16
5df635c6cbf3ed0fb9ae6db1f05cfff75adbf605 <= SHA-1 of written data
verifying written data
reading 100.0% (155629664 of 155629664) 00:41:27
5df635c6cbf3ed0fb9ae6db1f05cfff75adbf605 <= SHA-1 of read data
SUCCESS
succesfully released no idle assertion

Open to publishing on brew?

Firstly, thanks for stressdrive, it's really useful to be able to test a whole hard drive.

I saw the install instructions of port install stressdrive. I already have brew installed, and I see brew install ... as one of the recommendations to get openssl. I wonder if you're up for publishing to brew?

I have helped a few other projects publish to brew, and so I know a little about the process. I'd be happy to lend a hand if that's helpful.

Checkpoint checks

For large drives, determining the full checksum can take several hours (ie: 40h in my external 4Tb drive).

It would be nice to set an interval for checking integrity at every X Gb, where X is a command line option, so that problems can be identified earlier even if overall time might increase.

New release

Could you please release new version/tag with already merged changes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.