I prefer badblocks
in destructive write mode for this. It writes, it continues doing so when it hits errors, and finally it tells you where those errors were, and this information may help you decide what to do next (Will It Blend?).
# badblocks -v -b 4096 -t random -o badblocks.txt -w /dev/destroyme
Checking for bad blocks in read-write mode
From block 0 to 2097151
Testing with random pattern: done
Reading and comparing: done
Pass completed, 52105 bad blocks found. (0/52105/0 errors)
And the block list:
# head badblocks.txt
2097000
2097001
2097002
2097003
2097004
And what's left on the disk afterwards:
# hexdump -C /dev/destroyme
00000000 be e9 2e a5 87 1d 9e 61 e5 3c 98 7e b6 96 c6 ed |.......a.<.~....|
00000010 2c fe db 06 bf 10 d0 c3 52 52 b8 a1 55 62 6c 13 |,.......RR..Ubl.|
00000020 4b 9a b8 d3 b7 57 34 9c 93 cc 1a 49 62 e0 36 8e |K....W4....Ib.6.|
Note it's not really random data - the pattern is repetitive, so if you skipped 1MiB
you'd see the same output again.
It will also try to verify by reading the data back in, so if you have a disk that claims to be writing successfully but returns wrong data on readback, it will find those errors too. (Make sure no other processes write to the disk while badblocks is running to avoid false positives.)
Of course with a badly broken disk this may take too long: there is no code that would make it skip over defective areas entirely. The only way you could achieve that with badblocks
would be using a much larger blocksize.
I'm not sure if ddrescue
does this any better; it's supposed to do that in the other direction (recover as much data as fast as possible). You can do it manually for dd/ddrescue/badblocks by specifying first/last block...
dd conv=noerror
might be a GNU extension, I'm not sure. In any case, it should do the trick. The SATA tell-the-drive-to-erase-itself answer is worth looking into for erasing entire drives, though. – Peter Cordes 18 hours agodd
documentsnoerror
as 'continue after read errors' ... – maxschlepzig 17 hours agodd conv=noerror
ist POSIX standard but it may be really slow – schily 17 hours agodd conv=noerror
must be for reading errors (according to the manpage), not writing errors. There is nothing bad in combining it withconv=notrunc
, which did the trick with ignoring the write errors for me. unix.stackexchange.com/a/229379/4319 – imz -- Ivan Zakharyaschev 17 hours ago