1. Home
  2. Linux

3 Ways To Securely Erase A Hard Drive On Linux

Each time you re-install Linux and format your hard drive partitions, the data on them isn’t fully purged. The reasons for this are complicated, but suffice it to say, anyone that gets their hands on an old hard drive that hasn’t been adequately erased can recover personal files and sensitive data. That’s why in this article, we’ll be going over all of the best ways to erase a hard drive on Linux. Everything from using something like DD, to Shred and even DBAN.

Note: Shred and DD require knowing what letter is assigned to the drive you want to erase. To find the drive letter for the hard drive you plan to erase, open up a terminal and enter the lsblk command. The names they show correspond to the hard drives.

Zeroing A Drive – DD

The most common method for securely erasing a hard drive (aka zeroing) on Linux is done using the DD command. This method isn’t quick, but given the fact that every Linux and Unix system comes with the DD tool pre-installed, it makes this way of erasing a hard drive very accessible. There’s one catch though, and that is the fact that DD will not zero a drive currently in use. Meaning you can’t just do a DD overtop of your running Linux operating system. Instead, you’ll need to either unplug the hard drive and put it in another PC or load up a Linux live disk.

Assuming you’ve done one of these two things, here’s how to securely erase a hard drive using DD on Linux.

Step 1: make sure that the drive isn’t mounted. If it is attached, unmount it using the file manager. Alternatively, use the umount command.

Note: replace X with the actual drive letter, and the Y with the partition number (e.g., /dev/sda1).

sudo umount /dev/sdXY -l
sudo dd if=/dev/urandom of=/dev/sdX bs=10M

Using /dev/urandom to write zeros on top of your entire hard drive is going to take a very long time. The best way to go about using DD in this manner is to turn it on and let it run overnight. When the next day comes around, everything should be good to go. You’ll know that the DD command is done when you can type in the terminal window again.

Using Shred

Another reliable way to erase a hard drive is with the GNU Shred tool. Like DD, it’s included on all Linux distributions in some form. Unlike DD, it can delete both files and entire hard drives. This method is ideal, especially if you want to erase aspects of the hard drive, but maybe not the whole file system. Here’s how to delete files with shred.

shred -u file.odt photo1.png photo2.zip


find /path/to/folder/to/shred/ -exec shred {} \;

Lastly, use the Shred tool to erase a hard drive by running this command.

Like DD, using Shred to erase a drive takes quite a while. Best to just run this tool overnight and let it delete everything. When the terminal can accept typing again, you’ll know it’s finished.

Note: change X with your drive letter (e.g. /dev/sda).

sudo shred -vfz /dev/sdX

Other Methods

If DD and Shred aren’t good enough for securely wiping your hard drive, consider using the Darik’s Boot And Nuke tool. It’s a Linux powered open source tool that will delete anything and everything connected to your PC, as long as its running. Using DBAN requires a USB live disk. Download the Etcher USB imaging tool, as well as the latest DBAN ISO image. The DBAN tool is only a 15 MB file, so pretty much any USB drive i.e., any capacity, will work.

When everything is downloaded, open up the Etcher USB tool and use it to flash the DBAN ISO image. Then restart your PC. Be sure to log into your PC’s BIOS and change the bootloader so that the USB key loads first.

Note: disconnect any hard drives from your PC that you do not want to erase. DBAN will delete absolutely everything that is connected to it.

On the DBAN boot screen, enter “autonuke” into the prompt. This command will automatically nuke anything and everything connected to the PC. So once again, be very sure that every hard drive you want to save IS NOT CONNECTED, and that only ones you do wish to erase are connected. There is no way to undo this one it’s been done.

Running autonuke will bring up the DBAN UI. It’ll scan for drives and erase them one at a time. Be patient, as this process takes a long time. You’ll know when DBAN is complete, as it will tell you on the screen. Best to just leave the tool running.

After the erasing process completes, the screen will turn black and say “All selected disks have been wiped”. Press any key to continue with the tool to the end screen.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.