How to wipe a hard disk completely so that no data recovery tools can retrieve anything? [duplicate]

How can I do a disk low level formatting in Ubuntu on an external hard disk so that any data recovery tools like test-disk or photorec cannot retrieve any data once formatted to ext4 or any file-system? As I was playing around with Test disk, I found that it can recover almost all old files even after formatting it many times and I want to use my external hard disk as new because it is only one year old and in warranty but without any old data.


Solution 1:

I use shred when selling old hard drives, use man shred for more information:

shred -vzn 0 /dev/xxx

You can specify n number of times to overwrite and z to overwrite it all with zeros at the end.

Solution 2:

Modern discs implement the ATA secure erase feature, which you can do with the hdparm command using the --security-erase option, after first setting a password on the disk. Note that there are caveats, including

  • possible firmware bugs
  • possible disk controller timeout for a possibly long-running operation
  • you shouldn't do it over USB

For some discs this will take hours, as each block is rewritten. For others it can take seconds as it just means changing a global encryption key held by the disc that transparently encrypts/decrypts all data going to/from the disk. This is true for hard discs and SSDs. It's the firmware than counts.

Another article also suggests that --security-erase has the advantage that it may also wipe out the hidden areas HPA host protected area and DCO device configuration overlay.

Solution 3:

If you want totally wipe the hdd the best is to use dd:

dd if=/dev/zero of=/dev/sdX bs=512 

Replace sdX with your drive letter

Another possible tools:

  • srm

This command is a replacement for rm command. It works under Linux/BSD/UNIX-like OSes. It removes each specified file by overwriting, renaming, and truncating it before unlinking. This prevents other people from undelete or recovering any information about the file from the command line. Because it does lots of operation on file/directory for secure deletion, it also takes lot of time to remove it.

  • wipe

Solution 4:

This doesn't really answer your question, as you want to use the HDD. However, it's important.


If this is really important data that should never be recovered, it's not safe to use the disk any more. Apple Macs offer a 35 overwrite feature - which they claim is what the government requires, but it's complicated:

Effective immediately, DSS will no longer approve overwriting procedures for the sanitization or downgrading (e.g. release to lower level classified information controls) of IS storage devices (e.g., hard drives) used for classified processing.

It is thought that some of the 3-letter agencies (FBI, CIA, MI6) require physical destruction of magnetic media (e.g., melting in a furnace).

You do have a few options - the one I've relied on in the past is hitting it with a hammer lots of times, then wiping the magnets over it.

However, I'm a student and nobody wants to hack into an empty bank account, so it didn't need to be as secure. Plus, I wasn't going to bin the Hard Drive - it's now a bird scarer for the allotment.

If you work under confidentially agreements (especially those involving the government) you need something a little more secure. I'd recommend a blowtorch:

Source, CNET

My pronouns are He / Him

Solution 5:

The dd command by Maythux is a good one to go with, though I've read somewhere (sorry for no source!) that it's good to overwrite with zeros then do a second pass with random writes, then zero it off on a third pass.

To use dd to write random patterns:

dd if=/dev/urandom of=/dev/sdX bs=512

I have seen some examples of dd using smaller block size (down to bs=4) which I think will make the write slightly more random, but take longer.

Be super careful that you select the correct drive when using dd as it's very dangerous if you make a mistake!