Failsafe booting

Q Most distros use Grub nowadays and I can see how it is easier to use than Lilo. But there appears to be one very important feature missing: Lilo can use the -R option to boot a kernel once only, so the next time it goes back to the old default, which is handy for testing new kernels. If it fails, a reboot goes back to the old kernel. It is really important to be able to do this on a remote server and I can't see how to do it in Grub.

A This is possible with Grub, although a little less intuitive. There are a couple of methods available, but the fallback is the most flexible.Here is an example configuration

root (hd0,0)
timeout 10
default saved
fallback 1 2
title new kernel
kernel /boot/vmlinuz root=/dev/
sda1 panic=10
savedefault fallback
title old kernel
kernel /boot/vmlinuz.old root=/
dev/sda1 panic=10
savedefault fallback
title rescue shell
kernel /boot/vmlinuz.old root=/
dev/sda1 init=/bin/bb

The default saved line tells Grub to use whichever menu item was saved in /boot/grub/default (or the first item if that file is not present). So Grub boots the first item, your new kernel and the savedefault line now sets the default to 1, the second menu choice (remember Grub counts from zero). The panic=10 kernel option means that if the kernel panics, it will reboot after ten seconds, and now Grub will use your new default of the second That should be enough, but for belt and braces you can repeat the process with this kernel, which will then use your second fallback if things go wrong. This final choice simply uses savedefault which saves itself as the default. You may have noticed a slight flaw with this process in that your fallback is always saved as the new default, even if the boot succeeds. This is handled by running the command

grub-set-default 0

at the end of a successful boot, usually from your rc.local script, depending on your distro. Although this is a more complex system that Lilo's -R (there is a slightly simpler alternative) is is far more useful as it is always in effect. Any time your computer reboots without completing the full boot process, it switches back to your old kernel, whereas Lilo requires a specific command to do this.

Follow us on or Twitter

Username:   Password: