GRUB2 migration from GRUB Legacy
1.
Background
What's Grub?
Grub is one of the most commonly found boot loaders in use on non-embedded
Linux machines. The role of Grub is to facilitate the Linux kernel being loaded
from your disk into memory and start executing the Linux kernel.
So Why Migrate?
Firstly, GRUB Legacy is no longer maintained and as such no longer receives
updates. GRUB Legacy was created at a time when the developers felt safe in
making several assumptions which no longer hold true today. For example,
GRUB Legacy is unable to boot from disks larger than 2TB and assumes that
newer filesystems wouldn't come to replace /boot.
GRUB2 aims to be more robust, more portable, more powerful and is maintained
with a cleaner code base. GRUB2 supports more hardware configurations, more
filesystems and more drive layouts than its predecessor.
2.
Migration to GRUB2
Migration to GRUB2 is fairly straightforward: it will be pulled in as part
of your regular upgrade process by your package manager. If it is not pulled
in automatically, you can always install sys-boot/grub:2.
Boot Drive
The first important part is to understand what your bootable drive is. For
many people it will be /dev/sda. The easiest way to find this is
to look at how your existing GRUB Legacy is setup by viewing
/boot/grub/grub.conf. An example one is provided below.
Note:
You must have your /boot mounted to be able to view these files.
It should be as simple as mount /boot to mount /boot.
|
Code Listing 2.1: /boot/grub/grub.conf |
default 0
timeout 30
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Gentoo Linux 3.2.12
root (hd0,0)
kernel /boot/kernel-3.2.12-gentoo root=/dev/sda3 quiet dolvm
initrd /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
|
Based on the above file we know that (hd0) is the boot drive but we
must map this to a real device. To know this you must view
/boot/grub/device.map. An example one is provided below.
Code Listing 2.2: /boot/grub/device.map |
(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
|
Based on the above file we know that /dev/sda is the boot drive.
Installing and Configuring GRUB2
The next step is to install and configure GRUB2 on your /boot
partition without removing GRUB Legacy from your MBR. The example below
uses /dev/sda but you must replace it with your boot drive path.
The first step installs the necessary GRUB2 files to /boot/grub2,
while the second step scans your available kernels and generates a suitable
config file to /boot/grub2/grub.cfg.
Code Listing 2.3: Installing and configuring GRUB2 |
# grub2-install --grub-setup=/bin/true /dev/sda
Installation finished. No error reported.
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.2.12-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
done
|
Note:
GRUB2 has strict naming requirements for kernels and initramfs images. A
kernel must be named kernel-${version} or vmlinuz-${version}
while an initramfs must be named initramfs-${version},
initramfs-genkernel-${version},
initramfs-genkernel-${arch}-${version},
initrd-${version}.img, initrd.img-${version},
initrd-${version}.gz, or initrd-${version}.
Together with ${version}, the filename must match a corresponding kernel
that is available in /boot.
|
Chainloading GRUB2 from GRUB Legacy to test the setup
Because a broken GRUB configuration could mean an unbootable
system, we want to test our GRUB2 configuration before making it permanent.
To do this we will chainload GRUB2 from GRUB Legacy. This is done by adding
a new section into /boot/grub/grub.conf. An example is shown
below.
Note:
Be aware that your root may be different from (hd0,0) used in the
example, and make sure you reuse the same root value from your
/boot/grub/grub.conf.
|
Code Listing 2.4: /boot/grub/grub.conf |
default 0
timeout 30
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title GRUB2 Chainload
root (hd0,0)
kernel /boot/grub2/i386-pc/core.img
boot
title Gentoo Linux 3.2.12
root (hd0,0)
kernel /boot/kernel-3.2.12-gentoo root=/dev/sda3 quiet dolvm
initrd /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
|
At this point you should reboot your machine and select GRUB2 Chainload
from the GRUB menu when your machine begins to boot. You will be presented with
another GRUB menu which should advertise itself as GRUB 2.0.0 or higher at the
top and show your available kernel(s) to boot. Should this not work, simply
reboot your system and pick your normal boot option instead of GRUB2
Chainload.
Replacing and removing GRUB Legacy
At this point, if everything worked successfully, you can replace GRUB Legacy
and remove it from your system.
Note:
Since you've rebooted your system, you may need to mount /boot
again. Make sure to use your own boot drive path instead of
/dev/sda.
|
Code Listing 2.5: Replacing GRUB Legacy |
# grub2-install /dev/sda
Installation finished. No error reported.
# rm -rf /boot/grub/
|
At this point you can use your package manager to remove sys-boot/grub:0.
The migration is complete.
3.
Maintaining GRUB2
Whenever you install a new kernel, you must perform the next step so
that your GRUB2 configuration recognizes the new kernel.
Note:
You must have your /boot partition mounted for this step.
|
Code Listing 3.1: Installing a new kernel |
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.3.8-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.3.8-gentoo
Found linux image: /boot/kernel-3.2.12-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
done
|
4.
FAQ / Known Problems / Gotchas
Content to come.
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-2.5 license. The Gentoo Name and Logo Usage Guidelines apply.
|