Last active
September 4, 2020 12:00
-
-
Save insanity54/98fc4431cbc0be6f91a98c7a6d9ede04 to your computer and use it in GitHub Desktop.
Erase a disk using dd - An alternative to DBAN
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
#!/bin/bash | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
warn='!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
echo -e "$warn\n$warn\n$warn" | |
echo " WARNING" | |
echo " Destructive disk wiping is about to take place " | |
echo "" | |
echo "" | |
echo " enter the disk device you want to erase." | |
echo " example: /dev/sdd" | |
echo "" | |
echo " Press Ctrl+C to cancel" | |
echo "" | |
printf " Erase device : " | |
read device | |
[[ $device =~ ^/dev/.+$ ]] && match=1 || match=0 | |
if [[ "$match" -eq 0 ]]; then | |
echo "Invalid device entered. Exiting." | |
exit 1 | |
fi | |
echo "Erasing disk $device. Press enter to continue or Ctrl+C to cancel." | |
read fart | |
disksize=$(blockdev --getsize64 $device) | |
# greets http://stackoverflow.com/a/806923/4071859 | |
re='^[0-9]+$' | |
if ! [[ $disksize =~ $re ]] ; then | |
echo "error: blockdev could not get size of disk. try running dd manually." >&2; | |
exit 1 | |
fi | |
# DESTROY! DESTROY! DESTROY! | |
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | pv -bartpes $disksize | dd bs=64K of=$device | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better alternative discovered! nwipe.
sudo apt-get -y install nwipe && nwipe