So I have a hard drive that is failing. I want to erase the data on it before sending it for replacement. I'm trying to use dd if=/dev/zero of=/dev/sdXX, but it stops at the first write error. How can I overwrite the drive with zeros, ignoring write errors? conv=noerror seems to only affect the input file.

  • There is a bug report in the Debian database about this behavior, but it seems like it's not implemented yet. – Bobby Dec 15 '10 at 12:09
  • Does badblocks also stop on errors? Perhaps you could do a destructive write with that? – oKtosiTe Dec 15 '10 at 13:57
  • I now also ran destructive badblocks to be sure how much bad blocks are there before I return the disk on Monday. It also erased the disk successfully, but it took nearly 50 hours. – TestUser16418 Dec 19 '10 at 19:30

try ddrescue instead of dd - it tries harder with errors

| improve this answer | |
  • 1
    ddrescue successfully erased the entire disk, ignoring the write errors. Thank you very much. – TestUser16418 Dec 15 '10 at 22:41

Parameters I used with ddrescue to erase drive /dev/sdb (filled with zeros from /dev/zero) and log output into file log.txt:

ddrescue --force /dev/zero /dev/sdb log.txt
| improve this answer | |
  • To wipe with random data use: ddrescue --force /dev/urandom /dev/sdX tmp.log – Bastion Aug 15 '19 at 4:08
  • How do you know when it's done? I did it and let it run for about 20 minutes and it remained at 0.00% rescued. It's an NVMe SSD with bad blocks that I'm trying to erase... the Samsung Secure Erase utility didn't work for me. – user1960364 Dec 6 '19 at 22:49

If you are just looking to wipe the drive try dban

From the site:

Darik's Boot and Nuke ("DBAN") is a self-contained boot disk that securely wipes the hard disks of most computers. DBAN will automatically and completely delete the contents of any hard disk that it can detect, which makes it an appropriate utility for bulk or emergency data destruction.

| improve this answer | |
  • I was going to suggest this. – qroberts Dec 15 '10 at 17:23

For the record, dd also has an option conv=noerror to skip errors. If you had errors on an input file, and when not using /dev/zero, you'd want to use conv=noerror,notrunc or conv=noerror,sync to prevent dd from truncating the output file where errors exist on the input file.

For your query, you might try this command instead:

dd if=/dev/zero of=/dev/sdXX conv=noerror  

To speed up the process, and potentially avoid the drive dying in mid stride, you might also try increasing the byte size from the default 512 (which makes dd read sector-by-sector, which is slow) to something larger such as 4K (which is eight times as large):

dd if=/dev/zero of=/dev/sdXX bs=4K conv=noerror  

Note: With a larger byte size, skipped errors may leave sections of readable data slightly-less than the byte size you choose, but it's still unlikely that anyone would be able to get anything from those sections after the entire disk has been run through the process.

Besides that, I'm sure hard drive manufacturers properly dispose of hard drives that get returned for warranty replacement, in case the drive does fail before you were able to fully complete the overwrite process.

| improve this answer | |
  • man dd shows "noerror" means "continue after read errors" – Kevin Smyth Jan 18 '14 at 20:43

Definitely not a power-user solution, but if the write errors are rare, you might just want to continue manually after their occurence.

You could theoretically script something to do that automatically, but it's not that trivial, and I'd rather write a tool to do the trick than bother with scripting dd..

          skip BLOCKS obs-sized blocks at start of output
| improve this answer | |
  • 1
    ... or use dd-rescue... – Antti Haapala Sep 5 '17 at 6:52
  • ... would dd-rescue handle write errors correctly? – qdot Jul 6 '18 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.