Home How to's

How To Erase Disk In Linux And Mac Using Simple Commands?

SHARE

The best way to move forward is to erase the drive. Many tools can reliably secure-erase drives, albeit painfully slowly. If that’s not what you need, what do you do when your normal drive tools are still behaving wonky? To erase drives with ease and speed, you need to go back to the basics.

NOTE: SSDs require much more care when erasing. Because of the compression techniques used inside SSDs, zeroing-out a drive (writing only zeros) will produce a drive that looks like it has been wiped, but has not been wiped. Read the manual for your SSD if you need to securely wipe it, chances are, the manufacturer has provided a tool or very specific instructions.

Erasing disk in Linux and OS X using dd command

The first tool, and arguably one of the most important to erase disk in Linux and Mac, is dd(Windows versions are available, but the use is slightly different)dd command for wiping drive is like a data scalpel. It allows you to cut out pieces of data in precisely the size you want from precisely where you wanted it, and then place it where you want it, all while providing a bunch of different options. Its syntax is archaic but simple.

Here we use four flags:

  • if – This is the input file, we’ve used /dev/zero to produce zero or null bytes.
  • of – This is the output file, our disk.
  • bs – This is the block size (not super important in most cases).
  • count – This is the number of blocks that we copy.
Also Read:  How to Hack Any Game On Your Android Smartphone (2017)

The above command will copy one megabyte of zeros to the disk. That would erase the partition table of the drive and allow a partitioning program to create the table and some partitions.

Alright, what if you want to securely erase an entire drive? Well, you can still do that with dd, all you need to do is change your input from /dev/zero to /dev/random or /dev/urandom and then run it through however many passes you believe is sufficiently secure. A for loop is handy for this drive wiping process, else you would need to intervene manually and repeat it as necessary, hardly efficient.

We’ve omitted the bs and count options because when writing through a whole disk, they are unnecessary. dd will stop when it encounters the end of the file, the end of the file being the end of the disk. You could even accomplish this with cat as well.

Alternatively, you can use dcfldd, which supports all that dd does and much more, including (most importantly?) displaying the amount of data copied.

Also Read:  How to Set Custom Lock Screen Shortcuts in Android Oreo

BONUS TIP: Apart from using dd to erase disk in Linux and Mac, you can use it to write an ISO to a drive by specifying the ISO as the input file to create a bootable USB disk with ease. Additionally, you can use a disk as the input file and point to a filename that doesn’t exist to create an image of your disk.

Erasing disk in Linux and Mac using shred

The next option to erase drive, which is available on both Linux and Mac, though not always installed by default on Linux, is shred. It is very easy to use.

Running this command to wipe hard drive is essentially the same as our dd command in a for-loop. shred takes information from /dev/urandom and uses it to overwrite the disk (or file) specified. The -n option specifies the number of passes to make. In my experience, shred tends to run faster that using dd to read directly from /dev/urandom, but it does not benefit from the incredible ubiquity that dd does.

Also Read:  How to remove "Powered by Blogger" in blogger blog

There are many other tools too that can be used erase disk in Linux and Mac, but they aren’t always within arm’s reach, especially on systems that are command line only. Windows has its own command line tools for disk manipulation, but tread cautiously, they are not as reliable as they might seem. I’ve found myself needing to create a partition table several times in diskpart before Windows would acknowledge it as a usable disk.

When in need of an even more secure way to erase drive, follow whichever of the above solutions you prefer, and then remove the platters from the drive and destroy them in your preferred method. That is about as secure as it gets, though it’s likely overkill for just about anything other than nuclear warhead codes.

What are your favorite methods to erase disk in Linux and Mac? Let us know in the comments below.