Grub2 notes

Since most of the documentation I see on Grub2 at this point is written for Ubuntu, and Fedora does it differently, this page is more of a reminder to myself.

These commands are for Fedora 16 in its alpha stage. I don't know how many of them will change. Please consider this a work in progress.

Making changes.

One doesn't edit /boot/grub2/grub.cfg. Instead, one edits /etc/default/grub. There, one can remove, for example, the rhgb and quiet entries in the menu, so that one can see what's happening during boot, or change the default timeout. After editing it, one must then run
grub2-mkconfig -o /boot/grub2/grub.cfg

The -o is for the output file--if you don't give it, then no changes are actually made.

Adding entries to your grub menu.

Grub2 may or may not detect other systems. If I have say, Fedora, some Ubuntu variant such as Lubuntu, and CentOS on a machine, it might find all of them. If not, though there is a 40_custom that you can edit--last time I looked it was in /etc/grub.d-- I always find it easier to just create a new /boot/grub2/custom.cfg. This will be read.

While old grub would count disks and partitions starting at 0, so that /dev/sda1 would be hd0,0, grub2, while still counting disks at 0, starts partitions at 1. So, /dev/sda1 will be sd0,1. Assuming you have installed, for example, ArchLinux on /dev/sda6, and need to create a /boot/grub2/custom.cfg
menuentry "ArchLinux" {
set root='(hd0,6)'
linux /boot/vmlinuz-linux
initrd /boot/initramfs-linux.img
}

If using chainloading then,after the setroot line, instead of linux and initrd, it would look like
menuentry "ArchLinux" {
set root='(hd0,6)'
chainloader (hd0,6)+1
}

When editing custom.cfg, one doesn't need to run grub2-mkconfig, the custom.cfg changes will be read on boot. (I think if you do use the /etc/grub.d/40 or 41_custom files, you _do_ have to run grub2-mkconfig, but am not sure.)

If using FreeBSD as another system, although the chainloader syntax will work, it's better to use the kfreebsd /boot/loader syntax. For example with FreeBSD on partition 3
menuentry "FreeBSD" {
set root='(hd0,3)'
kfreebsd /boot/loader
}

I've seen various posts and articles saying one should use (hd0,3,a) but that hasn't worked for me.
I say it is better because if one uses the chainloader syntax and has more than one installation of FreeBSD on the machine, grub2 will only boot the last one installed. As mentioned in this stackexchange thread, if one uses the chainloader syntax, it will boot whichever partition is marked as active. So, if I install FreeBSD-9.2, then install FreeBSD-10.1, it will only boot the last one.

I've had the same problem sometimes happen with the /boot/loader syntax, but less frequently. Generally, I don't multiboot anything that's too important, so I haven't kept careful track of it, but generally speaking, I've had the the kfreebsd /boot/loader syntax work.

If you do want to use the chainloader syntax it is
menuentry "FreeBSD" {
set root='(hd0,3)'
chainloader (hd0,3)+1
}

Note that there is no space between the (hd0,3) and the +1. I found that if I put in the space, that is, wrote it as (hd0,3) +1, it wouldn't work, giving me an error of
invalid file name `'.

I've found that both Ubuntu and Fedora seem to sometimes, though not always, have issues finding other systems. In addition, if you're using, say, Ubuntu's grub, then update Fedora, it might not find it until you once again update grub in Ubuntu. So, my personal preference is to decide upon one as the main grub. In /etc/default/grub, I will then add the line
GRUB_DISABLE_OS_PROBER=true

Then, update grub. In Ubuntu just run sudo update-grub, in Fedora, the command would be grub2-mkconfig -o /boot/grub2/grub.cfg. Now, this means it will be up to me to add a chainloader entry each time I install another system.

For me, this is the easiest way to do it. It also tends to keep grub menus smaller--if I don't do this, then each system running grub2, even if grub2 is in that systems root partition rather than the mbr, will show all systems that it's found on the machine.

I only have one machine that uses Uefi, and as people probably know, it requires its own set of rules. To install grub on a Uefi system, your best bet is to look for instructions for that system, be it (listed alphabetically) Arch, Debian, Fedora, or other. It's usually pretty straightforward. I've found that Fedora's grub2 had trouble booting FreeBSD, regardless of the syntax I used. In the end, I used VoidLinux to boot other Linux installs, as well as FreeBSD. FreeBSD seems to not recognize an already installed Linux efi partition, and puts in its own. On my machine, the FreeBSD efi partition was on partition 5 and the FreeBSD partition itself was on partition 6. After various experiments, the following worked for me on Void, (and on Arch, when I tried it, though I use Void's grub2.) Void has its grub file, even with efi, in /boot/grub/grub.cfg, so I made this custom.cfg which I also placed in /boot/grub.
menuentry "FreeBSD" {
set root=(hd0,6)
chainloader /boot/loader.efi
}

I didn't need to insert modules for bsd or ufs2 nor did I need to use gpartX as my numbering scheme. I also didn't need single quotes around (hdo,6).

If one checks the FreeBSD forums, they can see various other methods, some of which work for other people. In my case, this is what worked, though not with Fedora's grub.