
A simple description of how Linux boots:

( This description is a simple approximation of what's happening, 
but may not be 100% accurate in detail. )

1) The kernel needs to get into memory and it is loaded into
memory by a boot loader.

2) The kernel normally has a "boot loader" put on the front (i.e.
in the beginning of the kernel image). 

3) The kernel proper (i.e. the part that gets put into memory) is
gzip'ed into a file that is 30-40% the size of the corresponding
memory image.  This is done after compilation and linking when
the kernel is created.  An uncompress routine is included in the
kernel's boot loader.

4) In any boot sequence, the system BIOS runs first and finds
the boot disk from CMOS RAM, usually starting with the floppy
(A:) and then the hard disk (C:).  The BIOS activates the drive,
then reads the first block (512 bytes) from the drive into
memory and executes the block's image as a binary program.  The
boot program then can proceed to read other parts of the same
disk or another disk, or can read the keyboard or display a menu.
This is called "bootstrapping" or "booting".

5) To set up the hard disk boot process, you run the lilo program
which installs itself either on the boot sector of the HD or in
the first block of a partition (set by /etc/lilo.conf).  (It's
much safer to install lilo in the Linux partition only, since
then other OS's like W31 or W95 or OS/2 don't notice it. You make
the Linux partition active and then lilo runs upon booting,
allowing you to set up an automatic or manual boot.  Lilo in
either location has the ability to boot any OS including Linux on
any partition on any HD. Some OS's don't boot from the second HD,
but Linux can...) 

6) After the BIOS starts the lilo boot program on the first sector
of the disk, lilo finds the kernel image (from an internal table
generated by /etc/lilo.conf when you run lilo to set the boot),
and runs it.

7) It is possible to boot the kernel without lilo simply by
copying the kernel to the beginning of a disk (i.e. usually a
floppy).  In this case the first sector on the disk is the first
part of the boot loader in the kernel. You can make a boot floppy
for your HD this way by telling the kernel what the root
partition is with "rdev /dev/f0 /dev/hda1".

8) The boot loader in the kernel gets run.  It decompresses the
kernel image, checks RAM memory, and loads the image into the
proper location in RAM memory and executes it.  If you pass
parameters (through lilo in /etc/lilo.conf or from another boot
sequence like a Slackware boot disk) to the kernel it can modify
what happens in the boot sequence.  Another way to do this is to
set some parameters with "rdev" which modifies a special set of
locations in the kernel image (the part that is not compressed).   

9) The kernel runs and finds what the root partition should be.
There are several places the kernel can look to find what the
root partition should be: 1) it can assume the current drive, 2)
the drive described in the "rdev" parameter, 3) or the drive
listed in the "/" line in /dev/fstab.

10) The kernel mounts the root partition.  This can be very
simple, just a matter of running "mount" on the hard drive.  Or
it can be more complex, where the root partition is a RAM disk
that needs to be read in from a floppy.  There is a "rdev"
parameter in the kernel that tells the kernel to make the root
disk a RAM disk, and another to describe which disk it is, and
another to describe where to find the ramdisk image, as an offset
in 1K blocks from the beginning of the disk (for more on this,
read /usr/src/linux/Documentation/ramdisk.txt in any Linux
system).  The ramdisk driver in the kernel can detect whether the
ramdisk image is compressed, and will automatically uncompress it
if so.

11) The kernel runs the "/sbin/init" program, which starts up the
software boot sequence described in /etc/inittab.  Normally this
sequence starts with a single-user system, checking the
filesystems with "fsck" before remounting them "rw" (read-write)
and then running any background daemons before going multi-user
and running a version of the "getty" program to allow logins.

12) The /etc/inittab file contains entries that activate commands
when a "runlevel" is reached.  Normally the "S" or "1" runlevel
is the first to run, and this activates the /etc/rc.d/rc.S
script.  Next, the runlevel is set to the default runlevel
"initdefault" which can be 3, 4, or 5, and the /etc/rc.d/rc.M
script runs.

13) The difference between the normal HD boot sequence and the 
cramdisk boot sequence is that:

  a) In a hard disk, the kernel is normally (not always) inside
  the filesystem on the disk (If necessary, lilo can find the
  kernel on some other HD partition or in a floppy). However, in
  the cramdisk, the kernel is not inside the filesystem image; it
  is copied separately onto the floppy, starting at the boot
  sector (sector 0 of track 1) with the remainder of the
  (compressed) kernel immediately following.  The reason for this
  is that the boot sector must be uncompressed, and since the
  filesystem is compressed, the kernel must remain outside the
  kernel (i.e.  copied separately).  This is efficient and OK, as
  most of the kernel is also compressed.  Only the boot loader
  and the parameters need to remain uncompressed.

  b) Lilo is not used, as the boot loader in the kernel is placed
in the boot sector and executed directly by the BIOS.

  c) When the kernel is uncompressed in RAM memory, it checks the
ramdisk parameter (set by rdev) and finds the floppy device containing
the ramdisk image (i.e. filesystem), which may be compressed (but
need not be).  The kernel finds the offset for where to start
copying the filesystem, and if it finds the signature of "gzip"
there it assumes that the filesystem is compressed and ungzips it.

  d) When the cramdisk filesystem is uncompressed and loaded into
RAM, it takes up RAM that cannot be used for executing commands.
So one needs to strike a balance between the size of the
filesystem and the remaining RAM.  In a 4MB system, a cramdisk is
difficult to set up because a Linux kernel needs about 1 MB, the
filesystem needs about 1.5 MB of commands and libraries to be useful,
and that leaves only 1.5 MB for running processes.  Since there
is no swap space, all processes must reside in memory. Background
processes in Linux are notorious for eating memory.

That's more or less what happens.

A good place to read more about this is:

  sunsite.unc.edu:/pub/Linux/docs/HOWTO  (grep for lilo, boot, install)
and
  sunsite.unc.edu:/pub/Linux/docs/linux-doc-project

and, for the cramdisk, the file:

  /usr/src/linux/Documentation/ramdisk.txt
 
 which is included in the cramdisk-2.0 distribution.

Hope this is useful in understanding what goes on with booting.
(Let me know if you find any major inaccuracies.)

Rob Smith
