SHARE
TWEET

Untitled

a guest Feb 25th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # Use it like
  3. # wipe-drive-quick <device-path>
  4. # wipe-drive-quick /dev/sda1
  5. wipe-drive-quick(){
  6.  
  7.   # This is the device that will be zeroed
  8.   device_path="$1"
  9.   block_size=512
  10.  
  11.   # 512 * 2048 = 1048576 bytes = 1.05 MB
  12.   # This will wipe 1MB
  13.   # how_much_to_wipe=2048
  14.   # 512 * (2048 * 10) = 512 * 20480 = 10.4 MB
  15.   # This will wipe 10MB
  16.   how_much_to_wipe=20480
  17.  
  18.   # If path is a block device or a file then
  19.   if [[ -b "$device_path" || -f "$device_path" ]]; then
  20.  
  21.     # Getting the size of the device in the number of sectors
  22.     # Total size of the device in bytes is is $divice_size * $block_size
  23.     device_size="`blockdev --getsz $device_path`"
  24.     seek_amount="$((device_size - how_much_to_wipe))"
  25.  
  26.     echo -e "\n"
  27.     echo "The device to be wiped is:"
  28.     echo   "$device_path"
  29.     echo   "`lsblk -pf | grep $device_path`"
  30.  
  31.     echo -e "\n"
  32.     echo "Will run the following command to wipe the first part of the device:"
  33.     echo sudo dd bs="$block_size" if=/dev/zero of="$device_path" count="$how_much_to_wipe"
  34.     echo -e "\n"
  35.  
  36.     echo "Will run the following command to wipe the last part of the device:"
  37.     echo sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe seek="$seek_amount"
  38.     echo -e "\n"
  39.  
  40.     echo "Please check the commands above and make sure that this is what you want to do."
  41.     echo -e "Choosing continue will execute them.\n"
  42.  
  43.     # Uncomment this if you use BASH and comment if you don't
  44.     read -r -p "Continue (y/N)?" choice
  45.     # Comment this if you use BASH, and uncomment if you use ZSH
  46.     # read "choice?Continue (y/N)?"
  47.  
  48.     if [[ "$choice" =~ ^(Y|y) ]]; then
  49.       echo -e "\n"
  50.       echo "Wiping first part of the device:"
  51.       sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe
  52.       echo -e "\n"
  53.       echo "Wiping last part of the device:"
  54.       sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe seek="$seek_amount"
  55.     else
  56.       echo "Not executing commands, because you chose 'No'."
  57.     fi
  58.   else
  59.     echo "The path \`$device_path\` is not a block device or a file."
  60.   fi
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top