Knowledge Base Glossary       Exit
(how to) Search  

Browse by Category
Knowledge Base > Operating Systems > Linux > Grub Article #2 - How To Reinstall Grub (Grub Legacy)

Grub Article #2 - How To Reinstall Grub (Grub Legacy)

Important: This article is specific to Grub legacy (the original Grub). For the equivalent article that is specific to Grub2, please see How To Reinstall Grub2

This article covers the basics of reinstalling Grub, if it becomes necessary to do so. It is written primarily from the perspective of BootIt BM users, who will need to have Grub installed in a partition's boot sector, rather than in the MBR.

The need to reinstall Grub can come about for several reasons, but usually it is the result of changing your drive/partition configuration in some way. In most cases, the Linux installation itself will still be intact, and you just need to reinstall the Grub boot code so that BootIt BM can boot the partition again.

For some introductory and background information on Grub that may help you better understand this article, please refer to Grub Article #1 - Installation Notes and Background Information.

Before getting started, it should be mentioned that some distributions provide a way to reinstall Grub by booting from the installation CD and choosing that option in some manner. But since the procedure to do this can vary from one distribution to another, you will need to refer to your distribution's documentation for instructions. This article will, instead, cover a generic method of reinstalling Grub that should work for any distribution.
 

What you will need
The method of reinstalling Grub covered here will use the native Grub shell, using commands entered from the Grub prompt (grub>). This is the preferred and most reliable way to install or reinstall Grub. 

On a fully working Linux installation, the native Grub shell is reached by booting up to the Grub boot menu, and then pressing <c> to get to the Grub command prompt (grub>). If your Linux installation still boots far enough so that you can get to the Grub prompt, then you can reinstall Grub from there.

If not, you will need a Grub boot disk. To obtain one, you can download grub.zip from the TeraByte Unlimited ftp site. The zip file contains images from which you can create either a Grub floppy disk or a Grub CD or DVD.  Both the Grub floppy and the Grub CD/DVD will boot the system up to the Grub prompt. If you prefer, the Grub manual also provides instructions on how to create a bootable floppy disk, or a bootable CD/DVD disc.
 

Resinstalling Grub from the native shell
Once at the Grub prompt, it is suggested that you follow these steps:
1.  Run find to determine which partition contains the /boot directory
2.  Run root to tell Grub which partition contains the /boot directory
3.  Run setup to install Grub to a partition boot sector

The remainder of this article will cover the steps listed above in detail.

1.  Run find to determine which partition contains the /boot directory

This can be done with Grub's find command. The /boot directory contains the grub directory, which is where Grub will find the files it needs to install. The /boot/grub directory should contain the file 'stage1', which is the file we will look for with the find command. In most cases, the /boot directory will be included in the root partition, so that the path to stage1 will be /boot/grub/stage1. To determine which partition contains this path/file, run the following command from the Grub prompt:

grub> find  /boot/grub/stage1

If the search is successful, Grub will return the partition in Grub notation, such as shown below:

grub> find  /boot/grub/stage1
  (hd0,1) 

In this case, partition (hd0,1) contains the /boot/grub directory. If the find command returns an error (Error 15:  File not found), this likely means that you have a separate /boot partition. In that case, the path to the file stage1 will be /grub/stage1 instead, and so the following command should find it:

grub> find  /grub/stage1
  (hd0,1) 

Please note that (hd0,1) shown above is just an example. The actual partition in your case may very well be different. The notation (hd0,1) means the 2nd partition on drive hd0, while the notation (hd0,0) would mean the 1st partition on drive hd0.

If neither find command above can find the stage1 file, then reinstalling Grub is not going to work.  However, keep in mind that if  you are NOT limiting primaries in BootIt BM, not being able to find the file above could just mean that the Linux partition is currently not in the MBR, and therefore is not visible to Grub.

2.  Run the root command to tell Grub which partition contains /boot

Using the partition determined in step 1 above, run the root command as shown below. This command tells Grub which partition contains the /boot directory, which is where it can find its required files.

grub> root (hd0,1)

If successful, you will get a response similar to that shown below. It should identify the filesystem on the partition, and the partition type  - which is normally type 83h for Linux partitions. If using reiserfs, the response should show that instead.

grub> root (hd0,1)
 Filesystem is type ext2fs, partition type 0x83

If the root command returns an error, recheck the partition determined in step 1. Also recheck the root command you entered above. If the root command does not return with a successful response, then reinstalling Grub in step 3 below is not going to work.

3.  Run the setup command to install Grub to a partition boot sector

The final step is to install Grub to a partition boot sector using the setup command. In most cases, you will want to install Grub to the Linux root partition. However, if you do have a separate /boot partition (as determined in step 1 above), you also have the option of installing it there. Regardless of where you install it, the important thing is that the Linux boot item in BootIt BM must be configured so that it boots from the partition that you install Grub to.

The setup command is used as follows:

grub> setup  (hd0,1)

In this case, we are installing Grub to partition (hd0,1), the second partition on drive hd0. When running the setup command, you will get a series of output lines from Grub. While a couple of them may indicate a failure involving stage1_5, as long as the last message says it succeeded, then the install did succeed. The Linux partition you just installed to should now be bootable from BootIt BM.

Additional information on installing or reinstalling Grub from its native shell can be found in this section of the Grub manual.


How helpful was this article to you?


powered by Lore