Previous: Booting once-only, Up: Making your system robust

4.3.2 Booting fallback systems

GRUB supports a fallback mechanism of booting one or more other entries if a default boot entry fails. You can specify multiple fallback entries if you wish.

Suppose that you have three systems, `A', `B' and `C'. `A' is a system which you want to boot by default. `B' is a backup system which is supposed to boot safely. `C' is another backup system which is used in case where `B' is broken.

Then you may want GRUB to boot the first system which is bootable among `A', `B' and `C'. A configuration file can be written in this way:

     default saved        # This is important!!!
     timeout 10
     fallback 1 2         # This is important!!!
     title A
     root (hd0,0)
     kernel /kernel
     savedefault fallback # This is important!!!
     title B
     root (hd1,0)
     kernel /kernel
     savedefault fallback # This is important!!!
     title C
     root (hd2,0)
     kernel /kernel

Note that `default saved' (see default), `fallback 1 2' and `savedefault fallback' are used. GRUB will boot a saved entry by default and save a fallback entry as next boot entry with this configuration.

When GRUB tries to boot `A', GRUB saves `1' as next boot entry, because the command fallback specifies that `1' is the first fallback entry. The entry `1' is `B', so GRUB will try to boot `B' at next boot time.

Likewise, when GRUB tries to boot `B', GRUB saves `2' as next boot entry, because fallback specifies `2' as next fallback entry. This makes sure that GRUB will boot `C' after booting `B'.

It is noteworthy that GRUB uses fallback entries both when GRUB itself fails in booting an entry and when `A' or `B' fails in starting up your system. So this solution ensures that your system is started even if GRUB cannot find your kernel or if your kernel panics.

However, you need to run grub-set-default (see Invoking grub-set-default) when `A' starts correctly or you fix `A' after it crashes, since GRUB always sets next boot entry to a fallback entry. You should run this command in a startup script such as rc.local to boot `A' by default:

     # grub-set-default 0

where `0' is the number of the boot entry for the system `A'.

If you want to see what is current default entry, you can look at the file /boot/grub/default (or /grub/default in some systems). Because this file is plain-text, you can just cat this file. But it is strongly recommended not to modify this file directly, because GRUB may fail in saving a default entry in this file, if you change this file in an unintended manner. Therefore, you should use grub-set-default when you need to change the default entry.