GRUB

From OSDev.wiki
Revision as of 18:24, 30 March 2011 by osdev>Alfaomega08
Jump to navigation Jump to search
This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.

GRUB 2 is the GNU Project's next-generation bootloader. It has a more complete feature set than GRUB 0.97 (commonly referred to as "GRUB Legacy"). Still, all things considered, GRUB Legacy is more mature and most of the available documentation is for GRUB Legacy (hence the brief page).


History

GRUB 2 started its life as the PUPA (note the pun) research project and was rewritten from the ground up. Since then GRUB 2 (actually at time of update 1.97) has grown more stable and even hobby operating systems are starting to make use of the new bootloader instead of GRUB Legacy.

Features

  • Basic scripting support
  • GUI (better bootsplash support, custom colors, custom themes, ...)
  • Memory management
  • Cleaner design
  • Better portability
  • Internationalization
  • Rescue mode

Upgrading from GRUB Legacy

WARNING: These steps have not been tested very well yet. Use at your own risk!

Since GRUB 2 is very different from GRUB Legacy, the directions for getting your kernel up and running are different. GRUB 2 differs from GRUB Legacy in that to implement all but the most basic functionality, the user must load so-called "modules": little bits of code that add components (e.g. a different file system or a VGA font). This section gives you an overview of the process you need to go through when you want to have GRUB 2 load your kernel. It's actually rather simple to create a GRUB2 image (assuming you have GRUB2 either built or installed):

ISO instructions

mkdir tmp
grub-mkimage -p /boot -o tmp/core.img biosdisk iso9660 multiboot sh # Generate the core image
cat /usr/lib/grub/i386-pc/cdboot.img tmp/core.img > eltorito.img # You just replace stage2_eltorito with eltorito.img

# Now just use genisoimage, or mkisofs to generate an ISO image!

As of Grub 1.98+20100804 wich came with my Ubuntu 10.10 the correct grub-mkimage command is:

grub-mkimage -p /boot -o tmp/core.img -O i386-pc biosdisk iso9660 multiboot configfile

Grub2 seems to change a lot on each release. So if you're unable to make it work with the previous commands try this tested on grub 1.99~rc1-3ubuntu3. In particular this release seems to use only uppercase file names... Or I'm going crazy while trying to understand how this mess works. First create a file with the following contents:

set prefix=(cd)/BOOT
configfile /BOOT/GRUB.CFG

Now run:

grub-mkimage biosdisk iso9660 multiboot2 configfile -O i386-pc -p "(cd)/BOOT" -c <name of the file you just created> -o core.img
cat /usr/lib/grub/i386-pc/cdboot.img core.img > eltorito.img

And use it as always, putting your GRUB.CFG file in /boot and rememeber to use uppercase filenames...

Floppy instructions

mkdir tmp
grub-mkimage -p /boot -o tmp/core.img multiboot sh fat # This should work.. I hope :D

Explanation

Let's go through those grub-mkimage options:

-p By default, GRUB 2 looks in /boot/grub for its configuration file. -p changes this.
-o Like so many other GNU tools, grub-mkimage uses -o to set the output file. By default, it's stdout.
multiboot This module is required to load multiboot-compliant kernels.
biosdisk This module is required for GRUB 2 to be able to boot from a LiveCD.
iso9660/fat Allows GRUB 2 to look on the image for different files.
sh This module allows GRUB to parse the configuration file.

GRUB 2, like GRUB Legacy, needs a configuration file to find your kernel. In GRUB Legacy it's called menu.lst, but in GRUB2, it's called grub.cfg. The syntax for the configuration file is also a bit different.

Here's a sample configuration file (NOTE: This file should be placed into the /boot folder of your disk image, and be named grub.cfg):

set timeout=15
set default=0 # Set the default menu entry

menuentry "OS Name"
{
   multiboot /boot/kernel-file   # The multiboot command replaces the kernel command
   boot
}

That's basically it. Copy these files to a disk image, pop it in an emulator, and you're finished!

Multiboot

Some versions of GRUB 2 like to put multiboot modules in relatively high physical memory addresses, in contrast to GRUB-legacy which loaded them into low memory. Be careful when making your kernel work with GRUB 2 that it is not making any assumptions about where the multiboot modules will appear.

See Also

External Links