System rescue act using GNU/Linux Live CD

It happened like this: i once rebooted my machine and got back a grub call-whatever-you-like error at the boot prompt, with the consequence of no gnu/linuxes and no windows for the time being. i had so many operating systems installed on my computer, but i cannot boot into atleast one of them, as the boot loader itself had deserted me. what to do? reinstall all the operating systems again? reinstall one gnu/linux os and recover the others through it? or recover the entire hard disk from the backup drives? the last option looks like the most sensible one, provided that i had taken such a backup in the first place.
i keep the Live CD of Knoppix OS just for such occassions. it conveniently allows me to boot into the gnu/linux environment right from the CD, without having anything to do with the hard disk(s) present on my computer. once there, i could connect to the internet and ask for help. but i had my recipe to recover from such situations, written safely in a corner of my mind and i decided to make use of it on this occassion. i opened the terminal emulator and got on with the job:

#fdisk -l

this listed all my disks and their partitions, inducing a sigh of relief in me, and i started mumbling to myself “Everything is fine mate, everything is fine!”
then it was time to see if i had lost any data.

#mkdir /mnt/tmp && mount -t ext3 /dev/hda9 /mnt/tmp

i panicked for a moment as the mount failed with an error. i knew i need to run ‘fsck’ now, so headed straight to that step:

#fsck /dev/hda9

and accepted all the suggestions from it(pressed ‘yes’ to all the questions). my filesystem was ‘apparently’ fixed, but i wanted to confirm it. i tried to mount it again:

#mount /dev/hda9 /mnt/tmp

celebration time! the partition was successfully mounted, and i could browse through all the data in it. i happily repeated the procedure with other gnu/linuxes and then turned my attention to the boot loader.

i quickly chroot‘ed to the root partition of the Ubuntu OS(whose boot loader was installed on my MBR) and entered the following commands at the command shell:

#chroot /mnt/tmp
#grub-install /dev/hda

That’s it! my system was back to its normal state, with the familiar grub bootloader greeting me with all the operating systems that were installed on my computer.

in related but different situations, there are variations of the above procedure which i had to follow to get my system working again. after a hard disk failure, for example, ‘fsck’ refused to work with my filesystem, and i had to first run ‘badblocks’ to scan for any possible bad blocks on the disk, and then run e2fsck with an alternate block number, as the main super-block was corrupted.

#badblocks -svn /dev/hda9
#dumpe2fs /dev/hda8
(use a partition here whose super-block is not corrupted)
#e2fsck -b alternate-super-block-from-above-command> /dev/hda9

if there is currently no partition that has a valid super-block, then the trick is to make a new file with an equal number of blocks as the corrupted partition, and then finding an alternate super block by applying the above procedure to this newly created file.

Anyway, there is atleast one way to get out of the trouble if you have one GNU/Linux Live CD handy with you. If you don’t have one already, go and grab it right now.

A list of popular gnu/linux live cd’s is here.


1 Comment »

  1. […] Adding to what i had written in one of my earlier posts about the rescue act using a gnu/linux live cd , here is a related story posted on the ubuntu-users mailing list: (this is a trimmed version, full story here) […]

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: