Wednesday, October 28, 2009

Linux booting problems - 'GRUB' recovery

This is for the 'Linux Advanced Users'. It is based on a requirement of a friend (Mickey - hands up!! - and for many others who have faced similar problems and taken help!!) to recover his messed up booting disk, luckily on Linux, ostensibly due to inadvertent power supply switching off problems!!

Intro: When your system boots up, post the BIOS, a small software/program in the hard-disks boot sector loads up to 'pull' in your Operating System basic core (kernel) into the RAM , which in-turn loads other parts of the OS (putting this rather simplistically although its a pretty hard-working/complex process!!!). The initial 'small software/program' is called the boot loader. 
A boot loader, also called a boot manager, is a small program that places the operating system (OS) of a computer into memory.
If there are multiple Operating Systems in your system, the boot-loader presents you a menu, from where you choose which OS to load. For example, in a multi-boot system, if you have, say, 'Windows 7', 'Ununtu Karmic Kola' and 'Mint Gloria', the boot loader will initially show you a simple menu asking you to choose which one to use for the session.

Windows has its own proprietary boot-loader (not discussed here!!). Linux has many boot loaders that a user can choose from, and generally two are offered by the Linux distributions - LILO (Linux Loader) and GRUB (Grand Unified Bootloader).

From experience, I have seen (don't worry! doesn't happen enough times! :-) ) that in case there is a power supply interruption, or improper shut-down, the sectors where the GRUB is written (boot sectors et la) do act up (generally of older/much-used hard disks!!). This will result in you being faced with GRUB menu screen that would have run partially (called 'stages') and you may not get to the part of the 'Operating System' choice screen!! It will be panic time, and rightly so as most users are not expected to handle 'boot loaders' acting funny!! In the Windows world - you get some kernel panic messages like NTLDR not found etc etc., obiviously followed by a 'blue screen of death' with lots of cryptic alphabets, words and numbers in white font - and you have no option but to reformat the disk!!!


In the Linux world, you can recover from this scenerio!! Will mention about the widely used GRUB boot loader recovery (and also because my friend 'Mickey' is stuck up with a funny GRUB!!). There are a few many ways to do it, but let me mention the the most widely used ones (this is standard procedures for most Linux Admin - but can be done by a general user too, as very logical sequence of steps!!).
1. Boot from a Linux Live CD (any one would do like Knoppix, Ubuntu etc.). You can get an extensive list of Linux Live CDs from here.

2. Open a 'Terminal' (its that command line, friend!! Generally found in the 'Accessories' menu item).

3. Check if its a 'root' login (prompt will have a #) else, just type 'su' at the dollar prompt ($). Most live CDs give you a 'root terminal' - check this out.

5. At the root prompt (important to be in the root prompt - signified by a #), type 'grub'. This will take you to a GRUB prompt.


6. At the grub prompt, type 'find /boot/grub/stage1' (without quotes of course!!). You'll get a response like '(hd0)'. In my case I got (hd0,1). You have to next use whatever response shown.

7. From whatever response you got above, at the grub prompt, now type 'root (hd0,1)'.

8. Follow this up by typing 'setup (hd0,1)' at the grub prompt.

9. Thats it - your GRUB is restored - just type 'quit', and reboot the system, making sure you have removed your Live CD from the CD-Drive.

Simple isn't it?? :-) Enjoy

No comments:

Post a Comment