0

I have a drive that's on the verge of failing (C5 a C6 are triggered) so I decided to make another backup while I still can. For that, I'm using dd to another drive of the exact same model. As expected, I have some input/output errors, and I'd like to know, what dd does when it encounters errors. Does it just skip the sector and writes nothing? Or does it replace the data that was previously on the target drive with 0s?

Also, since I'm using 64K blocks, can I run dd at the location where the copy failed with a smaller block size to try to get a little bit more data out of it?

  • 1
    Don't use dd. Use ddrescue, which handles these read errors gracefully. – roaima Jan 26 at 10:07
  • You get the program ddrescue by installing the package gddrescue (at least in Debian and Ubuntu). The info pages at info ddrescue are very useful. Please read them before starting to use the program. – sudodus Jan 26 at 12:12
1

As mentioned in comments, GNU ddrescue is a way better tool for this use case. Let me answer your explicit questions about dd anyway.

I'd like to know, what dd does when it encounters errors

It exits, unless conv=noerror was given, which makes the tool ignore input errors. Let's suppose noerror was given and an input error occurred. Then

Does it just skip the sector and writes nothing? Or does it replace the data that was previously on the target drive with 0s?

It depends whether or not you used conv=sync. If you do, dd will pad every input block to the size of the ibs= buffer, appending null bytes. I guess if ibs equals the sector size of your source block device, then this will keep your output stream in sync with the input in case of read errors. But with wrong ibs it's very probable a read error will make streams get out of sync, like in this excellent answer. It seems iflag=fullblock helps.

Additionally sync may make your output bigger than input, even when there are no read errors; this will happen if the last block hits EOF before ibs buffer gets full.

Note noerror and sync are required by POSIX, fullblock is not.

can I run dd at the location where the copy failed with a smaller block size to try to get a little bit more data out of it?

In theory -- yes. But this requires you to manually work with skip= and seek=, while still taking care of problems mentioned above. Don't forget you need to recalculate skip and seek to correspond to the new block size. It's possible, but you will soon wish to automate the process.


And now compare all these issues with GNU ddrescue default behavior:

  • It skips read errors; it gets back to "suspicious" fragments later, trying to read them in smaller and smaller chunks.
  • It keeps proper offsets no matter what.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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