[Nolug] bootloader mini howto

From: Trey Fox <gefox4_at_gmail.com>
Date: Mon, 21 Aug 2006 10:32:05 -0500
Message-ID: <315fd9540608210832n17b7a471qf6e5e1710549920d@mail.gmail.com>

 Boot Loader Configuration

A boot loader is the first program loaded from disk when your computer
up. It loads the operating system and hands it the computer. Generally it
reside in the MBR of your hard disk. Without it, you couldn't boot your
or other operating system. The Linux boot loaders are not immediately
intuitive to use, and a long IRC conversation the other night gave me the
to write this.
The most common boot loaders (for Linux on x86) are LILO and GRUB. I'm going
describe how to manipulate these so you should be able to operate both. It's
sort of thing that you just become accustomed to after a few times (like
compiling a kernel).

LILO is the original boot loader for Linux. It stands for LInux LOader.
pretty much what it does. You can chain other operating system loaders from
but there's no direct support (for example for FreeBSD kernels.)
It is required to re-install LILO for changes to take effect after editing
configuration file (/etc/lilo.conf) for the changes to take effect.
Homepage: http://lilo.go.dyndns.org/

GRUB stands for the GRand Unified Boot loader. It's a much more modern
alternative to LILO and has been adopted by many distributions. It supports
direct kernel booting for more operating systems (so you don't need two or
boot loaders installed.) It's compliant with the Multiboot specification.
It has got a different device naming scheme to LILO (and Linux for that
but supports editing of existing options from inside the boot loader
you to remove/change kernel options without editing the config).
Unlike LILO, it isn't required to reinstall GRUB after modifying the
file. Different distributions of Linux sometiomes have different names for
the GRUB
config file. On some (like Gentoo) it's /boot/grub/grub.conf, while on
others (like
Suse) it's /boot/grub/menu.lst. The syntax of these files is exactly the
same. Also,
GRUB takes all it's paths as relative to its root partition (which is
different to
the Linux one)
Homepage: http://www.gnu.org/software/grub/

