Since I was stuck with lilo and booting with different parameters is a pain when using it, I decided is time to try to install and start using grub-pc, aka grub2.
Documentation on migrating from lilo (or even grub 1) is lacking, even more for cases where you have the /boot directory on LVM, like I do. IMHO, one of the most important things during a migration is to never lose the ability to boot properly your system, which means that it was a must not to write the grub code into the MBR unless I was 100% sure I will be able to boot with grub at the next reboot.
I tried quite a few approaches (installing grub in a partition, trying to create a real /boot partition), but they all failed on way or another, so I will not describe any of those failing methods.
What I found to work was to:
- install the grub-pc package,
- create its configuration and set it up (creates the module files in /boot/grub and /boot/grub/grub.cfg),
- then install the boot code on an external USB stick, while nothing else was to written on the stick (so no data lost from the stick);
- after successfully booting from the USB stick, install the boot image on the internal harddisk's MBR
- reboot and be happy with grub2
Now lets go over the steps in more detail*.
Creating the configuration is a matter of creating the device.map file and grub.cfg:
Create a core.img file with support for lvm:
grub-mkimage --output=/boot/grub/core.img ext2 chain pc gpt biosdisk lvm
Install on the MBR of the USB stick (making sure lvm will be visible):
grub-install --modules="pc ext2 biosdisk gpt chain lvm" /dev/sdb
Try to boot from the stick at least one kernel. If it fails, you probably didn't add in the proper modules (see the possible module names in /usr/lib/grub/i386-pc and add the necessary ones in the modules list). If you're dropped into the GRUB rescue prompt, use ls and set to check if the root and prefix variables are set correctly and if the lvm root is visible.
If you manage to boot, you're ready to replace lilo or your old boot loader.
Install on the internal disk MBR:
grub-install --modules="pc ext2 biosdisk gpt chain lvm" /dev/sda
Reboot and be happy.
Please note that you might have added some optional parameters in your old lilo.conf which aren't present in the new /boot/grub/grub.cfg file and you might want to add those. If you want to add some option to all the images, you'll probably want to append those parameters to the value of this variable from /etc/default/grub:
For instance, since I want to find when sleep stopped working for my machine, I changed mine into:
After that, run update-grub once more to propagate the changes into /boot/grub/grub.cfg.
* skipping package installation; just use aptitude's text user interface and install grub-pc and grub-common from sid; depending on the system you might need to install grub-efi, grub-ieee1275 or even grub-linuxbios instead of grub-pc