Monday, January 11, 2010

Restoring Grub With A LiveCD

I enjoy installing different distributions that I usually find first on Distrowatch. This is the premiere Linux site for finding what's the latest on your favorite distro. I like to install the Debian derivatives like Ubuntu, Mint, Mepis, AntiX and now the most recent I have downloaded, elive. I have also cut my Linux teeth on Damn Small Linux, Zenwalk, Slax, Back Track and a few others. But the common denominator is I start looking and keep current on the Distrowatch site. This site is a great resource for the Linux enthusiast.

It was here I found the terrific article on Restoring Grub written by Jesse Smith in the Questions and Answers section. I felt it was a well written and easy to understand article that covers an important piece of information. No one wants to see the fatal message No Operating System found or Grub errors 17, 22 or 25. (These are the three I've seen in my short Linux experience.) Here is the article in its entirety re-posted with permission.

Restoring GRUB

Can't-boot-any-more asks: Distro hopping wiped out my GRUB. How can I reconstruct it?

DistroWatch answers: Sometimes when making changes to a hard drive, such as installing a new operating system, the disk's master boot record (MBR) will get wiped or corrupted. When that happens, GRUB will no longer function. This has the unfortunate side effect of preventing the user from being able to boot their operating system and, in those cases, it's important to be able to get the system up and running again, preferably without re-installing the operating system(s) from scratch.

The easiest way to get GRUB back on-line is with a live CD. It doesn't really matter which live CD, so long as it comes with a copy of GRUB. Place the live CD into the computer and boot from it. We're then going to venture into command-line territory. The next thing to do is run the "grub" command as root or, if you are running a live CD that uses sudo, run "sudo grub". This will start GRUB and provide us with a prompt.

     grub>

We'll then find out where the GRUB files are located:

     grub> find /boot/grub/stage1

The find command will return a disk location for us. Probably "(hd0,0)" or "(hd0,1)". We now know where the GRUB files are stored. Next, we'll tell GRUB to use this location in the future. In the following step, type "root", followed by the location we were given above. In my case:

     grub> root (hd0,1)

GRUB now knows where its files are located and we need to re-setup GRUB in the master boot record. To do this, we type:

     grub> setup (hd0)

The above step should work for most people, who have GRUB installed in the MBR. For folks who have installed GRUB onto a partition, the "setup" command can be modified to include the partition number. The catch is, you need to know where you originally installed GRUB. In these cases, remember that GRUB starts counting partitions from zero, not one. So, for example, if GRUB was installed on the third partition of the first hard drive, the "setup" command will look like this:

     grub> setup (hd0,2)

When we get back to the prompt again, we can quit GRUB:

     grub> quit

And then reboot the computer. Remove the live CD from the drive and we should be back to normal.

No comments:

Post a Comment

Techbits reserves the right to not publish comments but will only exercise this right if a comment is vulgar, completely off-topic or spam.