Created
September 3, 2021 13:20
-
-
Save Artefact2/f3fbcb89044614600249dd04f29dc322 to your computer and use it in GitHub Desktop.
test against fake flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
if test $# -ne 1; then | |
echo "Tests against fake capacity flash storage. Script should print two identical checksums." | |
echo "Usage: $0 /dev/sdX" >&2 | |
exit 1 | |
fi | |
parallel --version >/dev/null 2>&1 || exit 1 | |
hexdump --version >/dev/null 2>&1 || exit 1 | |
xxh64sum --version >/dev/null 2>&1 || exit 1 | |
KNAME=$(realpath $1 | rev | cut -d/ -f1 | rev) | |
cat /sys/block/$KNAME/size >/dev/null || exit 1 | |
SIZE=$(cat /sys/block/$KNAME/size) | |
if test ! -w /dev/$KNAME; then | |
echo "Device $KNAME not writeable. Are you root?" >&2 | |
exit 1 | |
fi | |
echo "Testing device $KNAME, $SIZE sectors." | |
echo "Will irreparably remove all the data from the device! Hit Control-C in the next ten seconds to abort the operation." | |
for x in {10..1}; do | |
echo -n "$x... " | |
sleep 1 | |
done | |
echo | |
fastrand() { | |
parallel -q --ungroup -n1 -j2 sh -c 'openssl enc -aes-128-ctr -K '{}' -iv 00000000000000000000000000000000 < /dev/zero' ::: $(hexdump -n 16 -e '8/1 "%02x"' /dev/urandom) $(hexdump -n 16 -e '8/1 "%02x"' /dev/urandom) 2>/dev/null | |
} | |
fastrand | head -c$(( 512*$SIZE )) | tee >(xxh64sum) | dd of=/dev/$KNAME bs=4M iflag=fullblock oflag=direct status=progress | |
dd if=/dev/$KNAME bs=4M iflag=direct status=progress | xxh64sum | |
echo "If the two checksums match, your drive is OK." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment