1

I am having ext3 filesystem, and recent Linux distribution.

I need to copy (read) a file(s) over to a new destination.

Unfortunately cp / mv or MC (Midnight Commander) stop / fail at certain point within the file(s).

Some files stops rather early, 30%, others stop at 98% with a sector error being shown in the system log.

mv / cp but also MC can not continue to copy the file simply skipping over this (and other) sectors that give I/O read errors. Inside MC I did try retry several times, but to no avail.

The files could be useful to me, and just because some single or few sectors wouldn't be readable on the current disk any more, I would like to continue to read the rest and other healthy parts of the files.

Any good tools or proven mechanism to read a file to the biggest extent possible? The first I/O read error always ends this game for me.

There is probably some way or even a handy tool that can read files more robustly, and just fill the unreadable sector with some placeholder bytes or similar.

Can Linux with a mounted ext3 filesystem not achieve this goal?

Does Linux as a kernel offer some way to read beyond sector errors, and skip to the next sector of the file and so forth?

The system log shows always the same sector (per file) to cause the I/O read error, just to make this clear, and I guess there would be plenty of more sectors and healthy parts to read from these files.

3

ddrescue (gddrescue package, man page)

Supposing the drive has a healthy partition table, you could easily do this:

  1. Create an image file of the failing drive's partition(s) onto some healthy drive (I don't want to make this harder for you than necessary, that is why we are not creating the whole drive's image, but if the partition table proves to be broken, you would have to in the end).

  2. Investigate the log file (it is actually called a map file, but that is of little importance now for you), depending on the number of errors there act accordingly.

  3. That means, either try to mount the image file of the partition in question directly, or run for instance testdisk on a whole disk image file, in case the partition table would be damaged, that's a perfect utility for a partition recovery, but let's start with creating the image file of the partition.


sudo ddrescue --idirect --retry-passes=3 /dev/sdx9 recovery.img recovery.log

Assuming:

  • the drives name is /dev/sdx

  • the partition you need to recover has number 9

  • you want to retry bad sectors 3 times

  • you want to save the image file into the current directory (.)

  • you want to save the image file as recovery.img

  • you want to save the log file, which is very important !, as recovery.log


If all goes well, then simply mount the image file afterwards:

sudo mount recovery.img /mnt/whateverMountPoint

If, for any reason, the drive stops responding, or whatever error occurs, I usually just reboot the machine, and run the very same command, which will restart the process from the point where it previously stopped.


BEWARE:

I did not realize you mentioned mounted filesystem. Which could be a problem.

You see, you should not create an image of a mounted filesystem. Instead I suggest you create some Linux USB, boot it, and then proceed with what I said.

  • Thanks for the ddrescue hints, I am already working on my two erroring files. The drive/partition mounts fine and the sector errors seem to be accidentally in these files. Will see how much ddrescue can read from them and what happens with the troubling sectors. Never used ddrescue before. – amacnewbie Sep 21 '18 at 16:27
  • @amacnewbie the troubling (bad) sectors will be skipped, I assume filled with zeroes, but I don't have a source for this claim. Don't worry, most of your files will probably be fine. – LinuxSecurityFreak Sep 21 '18 at 16:30
  • Also, OP should make sure the filesystem on the damaged disk doesn't get mounted: The kernel will write metadata blocks on mount and dismount, potentially damaging the disk further. – dirkt Sep 22 '18 at 6:04
  • @dirkt Thanks for pointing it out, I will edit the answer later today. – LinuxSecurityFreak Sep 22 '18 at 6:13

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.