Page 1 of 1

Restoring disk after hardware failure

PostPosted: Aug 23rd, '15, 15:30
by mackowiakp
I have to restore content of 480 GB SSD broken disk to new one 240 GB (smaller). I have ISO files created usin "dd" of /root (aprox 20 GB on previous disk) and /home (20 GB too on previous). All the rest of previous 480 GB SSD HDD was used for user data as separate partition mounted to /home/user_dir,. I have a copy of this files too (aprox 30 GB).
So how can I restore /root and /home partitions and make disk bootable? The third partition I can restore just by creating new one and simply copy user data files. Please advice me because it is my wife laptop :cry:

Re: Restoring disk after hardware failure

PostPosted: Aug 24th, '15, 00:11
by jiml8
For the future, I recommend that you study https://forums.mageia.org/en/viewtopic.php?f=41&t=5957this thread and implement the backup system it describes. This will keep your data safe, in a fashion that is independent of the size of the disk on which that data resides, and restores are dead simple.

To deal with your current situation, you need to open those images you created with dd. Exactly HOW you open them depends on exactly how you took them. It would be helpful if you could provide that information (the exact dd command you used).

Assuming, for the moment, that you took those images as partition images, then the following should work.

Attach the drive containing the dd image, then mount it to some mountpoint:
Code: Select all
mount -o loop -t ext4 /path/to/myddimage.iso /path/to/mymountpoint

This, of course, presumes that the filesystem on the dd image is ext4. Modify as necessary.

If this worked, then you can cd into mymountpoint and directly access all the files that are there.
Now, IF you took this information as a complete disk image, the problem is somewhat more complicated. In this event, proceed as follows:

First, find the partition in the image you wish to mount:
Code: Select all
parted myddimage.iso unit b print

Then assign it to a loop device:
Code: Select all
losetup -o<starting byte of partition from previous command> /dev/loopN myddimage.iso

where the N in loopN is a number from 1 to 8 (typically) representing an unused loop device that you intend to use for this.

Then, mount the partition:
Code: Select all
 mount /dev/loopN /path/to/mymountpoint


You may now cd into mymountpoint and see your data.

Later, unmount this guy like this:
Code: Select all
umount mymountpoint
losetup -d /dev/loopN

Re: Restoring disk after hardware failure

PostPosted: Aug 24th, '15, 00:15
by jiml8
Actually, if you did use dd to take a disk image, and both / and /home were at the front of the old drive, then you can just use dd to lay that image onto the new drive and it shouldl work fine. If you imaged the entire older drive, then any partitions that end after the end of the new drive or begin after the end of the new drive will be messed up and may or may not be accessible, but the / and /home partitions would be available.

Re: Restoring disk after hardware failure

PostPosted: Aug 24th, '15, 10:02
by mackowiakp
I created ISO file using script below. Script create compressed ISO file, count md5 sum and copy file to my home server:

Code: Select all
for i in 1 5 7
do
dd if=/dev/sda$i bs=10M conv=notrunc | gzip -c > /home/maciek/back/RSYNC/piotr_sda$i.iso.gz && md5sum /home/maciek/back/RSYNC/piotr_sda$i.iso.gz | awk '{ print $1 }' > /home/maciek/back/RSYNC/piotr_sda$i.iso.gz.md5 && ncftpput -u user -p password server /home/media/disk-2/ /home/maciek/back/RSYNC/piotr*
rm -f /home/maciek/back/RSYNC/piotr_sd*
done

Re: Restoring disk after hardware failure

PostPosted: Aug 24th, '15, 19:23
by doktor5000
They are not .iso images simply because you give them the ending .iso, they are still simple partition images (and in the case usually they get the ending .img).

And as they are .gzip compressed, mounting them directly is quite a bit harder then uncompressed images.
You should definitely read http://unix.stackexchange.com/questions ... on-the-fly to switch your backup process.

It also contains a link to a workaround so you could directly loop-mount your partition images:
https://blogs.gnome.org/muelli/2012/10/ ... pped-file/
Or try archivemount: http://linuxaria.com/howto/how-to-mount ... ile-system