Editing boot loader configs

Posted on Wed 21 September 2011 in Linux

When you delve into Linux you're likely to try out many different distros and in time it's not unlikely that you will use multiple distros for different tasks. All this means you will probably want to be able to switch between different distros (and/or windows) without having to reinstall the OS all the time. This is where multiboot and boot loaders enter the picture. There are multiple boot loaders available, with the most common being GRUB and GRUB2, then you have slightly less common boot loaders like syslinux and the nigh extinct LILO.

Boot loaders in general

Boot loaders are small programs that runs after the computer's BIOS have finished with the basic hardware check of the system. Boot loaders and their configuration files are located in the /boot/ directory on Linux systems.

Boot loaders will usually require three pieces of information to boot a Linux distro;

  1. Path to the kernel
  2. Path to the initial ramdisk (initrd)
  3. Arguments to pass to the kernel

The kernel and initial ramdisk MUST be on the same partition as the boot loader!

If they are not you will have to copy them from wherever they are located, usually in /boot/ on the partition for the OS you want to add to the boot menu.

If you have various boot loaders spread out over multiple partitions you will have to use a partition tool like gparted to add the boot flag to the partition containing the boot loader you want to use.

extlinux / syslinux

The configuration file for syslinux' boot menu is usually found at /boot/extlinux/extlinux.conf or a file called syslinux.cfg located somewhere in the /boot/ directory. A extlinux.conf may look something like this configuration from MeeGo 1.2:

# extlinux.conf generated by anaconda

prompt 1
timeout 50

default vesamenu.c32
menu autoboot Starting MeeGo...
#menu hidden

menu resolution 1024 600
menu background splash.jpg
menu title Silly boot loader!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
label meego
menu label MeeGo (2.6.38.2-8.26-adaptation-pinetrail)
kernel vmlinuz-2.6.38.2-8.26-adaptation-pinetrail
append ro root=/dev/sda5 quiet vga=current
menu default

As you might suspect from certain entries above, like menu title being "Silly boot loader", this isn't entirely the default config shipped with MeeGo 1.2.

To make the boot menu appear and give you time to choose it is important that you do what I have done above, set prompt to 1, increase timeout to 50 (5 seconds) or whatever floats your boat and comment out the menu hidden line as shown above. What is important in this configuration file is the section beginning with "label meego", because this is one item on the boot menu and you will have to add another one similar to it for every other OS you want on the boot menu.

Here is another boot menu item, to boot Mint Debian:

label mintdebian
menu label Mint-Debian
kernel /boot/vmlinuz-2.6.39-2-amd64
append initrd=/boot/initrd.img-2.6.39-2-amd64 root=UUID=c717544d-c339-432e-9d59-08350cea7590 ro quiet

label whateveryouwant (not displayed anywhere)
menu label the-name-that-will-appear-in-the-menu
kernel path-to-your-kernel
append extra options, initrd is required for pretty much all linux distros

The options I have included in append should be enough for most distros, we specify the path to the initial ramdisk (initrd), we tell the system which hard drive and partition is the root directory for the system (you can use root=/dev/sdXY instead of the unique identifier UUID). ro means root will be mounted as readonly which is recommended for various reasons. The quiet argument tells the kernel to only print important and system critical messages to the console rather than all kinds of information. If you are not sure what values to put in append, try having a look at the default boot config shipped with your distro, usually located somewhere in /boot/

If you want your added boot menu item to be the default choice (the one that is selected when time runs out) add the line "menu default" after append.

GRUB(1)

GRUB is still one of the most common boot loaders although it is gradually being replaced by GRUB2. The configuration file for GRUB is located in /boot/grub/menu.lst and can look like this;

default 0
timeout 10

title Ubuntu, kernel 2.6.17-10-generic
root (hd0,4)
kernel /boot/vmlinuz-2.6.17-10-generic root=/dev/sda5 ro quiet splash
initrd /boot/initrd.img-2.6.17-10-generic
quiet
savedefault

A quite simple setup, default indicates what menu item (0=first) should be the default choice. timeout sets the delay before booting the default choice and then we have the entry for the OS which should look familiar by now. What is new is root (hd0,4), hd0 = first hard drive, 4 = fifth partition and this should of course point to the HDD/partition your root is located on. quiet will hide "less" important boot messages. savedefault will make the menu item the default boot choice next reboot if selected. To illustrate, here is another menu item to load my Mint Debian distro which is located on /dev/sdb2;

title Mint Debian x64
root (hd1,1)
kernel /boot/vmlinuz-2.6.39-2-amd64 root=/dev/sdb2 ro quiet
initrd /boot/initrd.img-2.6.39-2-amd64
quiet

GRUB2

GRUB2 is slightly more complicated, or easy depending on your perspective. For manual setup I will just refer to Ubuntu's GRUB2 wiki article.

For automatic detection of your OSes you can try installing the os-prober package, run it and then update-grub2, in a Debian based OS like Ubuntu the commands would be;

sudo apt-get install os-prober
sudo os-prober
sudo update-grub2

LILO

One of the oldest Linux boot loaders is LILO (LInux LOader) and I have so far not come across it, I suggest you give the how-to at tldp.org a try if you're interested in configuring a LILO boot loader.