Sunday 13 December 2009

Assume Recovery Position

Had a hard drive fail in a notebook and unlike Windows filth I managed to salvage the entire drive on ubuntu and effectively copy the drive to a replacement with almost no effort.

Now the Windoze purists amongst the rear seats will witter about Ghost and stuff but looking at the crowd near the exit doors I notice very few hands when I ask who is running a legitimate (licensed) version of Ghost let alone a legitimate version of Windows.

So in the real world the argument would have to be, if your version of Ghost is not one you have purchased then you would be stuck.

With linux it's not a problem as I don't need to worry about the shops being shut and how to get a legal copy of a backup utility.

I could have used "sbackup" which will back up files but I decided to try a deep recovery method purely to see if it would work - It's important to note I didn't need to do it this way, I did it so if I have a drive that is REALLY faulty I should be able to do the same.

So .... the failing drive is 60gb, the replacement is also 60gb
Ubuntu 9.10 identifies the original drive as "imminent failure", Palimsest (the drive utility) monitors the drives on Ubuntu 9.10 and identifies failure in real time.
The replacement drive is identified as "Good" with no errors or issues.

Next step .. Boot on Ubuntu Live CD (or in my case Ubuntu pen drive)
Install ddrescue (make sure the repositories are enabled so you can get it from T'Internet)
sudo apt-get install ddrescue

Make sure I have a USB drive plugged in to dump the files onto.
Ubuntu mounts drives on my system into /media so I mounted the drives and made sure both were available.

I made a mount point for the USB drive so the target directory was easy i.e
sudo mount /dev/sdd1 /media/250gb
i.e the mount point was /media/250gb

as the Linux drive as a unique uuid which is VERY long I made a simpler mount point for my main drive (which is /dev/sda) i.e
sudo mount /dev/sda1 /media/hdd

Bear in mind I made the directories first in the /media folder - the Ubuntu pen drive is persistent so these mount points are retained for me later.

So I have 2 drives ...
/media/hdd (my original and failing drive)
/media/250gb (my USB drive)

a quick copy of the data using ddrescue....

sudo ddrescue /media/hdd /media/250gb/backup.img

This copied the entire drive and took about 15 minutes.

I now had a full image file of all the data ....

A quick check of the integrity of the backup...

fsck -y /media/250gb/backup.img

This checks the backup file for any issues, the backup file was fine.

In with the replacement drive ... now this was the bit where most web sites entered vague territory.

The replacement was formatted as "ext3" file system and mounted in the same way i.e

/media/250gb (the USB drive)
/media/hdd (the new hdd)

A quick recover (which took about 30 mins)

sudo ddrescue /media/250gb/backup.img /media/hdd

Back comes all the data .....

I didn't realise that in fact 2 things were missing, the grub boot loader and the swap file ... (If I had known this first I would have made partitions for them and got them ready - Doh !!!)

So ..... I had the data back but needed 2 partitions from logical reading , I needed a 100mb bootpartition and a swap one, about 1.5gb.

Using Gparted I moved the main parition "to the right" 100mb leaving an empty parition at the front, then I shrunk it at the end leaving another partition of 1.5gb.
Let Gparted do it's thing so I have blank 100mb, the main drive partition and a blank 1.5gb.

In Gparted click on the 100mb partition and format it to ext3 - done.
In Gparted click on the 1.5gb partition and format swap.

At this point I'm almost done, I have 100mb boot partition (ext3), the main file system and 1.5gb swap.

To re-install grub there's a little trick people have posted.

Using the pen drive or live CD tell it to install Ubuntu to hard drive.
When the partitioner comes up tell it you will manually partition, you will see the three patitions, click each one and "change", put the 100mb mount point as /boot, put the main partition mount point as / and the swap partition will already be showing as swap anyway.

You then continue forwards as if your installing, the system will advise it's installing but will re-install grub and the swap partition correctly.

Let it finish, reboot and it was done.

Sounds like a lot of steps but bear in mind ddrescue can recover drives even with errors on them while Ghost normally falls over in a big heap and considering it was done with free software then it's even better.

I could have simply copied the files over from drive to drive but wanted to try a full disaster recovery type scenario, I've also taken a full 100% copy using "tar" which again I could recover easily over the top of the new drive but wanted the full experience.

Add to this my experience a couple of weeks ago where our media PC locked up during a full Ubuntu change migration from 9.04 to 9.10 (turned out to be my fault, I had put a fan in backwards so it was blowing air the wrong way - ooops), in normal circumstances your windows would be screwed but with Ubuntu I booted on Live CD, mounted the partition (which was effectively screwed) transferred super user control to that drive (so your actions are on that partition and not the live CD) issue about 4 commands and the system is running as good as ever.

I would love to see the flaky software known as Windows do the same as that, no reload, no re-install of anything, just the ability for the OS to carry on where it left off !!!

Apparently Windows 7 is out, no idea what it's like maybe i'll be given it for my corporate laptop but it's OK I don't need it at home.

No comments:

Post a Comment