A large file on our ext4 file system may have picked up a bad block in the middle. Copying the file to another drive results in an input/output error part way through. Data beyond the bad sectors still seems ok though.

We don't have a backup of this file since it was recently created, so I'm looking for a way of copying the entire readable portion of the file while skipping bad sectors.

I've read other sites which suggest ways of recovering entire hard drives with bad blocks but they don't say much about recovering any files which span the bad blocks.


  • What type of file? Are you sure the file is of a type that will still be usable if a single block is corrupt? You could try performing a rescue on the entire drive, then mount the rescued filesystem, and recover the file.
    – Zoredache
    Mar 20, 2013 at 16:37

4 Answers 4


You should be able to dd it:

dd if=fileWithBadBlocks of=recoveredFile bs=4k conv=noerror,sync
  • 1
    This worked very well to copy the file away. It skipped over several sections which were corrupt but retrieved most of the file. Thank you very much for your help.
    – Chris C.
    Mar 20, 2013 at 18:15
  • This can result in a larger output file, can fix that using: truncate --reference corrupt-file recovered-file Jun 14, 2014 at 1:57

It should be noted that the file system will only be reading "blocks" off the disk (typically 4k) but corruption on hard disks would typically concern "sectors" (512 Bytes on non-ADF-disks).

If a single sector in a block is unreadable, the entire block is considered invalid by the filesystem and the contents are not returned upon request, so actually trying to copy the file might not give you the best results regarding the amount of recoverable data.

Instead, you could look into either using dd with the conv=noerror option and the default block size of 512 bytes or even ddrescue to copy the entire partition containing the file system and copy the file off afterwards.


A little update at 2021, recently I encountered the same issue, especially with innoDB (.ibd) files became corrupted. Needed to fix thing asap, and cloning the entire disk could take days, so I developed a software which intended to solve exactly the same issue.

I searched a lot without a success, thats why I made it to public. https://github.com/DaVieS007/Partial-File-Recovery


While dd can be useful, for such a task I suggest using ddrescue. @the-wabbit suggested something similar, by reading the entire partition. However, ddrescue can be used even for single-file reads so you don't read the entire partition for recovering a specific file.

For example: ddrescue /to/be/rescued /the/rescued/file

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.