Skip to content Skip to main navigation Skip to footer

Grub Article #1 – Installation Notes and Background Information

Important: This article applies only to Grub legacy

Grub is the most commonly used boot loader for Linux distributions. Its primary distinction from LILO is that it provides an interactive shell at boot time which can be used to boot items not listed on its menu. From that shell you can also install or reinstall GRUB to a drive or partition. You can also edit existing boot menu items on the fly at boot time.

This article is intended to provide BootIt BM users with information on installing Grub during a Linux installation, and also some additional background information.  Information on how to reinstall GRUB, if necessary, is covered in Grub Article #2 - How To Reinstall Grub. Information on how to recover from GRUB being installed to the MBR is covered in Grub Article #3 - How to recover from Grub being installed to the MBR

GRUB users should also be aware that the Grub manual is available online.

Installing Grub during a Linux installation:

Installing GRUB originally is usually done by the Linux installer at the time you install a distribution on your system. During the installation, you will typically be asked where you want to install the GRUB boot code. For BootIt BM users, the correct answer to that question is to install GRUB to a Linux partition, and not to the MBR.

When installing GRUB to a Linux partition, the usual choices would be to either the root partition, or to the /boot partition if you have one. What that does is install the GRUB boot code in the first sector (or sectors) of that partition. Doing that will cause the GRUB menu to appear when you boot from that partition in BootIt BM.

The incorrect choice for BootIt BM users is to install GRUB to the MBR. Because BootIt BM itself occupies the MBR, installing GRUB there will overwrite BootIt BM's MBR code. If you do install GRUB to the MBR, BootIt BM will not appear the next time you reboot the system. To get it back, you will then need to reactivate BootIt BM by booting from the installation floppy disk or CD and choosing the Reactivate option.

Installing GRUB to the MBR can also overwrite BootIt BM's EMBR area, which is a more serious problem. In this case, there will be no Reactivate option when you boot from the BootIt BM installation disk, and BootIt BM will have to be reinstalled. For more information on how to recover from GRUB overwriting the MBR and EMBR, see this KB article:

GRUB Article #3 - How to recover from GRUB being installed to the MBR

You can also provide yourself with an easy recovery path in advance by backing up the drive (or desired partitions on the drive) before installing Linux. The backup image will include a copy of  the first track of the drive. In the event of trouble, you can later restore the backup image and the EMBR (located in the first track). Please note that restoring the first track will also restore your the partition table, so any partition changes made since the backup will be lost.

Important files and utilities to know about:

