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.
- 920
- 3
- 7
- 13
-
There is [a bug report in the Debian database](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=415286) 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
5 Answers
try ddrescue instead of dd - it tries harder with errors
- 2,743
- 18
- 17
-
1ddrescue successfully erased the entire disk, ignoring the write errors. Thank you very much. – TestUser16418 Dec 15 '10 at 22:41
-
11. ddrescue is for *reading* from a disk with errors. it also *writes* to a disk with errors? 2. This answer would be better with an example command. – endolith Dec 03 '20 at 15:05
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
- 181
- 1
- 2
-
1To wipe with random data use: ddrescue --force /dev/urandom /dev/sdX tmp.log – Bastion Aug 15 '19 at 04: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 06 '19 at 22:49
-
This doesn't mention anything about the drive in question having bad sectors. – Hashim Aziz Dec 28 '20 at 20:44
-
1I would add the `-D` option to write directly to the /dev/sdX bypassing kernel cache &c. – berezovskyi Mar 11 '21 at 18:02
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
- 3
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.
- 11,898
- 35
- 98
- 166
- 597
- 1
- 6
- 19
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
- 816
- 1
- 7
- 21