9

I have an image of my home (/dev/sda3) partition, which I've created using the "dd" command.

dd if=/dev/sda3 of=/path/to/disk.img

I've deleted the home partition via gparted in order to enlarge my /dev/root partition. Then I've recreated the /dev/sda3 partition which is smaller in size then the one I've backed up to the image.

I was wondering since I have a 2TB external HDD, could it be possible to mount my backed up image on the external HDD and then copy the files into the /home directory. Since the external HDD would be already in a "mounted state", I'm unsure whether this is a good idea, mounting on a mounted device.

  • I'm running Slackware 13.37 (64bit).
  • used ext4 on all the partitions.
  • resized the root partition with gparted live cd.

I've tried:

mount -t ext4 /path/to/disk.img /mng/image -o loop

It gave me an fs error (wrong fs type, bad option, bad superblock on dev/loop/0)

Then I did

dmesg | tail

which outputs:

EXT4-fs (loop0) : bad geometry: block count 29009610 exceeds size of defice (1679229 blocks)

I have no idea what to do, I want to restore my /home data from the image I've backed up.

[Update]: * The disk.image is on my USB 16GB flash drive. The image size is around 6GB. The image was created from a deleted partition which was around 100GB and now it's reduced to around 80GB.

[Update]: I've tried this today: LQWiki: Some dd examples says:

You don't want to tell a drive it is bigger than it really is by writing a partition table from a larger drive to a smaller drive. The first 63 sectors of a drive are empty, except sector 1, the MBR.

dd if=/dev/sda skip=2 of=/dev/sdb seek=2 bs=4k conv=noerror

I tried then to mount /dev/sda3 to /home. dmesg | tail outputs an error "group descriptors corrupted!"

Then I tried:

fsck.ext4 -y -f /dev/sda3

It outputs a large amount of fixed issues and million of numbers going down at the speed of light.

After that I successfully mounted /dev/sda3 to /home, but there was no data present in the home directory. Only some directory named "lost+found" which is also empty.

3 Answers3

10

You can skip the first step, and simply:

sudo losetup /dev/loop0 /path/to/disk.img

mkdir /mnt/image
sudo mount /path/to/disk.img /mnt/image
MichaelC
  • 271
  • 1
  • 3
  • 9
2

I know this is an old question, but I just ran into this same problem two days ago, and was able to somewhat solve the problem.

This issue basically happens when somehow or another an ext2/3/4 filesystem image isn't fully copied to an image file, essentially leaving a chunk of data missing off of the end. Because of this, you won't be able to recover all the files that existed in the original image, unless by some miracle no file data was stored in the missing part of the image.

In my case, I was unable to mount the image, but there is a utility that will scan ext2/3/4 filesystem images and dump all the found files to a specified location:

bash$ losetup -f ./corrupted.img # mounts to /dev/loop0
bash$ sudo debugfs -c /dev/loop0
debugfs: rdump / /path/to/dump/files/
debugfs: quit

The rdump command takes two arguments: path inside the corrupted image to recursively scan for files, and the path on the native filesystem to save the files to. Any files that were not recoverable will be created with a size of 0 bytes.

You'll probably need to chown the files since debugfs runs as root.

Gogeta70
  • 131
1

Try to truncate the file to the exceeding block count and then remount.
In your situation:

EXT4-fs (loop0) : bad geometry: block count 29009610 exceeds size of defice (1679229 blocks)

truncate -o -s 29009610 /path/to/disk.img 
mount -o loop /path/to/disk.img /mng/image

Flavio