wiki:bootloaders/grub
close Warning: Failed to sync with repository "(default)": [Errno 12] Cannot allocate memory; repository information may be out of date. Look in the Trac log for more information including mitigation strategies.

Version 6 (modified by M.N. Akhiezer, 7 years ago) (diff)

Made some terminology/capitalisations, consistent across bootloader wiki docs.

Grub Legacy for CLFS Builds

Needed Files

Grub Legacy ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz

256-byte inode Patch ftp://ftp.osuosl.org/pub/clfs/conglomeration/grub/grub-0.97-256byte_inode-1.patch
EXT4 Patch ftp://ftp.osuosl.org/pub/clfs/conglomeration/grub/grub-0.97-ext4-1.patch
Fixes Patch ftp://ftp.osuosl.org/pub/clfs/conglomeration/grub/grub-0.97-fixes-1.patch
x86_64 Fixes Patch ftp://ftp.osuosl.org/pub/clfs/conglomeration/grub/grub-0.97-use_mmap-1.patch

Apply the Patches

These patches are required for both the Boot Method and the Final-System sections of the book.

patch -Np1 -i ../grub-0.97-use_mmap-1.patch
patch -Np1 -i ../grub-0.97-fixes-1.patch
patch -Np1 -i ../grub-0.97-256byte_inode-1.patch
patch -Np1 -i ../grub-0.97-ext4-1.patch

Changes for Cross-Tools Section

This build is only required if you're using the Boot Method of the build.

Build Grub Legacy

./configure --prefix=/usr \
   --build=${CLFS_HOST} --host=${CLFS_TARGET}
make
make DESTDIR=${CLFS} install
mkdir -v ${CLFS}/boot/grub
cp -v ${CLFS}/usr/lib/grub/*/stage{1,2} ${CLFS}/boot/grub

Changes for Final-System Section

This build is only required for the Final-System section of the book.

Build Grub Legacy

The 'make check' is optional.

./configure --prefix=/usr
make
make check
make install
mkdir -pv /boot/grub
cp -v /usr/lib/grub/*/stage{1,2} /boot/grub

The FHS stipulates that the bootloader's configuration file should be symlinked to /etc/{Bootloader Name}. The bootloader's configuration file is created in the following section. To satisfy this requirement for GRUB, issue the following command:

mkdir -v /etc/grub &&
ln -sv /boot/grub/menu.lst /etc/grub

Installing 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.

After running the 'grub' command. tell GRUB where to search for its stage{1,2} files. The Tab key can be used everywhere to make GRUB show the alternatives. Install grub to the MBR and then quit.

grub
root (hd0,3)
setup (hd0)
quit

Creating the Boot Menu

Create a "Boot Menu" for grub by defining the boot menu; ${CLFS} is only required if you are using the Boot Method.

cat > ${CLFS}/boot/grub/menu.lst << "EOF"
# Begin /boot/grub/menu.lst

# By default boot the first menu entry.
default 0

# Allow 30 seconds before booting the default.
timeout 30

# Use prettier colors.
color green/black light-green/black

# The first entry is for CLFS.
title CLFS SVN-20100101
root (hd0,3)
kernel /boot/clfskernel-2.6.30.5 root=/dev/hda4
EOF

Add an entry for the host distribution if desired. It might look like this:

cat >> ${CLFS}/boot/grub/menu.lst << "EOF"
title Red Hat
root (hd0,2)
kernel /boot/kernel-2.6.5 root=/dev/hda3
initrd /boot/initrd-2.6.5
EOF

If dual-booting Windows, the following entry will allow booting it:

cat >> ${CLFS}/boot/grub/menu.lst << "EOF"
title Windows
rootnoverify (hd0,0)
chainloader +1
EOF