Chapter 8. Making the LFS System Bootable

8.4. GRUB-0.97

8.4.1. Installation of GRUB

Your shiny new LFS system is almost complete. One of the last
things to do is to ensure that the system can be properly booted.

Caution

This package will only build for x86 and x86_64 architectures
containing 32-bit libs. If you chose to build on x86_64 without
32-bit libraries (no multilib), then you must use LILO instead.
Information on “boot
loading” for other architectures should be available
in the usual resource-specific locations for those architectures.

This package is known to have issues when its default optimization
flags (including the -march
and -mcpu options) are
changed. If any environment variables that override default
optimizations have been defined, such as CFLAGS and CXXFLAGS,
unset them when building GRUB.

Start by applying the following patch to allow for better drive
detection, fix some GCC 4.x issues, and provide better SATA support
for some disk controllers:

patch -Np1 -i ../grub-0.97-disk_geometry-1.patch

By default, GRUB doesn't support ext2 filesystems with 256-byte
inodes. Fix this by applying the following patch:

patch -Np1 -i ../grub-0.97-256byte_inode-1.patch

Prepare GRUB for compilation:

./configure --prefix=/usr

Compile the package, but use custom optimization flags to prevent
an error flagged in the test routines:

Replace i386-pc with whatever
directory is appropriate for the hardware in use.

The i386-pc directory contains a
number of *stage1_5 files, different
ones for different file systems. Review the files available and
copy the appropriate ones to the /boot/grub directory. Most users will copy the
e2fs_stage1_5 and/or reiserfs_stage1_5 files.

8.4.2. Configuring GRUB

Boot loading can be a complex area, so a few cautionary words are
in order. Be familiar with the current boot loader and any other
operating systems present on the hard drive(s) that need to be
bootable. Make sure that an emergency boot disk is ready to
“rescue” the computer if the
computer becomes unusable (un-bootable).

The procedure involves writing some special GRUB files to specific
locations on the hard drive. We highly recommend creating a GRUB
boot floppy diskette as a backup. Insert a blank floppy diskette
and run the following commands:

Remove the diskette and store it somewhere safe. Now, run the
grub shell:

grub

GRUB uses its own naming structure for drives and partitions in the
form of (hdn,m), where
n is the hard drive number
and m is the partition
number, both starting from zero. For example, partition
hda1 is (hd0,0) to GRUB and hdb3 is (hd1,2). In contrast to Linux, GRUB does
not consider CD-ROM drives to be hard drives. For example, if using
a CD on hdb and a second hard drive
on hdc, that second hard drive would
still be (hd1).

Using the above information, determine the appropriate designator
for the root partition (or boot partition, if a separate one is
used). For the following example, it is assumed that the root (or
separate boot) partition is hda4.

Tell GRUB where to search for its stage{1,2} files. The Tab key can be used
everywhere to make GRUB show the alternatives:

root (hd0,3)

Warning

The following command will overwrite the current boot loader. Do
not run the command if this is not desired, for example, if using
a third party boot manager to manage the Master Boot Record
(MBR). In this scenario, it would make more sense to install GRUB
into the “boot sector” of
the LFS partition. In this case, this next command would become
setup (hd0,3).

Tell GRUB to install itself into the MBR of hda:

setup (hd0)

If all went well, GRUB will have reported finding its files in
/boot/grub. That's all there is to
it. Quit the grub
shell: