dd tricks for holey files
By relling on Mar 13, 2008
The noerror option is described in dd(1) as:
Does not stop processing on an input error.
When an input error occurs, a diagnostic mes-
sage is written on standard error, followed
by the current input and output block counts
in the same format as used at completion. If
the sync conversion is specified, the missing
input is replaced with null bytes and pro-
cessed normally. Otherwise, the input block
will be omitted from the output.
This looks like the perfect solution, rather than my dd and iseek script. But I didn't post this because, quite simply, I don't really understand what I get out of it.
Recall that I had a corrupted file which is 2.9 MBytes in size. Somewhere around 1.1 MBytes into the file, the data is corrupted and fails the ZFS checksum test.
zpool scrub zpl_slim
Restore the file in question if possible. Otherwise restore the
Permanent errors have been detected in the following files:
I attempted to use dd with the noerror flag using several different block sizes to see what I could come up with. Here are those results:
for i in 1k 8k 16k 32k 128k 256k 512k
hmmm... all of these files are of different sizes, so I'm really unsure what I've ended up with. None of them are the same size as the original file, which is a bit unexpected.
of=/tmp/whaa.1k bs=1k conv=noerror
hmmm... well, dd did copy some of the file, but seemed to give up after around 5 attempts and I only seemed to get the first 1.1 MBytes of the file. What is going on here? A quick look at the dd source (open source is a good thing) shows that there is a definition of BADLIMIT which is how many times dd will try before giving up. The default compilation sets BADLIMIT to 5. Aha! A quick download of the dd code and I set BADLIMIT to be really huge and tried again.
of=/tmp/whbb.1k bs=1k conv=noerror
As dd processes the input file, it doesn't really do a seek, so it can't really get past the corruption. It is getting something, because od shows that the end of the whbb.1k file is not full of nulls. But I really don't believe this is the data in a form which could be useful. And I really can't explain why the new file is much larger than the original. I suspect that dd gets stuck at the corrupted area and does not seek beyond it. In any case, it appears that letting dd do the dirty work by itself will not acheive the desired results. This is, of course, yet another opportunity...