Skip to content

Instantly share code, notes, and snippets.

@ProBackup-nl
Last active February 11, 2021 22:44
Show Gist options
  • Save ProBackup-nl/949d34d51678fb0d77fcbcb8b60924f5 to your computer and use it in GitHub Desktop.
Save ProBackup-nl/949d34d51678fb0d77fcbcb8b60924f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script that runs a write endurance torture test, intended to measure SD card endurance.
# Like "Anvil's Storage Utilities" endurance test for command line Linux
# Check if running as root
if [[ "$(id -u)" -ne 0 ]]; then
echo "ERROR: Must be run as root" >&2
exit 2
fi
# Check required dependencies
readonly DEPENDENCIES='badblocks'
for dependency in ${DEPENDENCIES}; do
if ! command -v "${dependency}" > /dev/null 2>&1; then
echo "ERROR: Command '${dependency}' not found" >&2
exit 2
fi
done
COUNT_FILE="$HOME/.endurancecounter"
if [[ -s $COUNT_FILE ]]; then
read COUNT < "$COUNT_FILE"
fi
if echo "$COUNT" | grep '[^0-9]' > /dev/null; then
echo >&2 "$0: ERROR: non-integer counter found in $COUNT_FILE."
exit 1
elif [[ -z $COUNT ]]; then
COUNT=1
fi
# 20TBW / 32GB = 640 cycles
for (( ; COUNT < 641; COUNT++ ))
do
echo "Run: $COUNT"
badblocks -b 4096 -c 4096 -t random -e 1 -v -s -w /dev/sda
if [[ $? != 0 ]]; then exit 2
fi
# maybe it's better to increase the randomness of the data written
# head -c 1G </dev/urandom >myfile
# head -c 1G </dev/hwrng >myfile
echo $(( COUNT )) > "$COUNT_FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment