Skip to content

Instantly share code, notes, and snippets.

@someuser89
Created May 27, 2016 13:18
Show Gist options
  • Save someuser89/fe8f22245723c70be0f60d1cb3bdd1b1 to your computer and use it in GitHub Desktop.
Save someuser89/fe8f22245723c70be0f60d1cb3bdd1b1 to your computer and use it in GitHub Desktop.
#!/bin/sh
which openssl > /dev/null || exit 1
which pv > /dev/null || exit 1
which sudo > /dev/null || exit 1
test -n "$1" || exit 2
disk="$1"
test -b "/dev/$disk" || exit 2
size=$(awk "\$4==\"$disk\"{print \$3}" /proc/partitions) || exit 3
size=$(($size*1024))
nice openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2> /dev/null | base64)" -nosalt < /dev/zero | pv --progress --eta --rate --bytes --size "$size" | sudo dd of="/dev/$disk" bs=4096 || exit 4
@someuser89
Copy link
Author

!/bin/sh

which openssl > /dev/null || exit 1
which pv > /dev/null || exit 1
which sudo > /dev/null || exit 1

test -n "$1" || exit 2
disk="$1"

test -b "/dev/$disk" || exit 2

size=$(awk "$4=="$disk"{print $3}" /proc/partitions) || exit 3
size=$(($size*1024))

{
while true; do
#1 GiB
dd if=/dev/zero bs=512 count=2076672 2> /dev/null | nice openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2> /dev/null | base64)" -nosalt
done
} | pv --progress --eta --rate --bytes --size "$size" | sudo dd of="/dev/$disk" bs=4096 2> /dev/null || exit 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment