TransWikia.com

How to manage to read files unreadable due to bad sectors?

Unix & Linux Asked by amacnewbie on January 7, 2021

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.

One Answer

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.

Answered by LinuxSecurityFreak on January 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP