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.
- 950
5 Answers
Parameters I used with ddrescue to erase drive /dev/sdb (filled with zeros from /dev/zero) and log output into file log.txt (replace sdX with sdb):
ddrescue --force /dev/zero /dev/sdX log.txt
- 145
- 1
- 6
- 201
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.
- 141
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.
- 13,835
- 597
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..
seek=BLOCKS
skip BLOCKS obs-sized blocks at start of output
- 936