Unashamedly Stolen From CALDERA SYSTEMS SUPPORT KNOWLEDGE BASE

Zen and the Art of Using GRUB,Revisited.
(Ref. #010119-0025)

Being One with the GRand Unified Bootloader

a Technical Guide
by Gerald Homeyer

version 1.0.0

The GRUB bootloader was introduced with Caldera eDesktop 2.4. It is a bootloader similar to LILO that once the user understands its operation, is much more powerful, and easier to setup than LILO.

The basic components of the GRUB bootloader are as follows:

1.The Stage 1 image.
2.The Stage 1.5 image
3.The Stage 2 image
4.The menu.lst text configuration file.
5.The device.map file
6.And of course, the GRUB executable itself.
7.Tips and Tricks!
 

1.The Stage 1 image.

This image is the portion of GRUB that gets the whole process going. It is located in the MBR of the primary boot drive, or in a partition on a drive if called from another bootloader such as Boot Magic.

2.The Stage 1.5 image

This image is a mid-stage image used by grub to read the stage 2 image from the partition on which it resides. It contains the information on how to read the partition type such as ext2, ffs, fat or minix filesystem types.

3.The Stage 2 image

This is the portion of grub that contains the information necessary to load the OS of choice. It contains the actual code to load the kernel image, etc. that boots the OS. It also contains the chainloader image to load an OS such as Windows.

4.The menu.lst text configuration file.

This file is loaded by GRUB to pass arguments to load a specific OS. This file will be covered in more detail later in the technical guide.

5.The device.map file

This file stores the conversion information for the  drives in the system, which map drives from the GRUB naming conventions to the Linux style conventions.

6.The GRUB executable.

This is the program that is used to configure GRUB, as well as to write stage 1 to the MBR or location of choice as well as pass configuration options. It can also be used to manually load an OS from the GRUB prompt.

The menu.lst configuration file.

This file is located in the /boot/grub directory by default on the Caldera distributions. It specifies the various OS's that can be loaded, as well as options for each OS. An example default configuration file would be:
 

#
# /boot/grub/menu.lst - generated by Lizard
#

# options

timeout = 5
splashscreen = (hd0,1)/boot/message.col24
default = 0
title = Linux
root = (hd0,1)
kernel = /boot/vmlinuz-pc97-2.2.14-modular vga=274 noapic nosmp
debug=2 root=/dev/hda1
title = Windows
chainloader = (hd0,0)+1
 

This configuration file would be for a dual boot system, booting Linux and Windows, with Linux installed to the second partition of the first hard drive, and Windows installed to the first partition of the first hard drive. Please also note that although the above example, as would be generated by Lizard during the installation of the OS will work, it is not the preferred syntax for all the options. Also note that the = is not required in the option lines. title Linux would work the same as title = Linux. Options do need to be separated by a return however, one option section per line.

The timeout= option is used to determine the amount of time you have  to make a selection from the list until the system will automatically boot from the default option.

The splashscreen = line is used by eDesktop to load the graphical boot splashscreen. If you want to disable the graphical boot and use a conventional text based boot, you will need to comment out this line with a # (or remove it), as well as change any vga= options on the kernel lines to read vga=normal (standard 80x25 text display) or vga=ext (extended 80x50 text display).

The default = line determines the default OS and options that are loaded. Each section of the menu.lst is  numbered starting with 0. In this example, if you wanted Windows to be the default boot, you would change this to a value of 1.

The title = line is used to name the OS option as it will appear in the GRUB boot menu. This is a line that anything goes (within reason), but it is a good idea to keep it simple.

The root = line sets the root partition of the OS. In the case of a Linux OS, this is the partition that contains the /boot/grub directory, and not necessarily the root partition of the OS itself.

The kernel = line is to specify the kernel location and options for a Linux system. In LILO, options are passed on the append = line. In GRUB, they are simply added to the kernel line after the name of the kernel itself. This is where options such as the vga= line is set. Also, for example, if you were running a SMP capable machine, this is where you would remove the noapic and nosmp lines to enable the additional processors (this may already be set during installation on SMP machines).

The chainloader line is used to tell GRUB to boot to the specified location and pass control to the bootloader present in that location. This is used for booting Windows and other OS's that GRUB cannot directly boot.

Not shown but useful is the fallback = option. This is used in case the default option cannot boot (OS on a removable drive, etc.). In this example, if a fallback = 1 line was specified, and Linux (the default option) could not boot, the system would then try to boot Windows. This line should be specified following the default = line.

Note that there can also be other options that need to be specified,  many of which are shown in the examples below.
 

GRUB uses a different naming convention than lilo for the hard drives and their partitions. For example, the first partition of the first IDE hard drive in GRUB would be in most cases (hd0,0), where in Linux it would be /dev/hda1.

In the above example, the Windows option would be more properly written as in the following example:

title = Windows
root = (hd0,0)
makeactive
chainloader +1

You do not need to change this on a default installation. This is shown for convenience if you are writing the file from scratch, or adding a Windows section to an existing menu.lst.

GRUB is capable of booting many different OS's. The following are examples of the syntax used in the menu.lst file for other OS's:

# For booting the GNU Hurd

title GNU/Hurd
root (hd0,0)
kernel /boot/gnumach.gz root=hd0s1
module /boot/serverboot.gz

# For booting Mach (getting kernel from floppy)

title Utah Mach4 multiboot
root (hd0,2)
pause Insert the diskette now^G!!
kernel (fd0)/boot/kernel root=hd0s3
module (fd0)/boot/bootstrap

# For booting FreeBSD (getting kernel from floppy)

title FreeBSD
root (hd0,2,a)
kernel (fd0)/kernel

# For booting OS/2

title OS/2
root (hd0,1)
makeactive

# chainload OS/2 bootloader from the first sector

chainloader +1

# This is similar to "chainload", but loads a specific file chainloader /boot/chain.os2

# For booting Windows NT or Windows95/98/Me

title Windows NT / Windows 95 boot menu
root (hd0,0)
makeactive
chainloader +1

# For loading DOS if Windows NT is installed
# chainload /bootsect.dos

For booting Windows 95/98/Me directly, the syntax would be as in the full example above and as shown below:
 

title = Windows
root = (hd0,0)
makeactive
chainloader +1

The menu.lst file is located by default in the /boot/grub directory.  It can however be located anywhere you like, and can be called anything you like. It is recommended that you keep the naming convention and location so that the file can be easily found, but if  you so desire, it can be located anywhere.

The order that your various OS's are listed in the menu.lst file is  the order that they will be listed in the GRUB boot menu. Be sure however that the default and fallback lines reflect the options that you want to boot as default and backup options.

The device.map file.

This file is used by grub to map GRUB based drive names to the Linux counterparts. An example of this file would be:
 

(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdb
(hd2) /dev/hdc
(hd3) /dev/sda
(hd4) /dev/sdb

In this example, the system has the CD-ROM located at /dev/hdd (IDE secondary slave). You will notice that it is not listed in the device.map file. CD-ROMS are not listed as GRUB does not consider them to be a boot capable hard drive. The device.map file will only list the drives that were installed when the OS was installed. If, for example, you changed the order of the drives (swapped primary master and slave drives for example) or added another hard drive to the system, this file may need to be edited to reflect those changes.

The GRUB executable.

The grub executable is the heart of everything that GRUB does. It  can be used to boot a system that has a corrupt MBR, or to boot an alternative that is not listed in the menu.lst file. When GRUB is run, you will see a GRUB prompt as in the following example:

GRUB version 0.5.94 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB

lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ]
grub>

This can be used to boot a system (if for example the menu.lst was  not specified, or on a system without an existing menu.lst), as well as to configure and install GRUB.

Booting a system from the GRUB prompt:

Booting the system from a GRUB prompt is simple and straight-forward. You will specify options in the same order that they are listed in the menu.lst examples, with an extra step to get it all going. For example, to boot a Linux system from the GRUB prompt, you would enter commands as in the following example. The example would be for a system with Linux installed on the first partition of the first drive, with the /boot/grub directory located off / and not in its own partition.

grub>root (hd0,0)

grub>kernel = /boot/vmlinuz-pc97-2.2.14-modular root=/dev/hda1

grub>boot

The first line, root (hd0,0) tells GRUB where the root is located.  Note once again that this is the root for GRUB, and not the filesystem root /. This is the location of the Stage 1, 1.5 and 2 image files.

The second line, kernel = /boot/vmlinuz-pc97-2.2.14-modular  root=/dev/hda1, is the location of your kernel, and any options that need to be passed to the kernel. For example, if the root of the OS (/) was located on a different partition that /boot/grub, you would specify it on this line. Other options such as noapic, nosmp, debug=2 and vga=normal would also be specified on this line.

The third line, boot, is the magic command that gets the whole thing  going. It uses the information specified before it to boot the OS. In this example, it would try to load the kernel from /boot and use
/dev/hda1 as the root filesystem.

Other OS's would be similar, using the options required for the particular OS entered on the GRUB command line before the boot command is given.
 

Installing GRUB on your system.
 

Installation of GRUB on your system is also simple and  straight-forward. Once at the GRUB prompt, enter the following to install GRUB.

grub>root (hd0,0)

This is the location of the root for GRUB, NOT the root of your filesystem. This is the drive and partition that have your stage1, 1.5 and stage 2 files (located in /boot/grub). With GRUB treating all hard drives, IDE SCSI and others all the same, it can become confusing which drive actually contains the grub root. Luckily, there is a very simple way to find where these files are located. From the GRUB command prompt, type the following command:
 

grub>find /boot/grub/stage1

This will return a response similar to the following:

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

If you have multiple drives that contain this file, it will list all locations that it was found at.

Once this is set, type the following:

grub>setup (hd0)
 

This is the location that you want the stage1 image to load to.  (hd0) would load stage1 to the MBR of the first hard drive. This is the desired option for booting multiple OS's, using GRUB as the primary bootloader/menu. If for example you want to load GRUB to the first partition of the first drive, you would issue the command:

grub>setup (hd0,0)

This would be the preferred option if you either do not want to use the MBR for GRUB, or you are using another bootloader such as Boot Magic to boot the system, and want to chainload GRUB from that other
bootloader.

Typing this command will return something similar to the following:

grub> setup (hd0)

Run "embed /boot/grub/e2fs_stage1_5 (hd0)"

16 sectors are embedded.

Run "install /boot/grub/stage1 d (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2"
 

grub>

This will have successfully loaded grub, although it does have a problem. It will not have installed GRUB to use your menu.lst file. The solution to this is simple. Since GRUB has now provided you with all the necessary options for the stage1, 1.5 and 2 installation, simply duplicate the following portion of the last line:

install /boot/grub/stage1 d (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2

and add (hd0,0)/boot/grub/menu.lst to the end so that the line would read:
 

install /boot/grub/stage1 d (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 (hd0,0)/boot/grub/menu.lst
 

This will install GRUB so that it uses the /boot/grub/menu.lst file for your boot options. Note that the install lines shown above are all on one line, although they may wrap due to length as they did in the formatting of this document.

Once this is completed, type quit to exit the GRUB menu, and restart your system. You should now boot using GRUB, with the options specified in your menu.lst file presented to you on boot.
 

Tips and Tricks!

There are a few other things that you can do to help make configuration easier and boot otherwise troublesome configurations.

One of these, which helps with installation if you have more than one drive with a /boot/grub/stage1 file, is the following.

Create a file located in /boot/grub named after the drive you're on. For example, you have a system that has two ide hard drives and a SCSI drive, and you're not sure which shows up as which to GRUB. On one IDE
drive, create a file (the touch command works great for this) in /boot/grub called ide1, or anything else that makes sense to you that you can remember. On the other IDE, create an ide2, and on the scsi a file named scsi. Then, when you're in the grub menu, you could type grub>find /boot/grub/scsi and it will report that drive to you. Since the file only exists in the one location, you'll get that drive and that drive only!

How to create a GRUB boot floppy with the menu interface:
 

1. Create filesystem in your floppy disk. For example:

$ mke2fs /dev/fd0

2. Mount it on somewhere, say, `/mnt'.

3. Copy the GRUB images to `/mnt/boot/grub'. Only `stage1',

`stage2' and `menu.lst' are necessary. You may not copy "stage1.5"s.
 

4. Run the following command:

$ /sbin/grub --batch <

root (fd0)
setup (fd0)
quit
EOT

How to boot Windows off a drive OTHER than the first drive in the system:
 

By default, Windows will run only off the first drive in the system, referred to as C: in Windows. Some systems will allow you to swap drives around on a BIOS level to do this, but with GRUB it is not necessary. To swap the BIOS mapping from within grub, add the following commands:

grub> map (hd0) (hd1)
grub> map (hd1) (hd0)

This sets a 'logical' drive swap, and sets in the case of this  example, the first drive to the second and the second to the first. Viola! Problem solved. These can also be set in your menu.lst file before the chainloader is called to do this automatically.

There is much more information, tips, tricks and troubleshooting in the info pages for GRUB. These are accessed by typing info grub from a command line in Linux. If you have further questions or desire to know
more about the operation of GRUB, I highly recommend reading this information

Product: Technical Guides
Date Created: 10/26/2000 03:42 PM
Ref. #: 001026-0017
Category: Booting / Starting Linux
Date Updated: 10/26/2000 03:51 PM