Skip to main content

Learn How To Erase Disk In Linux And Mac With Few Steps Using Simple Commands


disk erasing linux and mac
Image: Flickr
Sometimes you need to erase a disk that isn’t working properly or just needs to be wiped for security reasons. But how do you do that without the all the fancy tools you can find online? Well, if you’re a Mac or Linux user, it’s very easy to do using tools like dd and
shred (Windows, not so much, but still doable).
Idon’t know how many times I’ve needed to wipe a disk that was acting up and just reformat. In a home that uses Windows, Linux, and Macs, there’s always some computer complaining about how some disk is not formatted properly.
I’ve come across a few scenarios when drives were so deranged that my go-to tools, like gParted (and Disk Utility before they butchered all the features and only left the bone), would produce errors every time I tried to format or create a new partition table. It’s pretty frustrating when some of the best tools simply don’t want to work. What do you do then to securely erase disk in Linux and Mac?
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.
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.
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.
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.

Comments

WHAT'S HOT

Samsung Overtakes Fitbit In Wearable Sales For First Time

Fitbit has been a top competitor on the global wearable market for a long time, but the South Korea giant Samsung managed to steal the silver crown of the wearable market from Fitbit. According to Strategy Analytics, Samsung gained the

Supermassive Black Holes Found Orbiting Each Other For The First Time

Image Credit: UCR Researchers from Stanford University have identified super-massive binary black holes at the center of Galaxy 0402+379 about 750 billion light years away. The two of the black holes are just 24 light years apart and one of them is orbiting the other. This is the first

System76 Announces Its Own Linux Distribution Named Pop!_OS

Image: System76 Linux machine vendor System76 has launched their own operating system named Pop!_OS. Based on Ubuntu GNOME, this new Linux distro’s Alpha version is right now available for download. The first final release of Pop!_OS will be shipped

"The corruption is everywhere" - Take a look at what a Nigerian saw in the cupcake he bought

A Nigerian man who bought something he thought was a cupcake, got the shocker of his life after he opened the package to see it was a well packaged "bread".


A Nigerian man who bought something he thought was a cupcake, got the shocker of his life after he opened the package to see it was a well packaged "bread".