Name and location
Purpose Notes
/boot/grub/device.map Text file calling out the relationship between Linux and GRUB drive designations.
Generated by 'grub-install' if file doesn't already exist in /boot/grub
/boot/grub/menu.lst Text file defining the GRUB boot menu
/boot/grub/menu.lst is a link to /boot/grub/grub.conf on Redhat and Redhat-based systems
/sbin/grub GRUB shell that runs from within Linux
GRUB can be installed or reinstalled from here
/sbin/grub-install Script that invokes /sbin/grub and installs GRUB to a specified location
Also generates device.map file and populates /boot/grub with GRUB image files on first install.
/sbin/update-grub Script that automatically generates and updates /boot/grub/menu.lst
Specific to Debian and Debian- based systems
/boot/grub/stage1
512 byte boot sector image file containing initial boot code
Gets installed in MBR, partition boot sector, or floppy boot sector
/boot/grub/stage2
Core image file for GRUB.
Executes GRUB shell and menu interface.
/boot/grub/*_stage1_5
A set of intermediate stage 1.5 image files, each one specific to just one file system.
Locates Stage 2 via the file system it knows. Is embedded  outside of any file system


How GRUB designates drives and partitions
:

The way GRUB designates drives and partitions differs from how Linux itself does it. GRUB numbers drives, starting from zero, in BIOS order - the same as BootIt BM does.  The first BIOS hard drive is (hd0), the second is (hd1), and so on. Similarly, it numbers the 4 possible primary partitions on a drive from 0 to 3. For volumes in an extended partition, GRUB numbers those starting from 4, regardless of how many primaries exist on the drive.

The syntax GRUB uses to designate a drive/partition combination follows the form of (hdx,y), where 'x' is the hard drive number, and 'y' is the partition number. Here are some examples:

First primary partition on first hard drive: (hd0,0)
Third primary partition on second hard drive: (hd1,2)
First volume on first hard drive: (hd0,4)
Second volume on third hard drive: (hd2,5)

GRUB designates entire drives by using a simpler form of the above. The entire first hard drive would be (hd0), the second would be (hd1), and so on. For floppy drives, GRUB designates the first one as (fd0), and so on if you have more.

Explanation of the GRUB boot stages:

GRUB boots in either 2 or 3 stages, depending on where it is installed.  The 3 possible stages are Stage1 (always used), Stage 1.5 (sometimes used), and Stage 2 (always used).

Stage 1
is always used, and this code fits into a 512 byte sector. Stage 1 can reside in the first sector of a floppy drive, or in the MBR sector of a hard drive, or in the first sector of a partition. The function of Stage 1 is to find either Stage 1.5 or Stage 2, and pass control over to them. Stage 1 finds Stage 1.5 or Stage 2 by means of physical block addresses that are encoded into the Stage 1 sector when GRUB is installed.

Stage 2 is always used, and it gains control of the boot process from either Stage 1 or Stage 1.5. It will be located at /boot/grub/stage2 on most Linux systems.  It can also exist outside of any file system, such as when used on a GRUB floppy disk. 

Stage 2 is the core of GRUB. It displays the boot menu, and also contains the GRUB shell from which GRUB commands can be manually entered and executed. Stage 2 is also capable of editing the boot menu commands on the fly at boot time. Stage 2 will display the boot menu if it finds the boot menu file (/boot/grub/menu.lst). If not, it will leave you at the GRUB shell command prompt.

Stage 1.5 is not strictly required, and it is not always used. When used, Stage 1.5 will gain control from Stage 1, and then pass control over to Stage 2. Stage 1.5 understands the file system in use, so it is capable of locating Stage 2 as a file within a file system, rather than the physical block addresses that Stage 1 uses.  If the physcial location of the Stage 2 file changes, Stage 1.5 will still be able to find it via the file system, while Stage 1 will not. GRUB has several Stage 1.5 images available. Each of these images understands one file system, and they are named accordingly.

The decision to use (or not use) Stage 1.5 is made by the GRUB installation code, depending on whether or not there is room for it.  Stage 1.5 is too large to fit into a single 512 byte sector, so there is not always a place to put it.

Basically, if GRUB is installed to an Ext2/Ext3 partition, Stage 1.5 will not be installed because it won't fit. However, if GRUB is installed to a ReiserFS partition, or to the MBR, then Stage 1.5 will be installed. The case of GRUB being installed to the MBR creates a problem for BootIt BM users, because  Stage 1.5 will be installed in the sectors between the MBR and the start of the first partition. This will overwrite BootIt BM's EMBR area because it uses the same sectors. Again, BootIt BM users will NOT normally want to install GRUB to the MBR.

Note: You can prevent Stage 1.5 from being installed by not having the Stage 1.5 image files present in the GRUB image directory (normally /boot/grub).

The GRUB Boot Menu:

The boot menu is defined in the text file /boot/grub/menu.lst on most Linux systems, and is displayed by Stage 2. That file consists of one or more boot menu items, and each of those contains one or more GRUB commands. For most practical purposes, you have 3 basic options at the GRUB boot menu:

1) Choose a boot menu item and boot it.
2) Edit a boot menu item on the fly by pressing <e>
3) Go to the GRUB command prompt by pressing <c>


 

 

Was This Article Helpful?

1