Created
May 10, 2017 23:26
-
-
Save gronke/aa6729c9cf715209b9de2cd248db4cfc to your computer and use it in GitHub Desktop.
Format a disk with pseudo-randon data using /dev/null encrypted with a random number
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
#!/bin/sh | |
# Format a disk with pseudo-randon data using /dev/null encrypted with a random number | |
# Dependencies | |
# - base64 | |
# - openssl | |
# - pv | |
DISK="$1" | |
UNAME=$(uname) | |
if [ "$(uname)" == "FreeBSD" ]; then | |
DISKSIZE=$(diskinfo -v "$DISK" | grep "mediasize in bytes" | awk '{ print $1 }') | |
fi | |
# Linux | |
if [ "$(uname)" == "Liunx" ]; then | |
DISKSIZE=fdisk -l "$DISK" | head -n1 | awk '{ print $5 }' | |
fi | |
# User Confirmation | |
echo -n "The disk $DISK ($DISKSIZE bytes) will be deleted. Please enter uppercase YES to continue: " | |
read user_confirmed | |
if [ "$user_confirmed" != "YES" ]; then | |
echo "aborted. exiting" | |
exit 0; | |
fi | |
openssl enc \ | |
-nosalt \ | |
-aes-256-ctr \ | |
-pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" \ | |
< /dev/zero | | |
pv --progress --eta --rate --bytes --size "$DISKSIZE" | | |
dd of="$DISK" bs=2048 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment