|
Last update: January 25, 2001
Secrets I learned...
about (multi-Linux) LILO
Pulling yourself up by the boot-straps
- It's hard for the cowboy to get up in the morning. In order to do so,
he has to pull on his boots.
- It's hard pulling on those boots. In order to do so, he has to pull
the straps attached to those boots.
That's where the computer model got its terminology. Your computer is tired.
(Maybe it had too much to drink.) It's been turned off all night. At the
instant that you turn it on, it can't do very much. It's almost as if it
was just borne.
It needs instructions on how to do just about anything.
Meet Asad
Asad was just borne. He is a living miracle (far more impressive than a
computer).
He needs instructions on how to do just about anything.
(That's what mothers are for.)
He can do only the most Basic of things.
Food goes In. Smelley stuff comes Out.
Well that's not really fair. Using his Basic
Input Output System, Asad has
already learned a tremendous amount from Mom. He's already quite the young
man. He'll soon be going to school.
The Boot Process
I'm cutting a few corners here, but suffice to say that the computer's
BIOS isn't capable of much. However, it is capable
of reading in 512 bytes worth of instructions from the very first sector if
its hard disk.
That tiny space, the 1st 512 bytes on the disk, is properly called the
Master Boot Record. (It's also
called "sector 0", but that sounds too much like Star Trek.)
The BIOS is capable of reading that small area and executing the
instructions that it finds there. But how do those instructions get
there in the first place?
A program called /sbin/lilo, as in LIux
LOader, is capable of gathering information from a variety of
sources. It can place some of that information into that tiny space.
The rest will have to go elsewhere.
/sbin/lilo wants to put a lot of information into the MBR, but
those 512 bytes aren't nearly enough room. It wants to say "Here's a
large set of instructions that will culminate in your loading of an Operating
System. You need to execute those instructions now."
But it aint gonna happen.
(Adding insult to injury, only 446 of those 512 bytes
are reserved for instructions. 64 bytes (4 * 16 = 64) are reserved
for information regarding the addresses of as many as 4 partitions.)
In that small space of 446 bytes, there's only enough room to say something
like "Go to school. Here's the school's address. (Welcome to Grade 1)"
Grade 1 - install
I've called that address "Grade 1" but it might better be called
called the boot or install area. In fact, it really is a regular
file, but the boot-process doesn't know about files yet.
The instructions necessary to describe a file system (like Linux's
ext2 file system) are complex. The computer hasn't learned that much
yet. File systems are not covered until Grade 3.
For that reason,
/sbin/lilo doesn't store install's filename in the MBR.
Instead it stores install's physical address in the MBR, because
you don't need a file system to access a physical address.
In the install area, /sbin/lilo will have prepared more
instructions for the boot-up process to follow. It's the Grade 1
curriculum.
At the end of the instructions in the install is something like
"Congratulations. You may now proceed to Grade 2. Here is its
physical address."
Grade 2 - map
I've called that address "Grade 2" but it might better be called
called the map area. It too is in fact a regular file, but the
boot-process still doesn't know about files. For that reason,
/sbin/lilo doesn't store map's filename in the install
area. Instead it stores map's physical address in the install
area, because you don't need a file system to access a physical address.
By the time the boot-up procedure has reached Grade 2, it has
learned enough to be able to ask you a question! It asks you "Which of these
several operating systems do you want to initiate (ie: do you want me to
learn about) next?"
We are moving up the socio-economic ladder. We're about to move to a new
house. We have (perhaps) several to choose from. You have to make that
choice. It will determine where you'll be attending Grade 3.
At the end of the instructions in the map are textual descriptions
of one or more operating systems and their physical addresses. After a
choice has been made, explicitly or by default, the boot-up process will
jump to its physical location.
Grade 3 - Operating System
Grade 3 is at that physical location. Grade 3's curriculum is the operating
system. Amongst other things, the operating system will be teaching things
like file-systems, so we won't have to use physical addresses anymore.
A preliminary look at /sbin/lilo's
configuration file
Most of /sbin/lilo's configuration options are in a configuration
file called /etc/lilo.conf Let's take a very preliminary
look at a typical /etc/lilo.conf (Don't get too excited. We're only
going to look at the first few lines of it. We'll revisit it later.)
| boot=/dev/hda |
This indicates the first of several destinations for LILO's
output. It's the location of the 512 bytes situated at the beginning
of some disk, which is the MBR. In this example, the disk is
/dev/hda
Note that we've said /dev/hda which is the Unix name
for the first IDE disk.
We did not say something like /dev/hda1 which
would have meant the first partition on that first disk.
|
|
install=/boot/boot.b
map=/boot/map |
Grade 1
Grade 2
LILO will derive, on the basis of other parameters that
are also specified in /etc/lilo.conf that we havn't yet
discussed, a lot more information
necessary for the full boot-up process. It will put that information
in these two output files.
After creating those 2 files, LILO will calculate the precise
physical location on the disk where these 2 files reside in terms of
cylinders, heads, tracks and sectors.
Grade 1's address (install) will be placed in the MBR
Grade 2's address (boot) will be placed in Grade 1.
You might think that you can avoid these two parameter settings.
Well, yes and no. If either or both of image and boot
are not specified, Linux will implicitly behave as if they were
specified, ie. it will provide default values for them. The implicit
default values are precisely the same as the examples I've chosen. I
suggest that you explicitly specify them, if, for no other reason
than that you can see those choices in front of you.
|
I promise that we'll come back to the /etc/lilo.conf configuration
file. But for right now, we need to look at how we partition the disk for
two different Linux distributions on it.
SuSE and Red Hat
Assume we want to construct a single disk that will house two versions of
Linux: a SuSE and a Red Hat. Ultimately, of course, we'll need the flexibility
of selecting, at boot time, which one we want to start up.
That issue will take us back to
our LILO discussions but, for right now, let's focus on our slicing.
While doing the first install (SuSE), we keep the second install (Red Hat)
in mind. While installing SuSE, we define all the partitions -- even
the ones we know SuSE doesn't care about.
The SuSE slicing will look something like this.
Note in particular:
- hda1 in SuSE is mounted as /boot
- hda2 in SuSE is mounted as /RHboot
- hda2 will also be Red Hat's /boot
The SuSE install procedure won't do anything
with the strangely named "/RHboot"
partition nor will it touch the others.
As part of the SuSE installation,
- I will have LILO write the MBR
When it comes time to do my Red Hat install,
- I won't have LILO write the MBR.
- I won't change any of the partitions.
- (but I will change most of the mount points.)
- hda2 as Red Hat's /boot
- hda3 as Red Hat's {swap}
- hda10 as Red Hat's /
- hda11 as Red Hat's /usr
- hda12 as Red Hat's /opt
- hda13 as Red Hat's /var
- hda14 as Red Hat's /home
|
Slice
|
SuSe
|
Red Hat
|
| hda1 |
/boot |
|
| hda2 |
/RHboot |
/boot |
| hda3 |
{swap} |
| hda4 |
(Extended partition) |
| hda5 |
/ |
|
| hda6 |
/usr |
|
| hda7 |
/opt |
|
| hda8 |
/var |
|
| hda9 |
/home |
|
| hda10 |
|
/ |
| hda11 |
|
/usr |
| hda12 |
|
/opt |
| hda13 |
|
/var |
| hda14 |
|
/home |
|
As part of the Red Hat install, I will NOT have LILO write the MBR.
I want to leave the one that SuSE wrote in tact.
That means that the system will only be able to re-boot into SuSE. But that's
ok. All I want now is SuSE.
When I re-boot the system, SuSE will come up. Afterall, as part of the SuSE
install, I had the installer run LILO which loaded the MBR in such
a way as to enable SuSE to boot.
Once SuSE has been booted, we'll modify SuSE's /etc/lilo.conf and run
SuSE's /sbin/lilo to enable Red Hat. We will never run Red Hat's
/sbin/lilo
Revisiting LILO
We've just rebooted the computer. SuSE is running.
We had earlier looked briefly at its /etc/lilo.conf
I've added a couple of reasonably self-explanatory commands to it:
boot=/dev/hda # write your 512 bytes to the MBR
install=/boot/boot.b # write the installer code to /boot/boot.b
# and put /boot/boot.b's address into the MBR
map=/boot/map # write the map code to /boot/map
# and put /boot/map's address into /boot/boot.b
prompt # when the computer boots, give me a boot prompt
timeout=50 # and give me 5.0 seconds to respond to it
default=SuSE # If I don't respond, use this default label
This code is only the "global" portion of a LILO configuration file. Now we
need to write portions that will each pertain to a single operating system.
These portions are called "stanzas". (In a poem or song, each verse may also
be called a "stanza". Think of it that way.) The following are the stanzas
as originally written by the installation (with only slight editing.)
#######################################
image = /boot/vmlinuz
label = SuSE
root = /dev/hda5
initrd = /boot/initrd
#######################################
image = /boot/vmlinuz.suse
label = OldSuSE
root = /dev/hda5
initrd = /boot/initrd.suse
#######################################
Stanzas are introduced with by
- either the keyword image, which indicates that we're talking
about a Linux image here
- or the keyword other which indicates that we're talkin
about some other arbitrary system.
Now I'm going to add another stanza for Red Hat. For the most part, the
following is lifted directly out of Red Hat's copy of its
/etc/lilo.conf -- however there is one very important
distinction.
- In Red Hat's /etc/lilo.conf, the device specified
for the Red Hat image was /boot
- In the SuSE /etc/lilo.conf, the device specified
for the Red Hat image must be /RMboot
Think about it. SuSE's /RMboot and Red Hat's /boot are the
very same thing!
Under SuSE, its mount point is /RMboot
Under Red Hat, its mount point is /boot
Since we're going to be running /sbin/lilo from SuSE, we must use
/RMboot
#######################################
image = /RHboot/vmlinuz-2.2.14-5.0
label = RedHat
read-only
root = /dev/hda10
#######################################
So here's what the entire SuSE /etc/lilo.conf now looks like, with
all the pieces brought together:
boot=/dev/hda # write your 512 bytes to the MBR
install=/boot/boot.b # write the installer code to /boot/boot.b
# and put /boot/boot.b's address into the MBR
map=/boot/map # write the map code to /boot/map
# and put /boot/map's address into /boot/boot.b
prompt # when the computer boots, give me a boot prompt
timeout=50 # and give me 5.0 seconds to respond to it
default=SuSE # If I don't respond, use this default label
#######################################
image = /boot/vmlinuz
label = SuSE
root = /dev/hda5
initrd = /boot/initrd
#######################################
image = /boot/vmlinuz.suse
label = OldSuSE
root = /dev/hda5
initrd = /boot/initrd.suse
#######################################
image = /RHboot/vmlinuz-2.2.14-5.0
label = RedHat
read-only
root = /dev/hda10
#######################################
Some review notes
- Remember that only making changes to /etc/lilo.conf
won't have any affect on your next re-boot.
/etc/lilo.conf is only a configuration file that the
/sbin/lilo program uses when it goes about making
changes. So, those changes won't happen until you run the
/sbin/lilo program.
- The top of the /etc/lilo.conf configuration file is the
global area, which defines parameters relevant to the whole
process.
- One or more stanzas follow the global area. Each stanza
defines parameters relevant to a particular operating system. Each
stanza is introduced by the keyword image=so-and-so
- When /sbin/lilo runs, it calculates and stores the physical
address pointers (not filesystem names) of files indicated in the
global section as well as the kernel operating system mentioned in
each stanza.
Thus, if you've rebuilt your kernel, -- even if you've given the new
kernel the same name as the old one (which is probably not a good
idea) -- you must remember to run /sbin/lilo again. Why?-
because you're new kernel isn't at the same physical location anymore.
There are many other parameters that may exist in
the /etc/lilo.conf configuration file. They go in either the
GLOBAL section because they are relevant to the whole thing or in a
STANZA section because they are relevant to a particular operating
system.
MBR is not the only option
In /etc/lilo.conf, the boot= line indicates where you
want /sbin/lilo to say "this boot processes begins here."
- boot=/dev/hda is the MBR of /dev/hda
- boot=/dev/hdaN is the boot sector of /dev/hda's
Nth partition.
Why might you wish /sbin/lilo to construct a chain of events that
starts at something other than the MBR, say /dev/hda3? Afterall,
when the computer starts up it is the MBR that gets accessed, isn't
it?
Yes, that's true. But if you have already installed another operating system
and it has written the MBR, you might wish to leave the MBR relatively
untouched. In your /etc/lilo.conf you could specify
boot=/dev/hda3 which would tell /sbin/lilo to write
its boot-up instructions there instead.
This tells /sbin/lilo not to touch the MBR at all. But you do
need to touch it just a little. Otherwise, the computer will still
boot referencing the MBR and won't know of the instructions which you've
put in the boot sector of /dev/hda3. You have to go one small
step further.
Remember those 64 bytes in the MBR that contain the partition table?
Besides containing the locations of up to 4 partitions, there is also an
indicator that says which one of them, if any, is considered active,
also known as bootable.
If one of those partitions is indeed active, then the boot-up procedure
will jump to the boot sector of that partition in order to continue the
boot-up process.
So how do you make a particular parition active/bootable?
The program fdisk is available in both the Windows and Linux
worlds. (Several variants are available in Linux). One of the things that
fdisk can do is to mark a particular partition as
active/bootable.
- Run Linux's fdisk /dev/hdwhatever and type "m" for
"menu" where you'll see a list of its available commands which
includes "a" for "activate" a partition.
- Type "a" to tell fdisk that you wish to
activate a partition. It must be one of partitions 1 through 4
where you've told /sbin/lilo to put its stuff.
- Type "w" to tell fdisk that you wish to
write the partition table and exit.
- There are other commands available such as:
p to print the partition table.
q to quit without doing anything
Because this process hardly effects the MBR at all, the original MBR can
be put back again without running /sbin/lilo. All that is necessary
is to modify the active/bootable partition with fdisk.
To summarize
- You can instruct /sbin/lilo to write its stuff to
the boot sector of a particular partition of a particular disk
rather than the disk's MBR.
- You would want to do so if you wanted to leave the MBR as untouched
as possible
- You must run fdisk and activate that partition.
Other command line parameters
There are many command line parameters that may be specified when you run
the /sbin/lilo program. Let's look at some of them.
-t
-v -t
-v -v -t
-v -v -v -t |
The -t (as in test) command line option
tells /sbin/lilo to test things without altering
the way things are. /sbin/lilo reports on things and
assures you "The boot sector and the map file have *NOT* been
altered."
Specifying one or more -v's as in verbose,
requests /sbin/lilo to progressively report its findings
with more and more detailed verbosity. |
Yet to be done
- Examination of other commands in /etc/lilo.conf
- Using "other" to boot up a non-Unix operating system
- Discussion of rdev
- Sources of reference
|