Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Use it like
- # wipe-drive-quick <device-path>
- # wipe-drive-quick /dev/sda1
- wipe-drive-quick(){
- # This is the device that will be zeroed
- device_path="$1"
- block_size=512
- # 512 * 2048 = 1048576 bytes = 1.05 MB
- # This will wipe 1MB
- # how_much_to_wipe=2048
- # 512 * (2048 * 10) = 512 * 20480 = 10.4 MB
- # This will wipe 10MB
- how_much_to_wipe=20480
- # If path is a block device or a file then
- if [[ -b "$device_path" || -f "$device_path" ]]; then
- # Getting the size of the device in the number of sectors
- # Total size of the device in bytes is is $divice_size * $block_size
- device_size="`blockdev --getsz $device_path`"
- seek_amount="$((device_size - how_much_to_wipe))"
- echo -e "\n"
- echo "The device to be wiped is:"
- echo "$device_path"
- echo "`lsblk -pf | grep $device_path`"
- echo -e "\n"
- echo "Will run the following command to wipe the first part of the device:"
- echo sudo dd bs="$block_size" if=/dev/zero of="$device_path" count="$how_much_to_wipe"
- echo -e "\n"
- echo "Will run the following command to wipe the last part of the device:"
- echo sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe seek="$seek_amount"
- echo -e "\n"
- echo "Please check the commands above and make sure that this is what you want to do."
- echo -e "Choosing continue will execute them.\n"
- # Uncomment this if you use BASH and comment if you don't
- read -r -p "Continue (y/N)?" choice
- # Comment this if you use BASH, and uncomment if you use ZSH
- # read "choice?Continue (y/N)?"
- if [[ "$choice" =~ ^(Y|y) ]]; then
- echo -e "\n"
- echo "Wiping first part of the device:"
- sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe
- echo -e "\n"
- echo "Wiping last part of the device:"
- sudo dd bs="$block_size" if=/dev/zero of="$device_path" count=$how_much_to_wipe seek="$seek_amount"
- else
- echo "Not executing commands, because you chose 'No'."
- fi
- else
- echo "The path \`$device_path\` is not a block device or a file."
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement