Skip to main content

Switching to Grub2 on Gentoo

Hi! There seem to be quite a number of people being "afraid" of Grub2, because of the "no single file" approach. From more people, I hear about sticking to Grub legacy or moving to syslinux, rather than upgrading to Grub2. I used to be one of those not too long ago: I've been sticking to Grub legacy for quite a while, mainly because I never felt like breaking a booting system at that very moment. I have finally upgraded my Gentoo dev machine to Grub2 now and I'm rather happy with the results:

  • No manual editing of Grug2 config files for kernel upgrades any more
  • The Grub2 rescue shell, if I should break things
  • Fancy theming if I feel like that next week
  • I am off more or less unmaintained software

My steps to upgrade were:

  1. Install sys-boot/grub:2.
  2. Inspect the output of "sudo grub2-mkconfig" (which goes to stdout) to get a feeling for it.
  3. Tune /etc/default/grub a bit:
GRUB_DEFAULT=0
GRUB_TIMEOUT=5

# This is genkernel
GRUB_CMDLINE_LINUX="dolvm dokeymap keymap=de
    crypt_root=UUID=00000000-0000-0000-0000-000000000000
    real_root=/dev/gentoo/root noslowusb"

# A bit retro, works with and without external display
GRUB_GFXMODE=640x480

GRUB_BACKGROUND="/boot/grub/gentoo-cow-gdm-remake-640x480.png"

NOTE: I broke the GRUB_CMDLINE_LINUX line for readability, only.

  1. Insert a "shutdown" menu entry at /etc/grub.d/40_custom:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu
# entries.  Simply type the menu entries you want to
# add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry "Shutdown" {
    halt
}
  1. Run "sudo grub2-mkconfig -o /boot/grub/grub.cfg"
  2. Run "sudo grub2-install /dev/disk/by-id/ata-HITACHI_000000000000000_00000000000000000000"

Using /dev/disk/ greatly reduces the risk of installing to the wrong disk. Check "find /dev/disk | xargs ls -ld".

  1. Reboot

Done.

For kernel updates, my new process is

emerge -auv sys-kernel/vanilla-sources

pushd /usr/src
cp linux-3.18.3/.config linux-3.18.4/

# yes, sys-kernel/vanilla-sources[symlink] would do that for me
rm linux
ln -s linux-3.18.4 linux

pushd linux
yes '' | make oldconfig

make -j4 && make modules_install install \
        && emerge tp_smapi \
        && genkernel initramfs \
        && grub2-mkconfig -o /boot/grub/grub.cfg

popd
popd

Best, Sebastian