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 system's root partition rather than the mbr, will show all systems that it's found on the machine.

I have two machines that use 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. One one machine, when I installed FreeBSD on gpt4, it added an entry to /boot/efi/EFI.

On the other machine, if I did a standard install with UFS, after creating the FreeBSD partition, it ignored the Linux efi partition and gave a message that the machine needed an efi partition to boot, and asked if it should create one. When I chose yes, it created a gpt5 EFI partition as well as the gpt6 partition where the actual system got installed. I then, at the time using CentOS's grub2, made an entry that put root at (hd0,gpt6), the actual O/S partition, rather than its EFI partition and that worked. However, I then reinstalled it on a ZFS FreeBSD partition. To do this, checkout FreeBSD forum user patovm04's tutorial. I used his suggested grub configuration. I once accidentally left out the insmod part_gpt but it didn't make a difference. We'll get to its configuration shortly.

On my yoga2, I did a standard UFS install. On Fedora I then installed libguestfs-ufs and grub2-efi-x64-modules. The later gives me a /usr/lib/grub/x86_64-efi directory which includes a bunch of modules. Although others have apparently been able to do this with a symlink, when I tried ln -s I got a permission denied error. However, doing rsync -avz /usr/lib/grub/x86_64-efi /boot/efi/EFI/fedora/ (note that the /usr/lib/grub/x86_64-efi doesn't have a slash at the end, enabled me to use the following custom.cfg that I put in /boot/efi/EFI/fedora.
menuentry "FreeBSD" {
insmod ufs2
insmod part_gpt
set root=(hd0,4)
chainloader /boot/loader.efi
}

Later, I wound up installing VoidLinux on the yoga2 and used Void's grub. In that case, I added the FreeBSD entry to Void's /etc/grub.d/40_custom and then ran update-grub.

In my admittedly limited experience, and not spending much time on it, I have found that Ubuntu based distributions, Ubuntu and Mint to be specific, didn't seem to work well booting FreeBSD from their grub.d/40_custom. It may have been my error though. I have found that Fedora, Void, and Archlinux seem to have no problem.

With CentOS, I ran into an oddity on 8-stream. It was fine but then after a grub update, from 2.02.90 to 2.02.93, grub2 wouldn't reinstall. I had installed Mint as a multiboot, and then booted into CentOS. Mint had installed its grub, and I wanted to go back to CentOS's grub. However, when I ran grub2-install --target=x86_64-efi, etc, I got a message that it couldn't handle secure boot. The machine didn't have secure boot running, there was no Windows install on it. So I downgraded back to 2.02.90 and used dnf versionlock to keep it at 2.02.90. However, later on, I installed Void Linux and just used its grub to boot, which worked on everything, including FreeBSD.

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.

My Void 40_custom was taken directly from patovm04's tutorial.
menuentry "FreeBSD" {
    insmod fat
    insmod part_gpt
    set root=(hd0,gpt1)
    chainloader /efi/freebsd/loader.efi
}

In that case, according to his instructions, I just reference the efi partition, not the FreeBSD partition itself. Due to a typo, I also found that the insmod for part_gpt isn't necessary. I should add that on both machines, if I hit F12 after seeing the Lenovo logo, which takes me to a boot menu, it gives me an option to boot FreeBSD that way as well, but as this is a page on grub2, and I do see the problem frequently on FreeBSD forums, I feel it's worth adding here.