First of all...
There's a few bits of information that go along with the kernel to make it
boot. These are generally passed on the command line. This includes:
1. The root filesystem. This is the filesystem on which you mount / It's
in the form "root=/dev/hda2" assuming the root filesystem is on /dev/hda2.
2. Whether the root filesystem should be mounted read-only (ro) or
(rw). Most people would want read-only here (as the system remounts it read-

write anyway.
3. The initial ram disk image (if required). This provides a filesystem
which is booted before starting the main init process. It's generally
as "initrd=/boot/initrd-2.6.7" or similar.
4. any other arguments, such as using scsi emulation for a CD writer or
miscelaneous options to the boot process (depends on configuration/distro).
we can also disable kernel features (eg nomce to disable the CPU exception
5. The vga mode to use for the graphics console. You need framebuffer
compiled into the kernel. This can be set either in hex or decimal. Here's
decimal codes for a few common modes/colour depths:
 *Code:* Color depth | 640x480 800x600 1024x768 1280x1024
256 (8bit)| 769 771 773 775
32000 (15bit)| 784 787 790 793
65000 (16bit)| 785 788 791 794
16.7 Mill.(24bit)| 786 789 792 795

In grub, the initrd goes on it's own line. The others all go on the kernel=
In LILO, numbers 1,2 and 3 go on their own lines. The others go in the

First we'll look at a basic lilo.conf. This will vary a bit between systems,

so I'll try and point out the important bits.
# Where to install the boot loader
# here we put it in the MBR of /dev/hda
boot = /dev/hda
# The location of the boot sector to use.
install = /boot/boot.b
# The message to display
message = /boot/message
# the type of interface to use
# wait 20 seconds (200 10ths) for user to select the entry to load
timeout = 200

All the stuff above should already be configured in your conf file.
Here's an example to boot linux:
image = /boot/vmlinuz
  label = linux
  root = /dev/hda2
  vga = 790

This boots the kernel image in /boot/vmlinuz passing it the options
described above. You can have as many of these entries as you like, provided

they have different labels. For booting a Windows/DOS install, you can just
add something like the following:
 *Code:* other = /dev/hda1
    label = Windows

Misc LILO stuff
There are some important options I should take this opportunity to go over.
It's possible to set a password so that the boot options can't be modified.
This is desirable if it's to be a public workstation, as if you have control

over the kernel command line, it's generally easy to gain full access to the

system.(for example passing init=/bin/bash on the command line to get a root

To set the password, add a line like this into your /etc/lilo.conf:
 *Code:* password = foobar
This will make it require a password for every boot (which isn't always
desirable) so we will add another option to only require a password if a
is made to the boot options.
 *Code:* restricted
IMPORTANT: After making any configuration changes to lilo.conf, you need to
/sbin/lilo at the command line (as root) for the changes to take effect.

GRUB's configuration file is a bit different. All the paths in it are
to its root partition (which can be different from your linux one). It also
a different naming scheme. I'll give a few examples so you see what I mean.
there's two hard disks in the system, one on hda and one on hdc.
(hd0) = hda
(hd0,1) = hda2
(hd1,0) = hdc1
Note that the numbers start at zero. The first number is the disk
identifier, the
second is the partition.
See how the numbers only apply to actual hard disks. You don't count ones
are not (like you do with LILO). When GRUB is installed, you give it a root
partition and a device to install the first stage on. Generally you'd use
either your
/ or /boot partition (if you have one) as the root for GRUB. The first stage
is the
part that goes in the MBR or something. All the examples here will assume
there's no
/boot partition but if there was, you wouldn't include "/boot" in the paths.

To boot Windows (or another system) from GRUB you want something like this:
title Windows 2000
   rootnoverify (hd0,0)
   chainloader +1
This is assuming it's installed on /dev/hda1

I've found it is sometimes necessary to re-install GRUB (i.e. if your MBR
gets wiped)
To do this, you'll need to have access to the relevant Linux (or other) OS
You will also need to know the location of your GRUB root partition (as
described above)
and where you want to install the actual boot loader. For example, if you
wanted to
install GRUB in the MBR of /dev/hda and you had a /boot partition on
/dev/hda3, you
would start grub from the command line and type the following:
root (hd0,2)
setup (hd0)

The first line tells GRUB that you want it to use hd0,2 (hda3) as its root
and the second installs it in the MBR of /dev/hda (which would generally be
booted by
default) If you wanted to install it into the boot sector of a given
partition you
would substitute in the correct name in place of hd0.

Adding a new kernel:

The operating kernel is basicly an executable program. In Linux's case, this
an ELF image compressed (normally) using bzip2. When you compile a kernel,
make process spits it out in the file ./arch/i386/boot/bzImage in the kernel

source tree. This goes into your /boot directory, generally kernel images
named in a similar manner to this: vmlinuz-2.6.7-gentoo-2 for the second
revision of the gentoo 2.6.7 kernel. This convention is of course entirely
optional, but it's handy to see which exact kernel each file is without
Once you've got the kernel in the boot directory (for the purposes of this
example, I'm going to call the file /boot/vmlinuz) You need the information
discussed above.

All these are passed on the kernel command line, but there's differences on
you configure it between the boot loaders.
Let's try an example, assume the root partition is /dev/hda2, we have a cdrw
/dev/hdc, and there's an initrd file at /boot/initrd. There's no seperate
boot partition.
image = /boot/vmlinuz
    root = /dev/hda2
    initrd = /boot/initrd
    vga = 790
    append = hdc=ide-scsi


 *Code:* title Linux
  kernel /boot/vmlinuz ro vga=790 root=/dev/hda2 hdc=ide-scsi
  root (hd0,1)
  initrd /boot/initrd
Hopefully by this point you are starting to see how the different files fit

Transferring a distro from one boot loader to another

This is another common task, but it can be quite hard to explain to people
over IRC or
similar, so I'll try my hand at explaining it here. In fact, the situation
itself is
hard enough to explain...
Let's say someone has a distro installed and they installed another
(intending to dual-boot)
in the best case, they'll end up with 2 boot loaders, having to go through
both to get to one
of the distros. We can add all the items into the same menu to save time and
hassle. However,
you need all the kernels/initrds in the same /boot directory. More problems
arise when you've
got both types of loader in use (i.e. one uses GRUB, the other LILO).
1. Boot into whichever distro you can.
2. Get root privileges.
3. Mount the partition containing your /boot directory for the other
4. Copy the initrd and vmlinuz files to your actual boot directory (on the
distro you're using
at the time) making sure to preserve all the files for your current distro.
5. Get the boot loader configuration file from the non-active distro and
open it in the text
editor. Find the bit about the entry you're interested in. For example, a
GRUB entry for SUSE
looks like:
title Linux
kernel (hd0,5)/boot/vmlinuz root=/dev/hda6 vga=0x317 splash=silent desktop
resume=/dev/hda5 showopts
initrd (hd0,5)/boot/initrd
Lets convert this into a lilo.conf entry. You'll have to rename these files
when you copy them.
For these purposes, we'll call it vmlinuz-suse and initrd-suse. Now we edit
the lilo.conf file for
the running system:
image = /boot/vmlinuz-suse
    label = Suse
    root = /dev/hda6
    vga = 0x317
    append = splash=silent,desktop,resume=/dev/hda5,showopts

See what I've done? You put all but the initrd, vga and root options on the
append line (comma
seperated) Now you run lilo and it should list all the entries defined.

When all goes wrong...
>From time to time, we all screw up our systems. I recommend backing up the
MBR if you're messing about
with the boot loaders (or installing a new distro). Germ wrote a nice little
guide here:
Anyway, I know for one that I don't back up everything I should. Assume you
need to boot a system you've
just hosed the bootloader for. It is possible, given the information above,
to boot into your system
using a LiveCD or install disk. When you get the ISOLINUX prompt (when
booting from CD)
you can just pick a kernel and pass the root= parameter to it. This
(provided the kernel you
chose has all the features required by the distribution you're using) should
boot into your chosen

This is taken from USALUG.org written by user: NuKeS.

Trey Fox
http://OpenSuse.us - Administrator
http://Ulteo.com - Administrator
Nolug mailing list
Received on 08/21/06

This archive was generated by hypermail 2.2.0 : 12/19/08 EST