GRUB2 is a modular, multiboot-capable bootloader for many operating systems that can be used as a payload for coreboot.
How to build GRUB2 as a payload
It's recommended that you use the latest SVN version of GRUB, since coreboot support is being actively developed and evolves rapidly.
$ svn co svn://svn.savannah.gnu.org/grub/trunk/grub2 $ cd grub2 $ ./autogen.sh $ ./configure --with-platform=coreboot $ make $ MODULES="normal ls cat help ext2 iso9660 reiserfs xfs fat part_msdos part_gpt ata serial memdisk multiboot linux minicmd configfile search tar at_keyboard" $ ./grub-mkelfimage -d . $MODULES -o ..../coreboot-v3/payload.elf --prefix='(ata0)/boot/grub'
See below about module selection.
GRUB2 modules
GRUB2 is a modular system, you can include whichever modules you need into the image. A few noteworthy ones are:
*normal, ls, cat, help: These make the user interface more complete/usable. *ext2, iso9660, reiserfs, xfs, fat: Commonly used filesystems. *part_msdos, part_gpt: Commonly used partition maps. *ata: Driver for ATA / ATAPI disks. *serial: Driver for serial terminal. *memdisk: Allows you to embed a virtual disk into the GRUB image (see below) *multiboot: Loader for Multiboot kernels (such as the kernel of [http://www.netbsd.org/ NetBSD] or [http://www.opensolaris.com/ OpenSolaris]) *linux: Loader for [http://www.kernel.org/ Linux] bzImages. *boot: Needed by all loaders.
You might also want to check the CommandList.
Building a memdisk image
Build your memory disk using your preferred filesystem. For example, tar. Then load the memdisk module, and include the image in your build.
$ mkdir -p boot/grub (put a grub.cfg file in boot/grub, see example below) $ tar -cf memdisk.tar boot $ MODULES="see above :-)" $ ./grub-mkelfimage -d . $MODULES -o ..../coreboot-v3/payload.elf -m memdisk.tar --prefix='(memdisk)/boot/grub'
GRUB will automatically use the the memdisk for finding modules and the grub.cfg file.
Hints and Tricks
Loading grub.cfg from disk
It is suggested that grub.cfg is contained in a memdisk/tar image. This grub.cfg can be used to load other configuration files from any mass storage media, or to load another Multiboot payload (e.g. GRUB itself).
echo -n "Press `ESC' to enter the menu... "
# If disks don't have time to spin, you might want to increase
# this number.
if sleep --verbose --interruptible 2 ; then
set timeout=0
fi
set default=0
set fallback=1
menuentry "Search & load /boot/multiboot.img" {
search -s -f /boot/multiboot.img
if multiboot /boot/multiboot.img ; then
boot
fi
unset timeout
}
# For separate /boot partition.
menuentry "Search & load /multiboot.img" {
search -s -f /multiboot.img
if multiboot /multiboot.img ; then
boot
fi
unset timeout
}
menuentry "Search & source /boot/grub/grub.cfg" {
search -s -f /boot/grub/grub.cfg
source /boot/grub/grub.cfg
unset timeout
}
# For separate /boot partition.
menuentry "Search & source /grub/grub.cfg" {
search -s -f /grub/grub.cfg
source /grub/grub.cfg
unset timeout
}
menuentry "Reboot" {
reboot
}
Building Coreboot with GRUB2 payload
Please consult the documentation that Coreboot for the build instructions once it becomes available. As of June 2009, building Coreboot is not well documented. Following script will build coreboot.rom and run it under qemu. The script should be run in the GRUB2 source directory after it has been compiled for the coreboot platform. coreboot-v2 is assumed to be checked out into a directory under the same directory and the GRUB2 sources. Instead of memdisk, a CD-ROM image is used, which allows all modules to be included.
#!/bin/sh set -e GRUB_SRC=`pwd` COREBOOT_SRC=../coreboot-v2 QEMU_VGABIOS=/usr/share/qemu/vgabios-cirrus.bin MODULES="at_keyboard iso9660 ata" LISTS="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst" ./grub-mkelfimage -d . $MODULES -o payload.elf --prefix='(ata2)/' genisoimage -r -J -o modules.iso *.mod $LISTS cd $COREBOOT_SRC/targets rm -rf emulation/qemu-x86/qemu-x86 cp $GRUB_SRC/payload.elf emulation/qemu-x86/ ./buildtarget emulation/qemu-x86 cd emulation/qemu-x86/qemu-x86 make PAYLOAD=$GRUB_SRC/payload.elf cp -f $QEMU_VGABIOS vgabios-cirrus.bin qemu -L . -bios coreboot.rom -cdrom $GRUB_SRC/modules.iso
To Do
USBSupport (in progress).
Check some research papers for more information concerning this software.
How to help and report bugs, etc
Contact the GRUB upstream mailing list for more information.