Restoring a disk image that was cloned with errors

0

I have a disk image of a 500 GB that was created using the following:

# dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c > backup.img.gz

There were certain errors (approximately 15-20 of them) stating the following, at a certain point above approximately 420 GB. The errors were interspersed by few GBs of data in between (so, for example, the first error was at 420 GB, the next at 430 GB, the next at 436 GB, and so on.)

dd: error reading '/dev/sda': Input/output error

Is it safe to restore this disk image?

user2064000

Posted 2016-07-28T17:26:24.113

Reputation: 1 326

No. What makes you think it would be? You will end up with a disk with unknown errors. – DavidPostill – 2016-07-28T17:59:57.123

if you do, restore it to other media, and copy the files you want back over manually. Also check the SMART status of your disk. Generally, DD should not encounter such an error on a healthy disk. – Frank Thomas – 2016-07-28T19:00:32.900

Answers

1

It depends of what you mean by "safe".

Restoring the image to a healthy drive won't break the drive, so it is safe in this sense. Still the image is somewhat corrupted and you may get corrupted filesystem and files as the result, so it is not safe in this other sense.

I say "you may get corrupted files", not "you will", because there is a chance all those errors were at blocks marked as empty. This is because dd knows nothing about the filesystem and a concept of free space, it reads all the data. If there were a lot of free space during image creation, you may have been lucky and all your files and crucial data is in the image. The errors were not at the beginning of the disk, so the partition table will be OK (unless it was MBR and there was extended partition with logical partitions and some logical partition entry has not been read by dd; it is possible because any logical partition is defined just before it begins, not at the beginning of the disk like primary partitions and extended one).

On the other hand you may not be so lucky, you may experience not only few corrupted files but also corrupted filesystem, which may manifest as (e.g.) lack of entire folders that should be there with many files. Compare this question; you are in similar situation when it comes to accessing files and folders. Read my answer there, especially the second edit where I explain what may happen.

One of the comments suggests to

restore it to other media, and copy the files you want back over manually.

To copy the files you don't need to restore to other media. You can mount your image directly. Use kpartx or mount -o offset=… to access partitions inside your image. For example try this sequence (some steps require sudo):

  • gzip -dc < backup.img.gz > backup.img (in a moment fsck and maybe some other tools will alter the image, so it's good to have the original archive untouched just in case, I hope you have enough free space for this);
  • kpartx -av backup.img (read the output, your partitions from inside the image are now available as /dev/mapper/loop?p?);
  • use fsck on /dev/mapper/loop?p? of your choice;
  • mount /dev/mapper/loop?p? of your choice;
  • copy the files;
  • umount …;
  • kpartx -dv backup.img to clean.

In case you find files or folders missing, you may use recovery software like photorec. Good software of this kind should operate on an image without the need of restoring it to physical device.

Kamil Maciorowski

Posted 2016-07-28T17:26:24.113

Reputation: 38 429