Skip to content

Instantly share code, notes, and snippets.

@macmladen
Forked from joeblau/OSX Secure Disk Wipe.md
Last active July 6, 2019 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macmladen/7e554dd647551bbbde56426e8dade80e to your computer and use it in GitHub Desktop.
Save macmladen/7e554dd647551bbbde56426e8dade80e to your computer and use it in GitHub Desktop.
Securely erase an external disk using dd on OSX

Securely erase an external disk using dd on OSX

  1. Plug in your SD card, HDD, or other block device and then use the following command to see which /dev/diskN node it's located on:
diskutil list
  1. Unmount the disk where N is the number of the disk taken from the above command:
diskutil unmountDisk /dev/diskN

If the above command was successful, you will see:

Unmount of all volumes on diskN was successful

  1. Execute dd command as super user on disk where "N" is the number of the disk from step 1.
sudo dd if=/dev/urandom of=/dev/rdiskN bs=1m

This will overwrite all partitions, master boot records, and data.

Please note that this may take a while depending on the size and speed of your disk and there is no progress indicator. However, if you want to check progress, on Mac you can use CTRL + T.

This is equivalent to

sudo diskutil zeroDisk /dev/rdiskN.

If you want true secure erase then use:

diskutil secureErase [freespace] level MountPoint|DiskIdentifier|DeviceNode

Securely erases either a whole disk or a volume's freespace.

Level should be one of the following:

    0 - Single-pass zeros.
    1 - Single-pass random numbers.
    2 - US DoD 7-pass secure erase.
    3 - Gutmann algorithm 35-pass secure erase.
    4 - US DoE 3-pass secure erase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment