Created
June 19, 2015 07:58
-
-
Save andrey-malets/594b3a160620c8536275 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 bash | |
set -e -o pipefail | |
dev=${1:?usage: $0 <device name>} | |
dir="/sys/block/$dev" | |
if ! [[ -d "$dir" ]]; then | |
echo "$dev probably is not a block device (no $dir)" >&2 | |
exit 1 | |
fi | |
if ! [[ -b "/dev/$dev" ]]; then | |
echo "$dev probably is not a block device (no /dev/$dev)" >&2 | |
exit 1 | |
fi | |
dev="/dev/$dev" | |
sectors=$(cat "$dir/size") | |
bsize=$((64 * 1024 * 1024)) | |
blocks=$((sectors * 512 / $bsize)) | |
dd=(dd "bs=$bsize" "count=$blocks" iflag=fullblock) | |
for pass in {1..3}; do | |
key="key$RANDOM" | |
enc=(openssl enc -aes-128-ctr -pass "pass:$key" -nosalt) | |
"${dd[@]}" if=/dev/zero | "${enc[@]}" | "${dd[@]}" "of=$dev" | |
sync; echo 3 > /proc/sys/vm/drop_caches | |
cmp <("${dd[@]}" if=/dev/zero | "${enc[@]}") <("${dd[@]}" "if=$dev") | |
done | |
dd if=/dev/zero of="$dev" bs=1M count=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment