Skip to content

Instantly share code, notes, and snippets.

@imrehg
Created June 3, 2016 09:40
Show Gist options
  • Save imrehg/ea89be2ab55183120c0151a70bb1e3f9 to your computer and use it in GitHub Desktop.
Save imrehg/ea89be2ab55183120c0151a70bb1e3f9 to your computer and use it in GitHub Desktop.
Disk eraser script
#!/bin/bash
# From http://unix.stackexchange.com/questions/72216/fast-way-to-randomize-hd
DISK="/dev/sda"
SIZE=`fdisk -l | grep "${DISK}" | awk '{print $5}'`
echo "Erasing ${DISK} (size ${SIZE} bytes)"
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "OOOh!"
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} \
| dd of=${DISK} bs=2M
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment