GRUB

Introduction
GRUB2 is next generation, a complete rewrite, of GRUB LEGACY popular GNU/Linux boot loader. The new version has a new shell like syntax which permit advanced scripting capabilities unlike the LEGACY version. So, even seasoned GRUB LEGACY users should take a look at what GRUB2 can do to take advantage of the powerful shell like scripting along with new features.

Upgrading to GRUB 2 might be necessary as it allows:
 * booting from UEFI;
 * booting from GPT partitioned drives without even needing an akward hybrid MBR, even though one can one for compatibility/portability reasons;
 * booting from directly logical volume management such as LVM2 support;
 * booting from raid DM-RAID support 4, 6 and 10;
 * and booting from encrypted devices, LUKS I assume because the inexistent documentation is not clear on this: so no guidance on a howto for the moment.

Installation
GRUB2 is both hard masked and in development, so one has to both keywords and unmask the package as the following before merging the package.

Else, one would have to undergo a manual configure, make and make install on his/her own which won't be covered by this modest contribution.

Partitioning and preparing boot disk
Before installing GRUB2 to the boot media a little care should be taken when preparing and partitioning the boot device be it an internal disk or be it a removable device. This depend on the boot type involved: BIOS or UEFI. BIOS booting can be easily achieved with either booting from disk partitioned with the aging MBR or with GPT with a protective MBR or a hybrid MBR if dual booting is involved with GPT unaware OS like MSDOS/Windows. It's another story for UEFI as GPT is part of UEFI specification and it's mandatory to use GPT partitioned in this case.

If dual booting is involved with Windows which cannot boot from anything else but BIOS/MBR or else on GPT partitioned disk only on EFI hardware. In the later case dual booting Windows is simple and the former is trickier a GPT partitioned disk and a hybrid MBR. More on this subject will come later.

Before going further, one could back the boot device MBR with something like:

or simply its boot loader with something like (here one can go as far as 446 bytes):

Here, one has to make a [0x]ef00 partition type. Here is an example of such a GPT partitioned disk with BIOS boot [0xef02] partition and an EFI [0xef00] partition. Here the output of the `p' command in gdisk main menu.

parted gives a somewhat different output with a slightly different semantics for the same device, here is the output.

Creating partions in gdisk is pretty straight and quick forward for somebody who use fdisk. Just type `n' in the main menu provide a beginning and end if need be and then type the partition type ef00 for EFI for example. That's all.

UEFI installation
Before setting up UEFI boot, one has to partition the boot device with a GPT compatible disk tools like GPT fdisk or gdisk, parted or gparted (a gtk gui) or other tools that I did not bother to try at this point. It's advised to have something greater than 200MB and maybe smaller than 500MB for multi boot systems. GPT disk is a powerfull tools than can be used to setup a few advanced settings like hybrid MBR or the number of alignment sectors. The default 2048 sectors (1MiB) is a sane default which will permit to make use of sector 34-2048 to embed GRUB2 core.img for example if one forgot to leave some space for BIOS boot partition.

Let's move to installing GRUB2 and setting up an EFI boot entry. I do not have an EFI board so EFI specifc boot steps is not tested!

First, create a filesystem and a mount point for the EFI partition with something like:

And then install GRUB2 (x86 users should replace x86_64 by i386)

or install everything manually if something goes wrong.

It might be necessary to build a customized core.img with a few builtin modules to be safe or to satisfy specific requirements.

Before any attempt to add a menu entry to EFI boot menu, inserting EFI module and merge the utility is necessary.

And then add an boot menu entry.

BIOS/MBR installation
Installing in this mode is straight forward as it's just like the legacy GRUB with new GRUB2 additions. Care should be taken for the first partition alignment. GRUB2 uses the gap between the MBR and the first partition to embed its core.img. If the disk is partitioned with recent tools, fdisk for example, the first partition should aligned to 2048 sector boundary. So the installation will go just fine. Otherwise, GRUB2 will rely on the `/boot' device to load core.img. In this later case something like:

the chattr commands are there to prevent core.img being moved by filesystem maintainance tools.

If using another specific bootloader like TrueCrypt bootloader which is problematic with GRUB2 at the moment, and then need to boot another OS, it's necessary in that case to install GRUB2 to a partition with something like:

Just ensure to have enough gape before that partition or else... mount boot and use something similar to the previous example.

BIOS/GPT partitioned disk without hybrid MBR installation
This setting is maybe the simplest methode in this guide along with a plain BIOS/MBR setup, well, assuming that at least if an EF02 type partition was created with a GPT compatible tools. A simple command like the following is enough to get everything fine and running.

And everything should goes as expected. I couldn't install GRUB2 without an EF02 partition although sector 34-2047 and about the same unused amount free sector at the end were left. You're warned!

BIOS/GPT partitioned dis and with hybrid MBR installation
Multi booting OSs that aren't aware of GPT partitioned disk, e.g. Windows 7 or Windows XP for those who still use that thing--that's because MSDOS/Windows cannot boot from anything else than BIOS/MBR aside from MSDOS/Windows 7 and possibly 8 from EFI platforms,--require this tricky workaround. The thing to keep in mind is that playing with a hybrid MBR can be tricky so, nothing in this sub-section should be taken as solid rock working but rather simply guidances to experiment to get something working.

First of, GRUB2 should boot and should recognize a partition table be it GPT or MBR simply by loading the associated module (part_gpt or part_msods). So it should be expected to be able to boot on BIOS/MBR or BIOS/GPT depending on GRUB2 loaded module? Nothing is far from the truth, because, the previous sections outlined the differences between installing GRUB2 on BIOS/MBR and BIOS/GPT. I don't know how grub2-install behave when trying to install in BIOS/MBR mode with an EF02 (or bios_boot in parted terms) partition because I did not simply try it.

Actually there's simple thing that would determine grub2-install to install in BIOS/MBR or BIOS/GPT: it's the presence of a EE00 (GPT protective) and being the first partition in the MBR with that. With a hybrid MBR, GRUB2 will install just fine if and only if the first partition in the MBR table is an EE00 partition. An EF02 partition should be present anywhere in the disk and not necesseraly in the MBR list to leave a few room to embed core.img in the disk tough.

Creating a hybrid MBR is easy with gdisk: just hit `r' (recovery and transformation) in the main, then hit `h' (CHS recompute) in that menu, and then enter a series of partition (less or equal to 3) in the order you want it to be, and then enter the hexadecimal partition type without the `0x' prefix or accept the default with hitting repeatedly with `Y', and enable only a single boot flag as the following example.

And then check out if the operation was successful or not by listing the devices.

And finally install GRUB as usual. Everything should be fine at this point. See troubleshooting section for possible issues not listed on the previous Notes and comments.