Advertisement
killermist

wipe.sh

Nov 30th, 2017
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. #!/bin/bash
  2. ## Some commands and/or syntax are targeted for FreeBSD and more
  3. ## precisely NAS4Free 9.2.*.* series.
  4. ## The script will probably fail if used in Linux or more limited
  5. ## FreeBSD environments.
  6. ## You have been warned.
  7. ##
  8. ## The purpose of the script is to zero out the first and last 4Mb
  9. ## of the disk targeted for disks reporting 512byte sector-size.
  10. ## For disks that actually report a 4k sector size, it will wipe
  11. ## out the first and last 32Mb.
  12. ## Many disks still false-report a 512byte sector when they are in
  13. ## fact 4k drives, due to backwards (and isn't it always)
  14. ## compatibility with windows.
  15. ## The purpose is to wipe out the MBR and GPT partition tables and
  16. ## ZFS fingerprints that may exist on a drive.
  17. ## Ever have a drive with a single ZFS pool, but "zpool import"
  18. ## shows three or more possible pools to try to import from the
  19. ## drive (due to reuse/testing)?  I have.
  20. ## After using this, the drive will appear to be blank.  It isn't.
  21. ## But plugging the drive into windows, Linux, FreeBSD, or Android,
  22. ## it will appear to be, and can be partitioned and formatted for
  23. ## use as you see fit.  Of course forensic scans of the disk would
  24. ## still return data from the previous usage, but for home users
  25. ## this simplifies readying the disk for use in a different
  26. ## capacity than previous.
  27. ##
  28. echo "What disk do you want"
  29. echo "to wipe? For example - ada1 :"
  30. read disk
  31. echo "OK, in 10 seconds I will destroy all data on $disk!"
  32. echo "Press CTRL+C to abort!"
  33. sleep 10
  34. diskinfo ${disk} | while read disk sectorsize size sectors other
  35. do
  36.     echo Deleting MBR, GPT Primary, ZFS(L0L1)/other partition tables.
  37.     /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} count=8196
  38.     echo Deleting GEOM metadata, GPT Secondary(L2L3).
  39.     /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} oseek=$(expr $sectors - 8196) count=8196
  40. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement