[nSLUG] kernel setup stack overlaps lilo

bdavidso at supercity.ns.ca bdavidso at supercity.ns.ca
Mon Mar 15 01:18:39 AST 2004


On Sun, 14 Mar 2004, Peter Cordes wrote:

> There's a 512 byte "stage 1" program in the master boot record, that the
> BIOS boots directly.
>  There's a ~8kB "stage 1.5" piece of code that groks ext2/3, and it is at the
> beginning of my ext3 partition.  Apparently partitions and/or filesystems
> leave some space at the beginning for bootable code, which is why you can
> use lilo with boot=/dev/hda3, for example.  Apparently it's big enough to

Yes, there is a boot sector at the start of every partition, as well as
the master boot record.  But I don't think it's big enough to hold 8k, I
think it is 512 bytes in every case. The lilo docs, the latex ones not
the man pages, do a good job of explaining this.  So I think what is in
your partition boot sector does not hold the entire stage-1.5.

Oh, here it is in the GRUB docs:

"The optional Stage 1.5 can be installed in a filesystem, in the boot
loader area in a FFS or a ReiserFS, and in the sectors right after a MBR,
because Stage 1.5 is enough small and the sectors right after a MBR is
normally an unused region. The size of this region is the number of
sectors per head minus 1."

Clever, they rely on the fact that the first partion will not start within
the first track of the first head, so you get something like 62 sectors
(31kB) of unused space.  OTOH, all stage1 needs is the sector starting
address of stage1.5, so it can reside in the filesystem, but I guess then
you need to be careful not to move or overwrite those files.

>  The ~100kB stage2 is the full thing.  It reads the config file, carries out
> the commands in it, and displays a menu of boot options.  Depending on the

That's the cool part.  When I set up a RH9 system with grub last year and
updated the kernel, I couldn't believe that just listing the new kernel in
the config file was enough to boot it.  In fact, I wasted a bunch of time
trying to figure out how to do the equivalent of "/sbin/lilo"  before I
gave up, rebooted, and lo! there was the new kernel.  Imagine, a boot
loader that reads its config file at boot time!

On RH, /boot/grub/menu.lst is a link to /boot/grub/grub.conf, which makes
it easier for people like me to find.

The important parts look like this:

title Red Hat Linux (2.4.20-24.9bigmem)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-24.9bigmem ro root=LABEL=/ hdd=ide-scsi
        initrd /initrd-2.4.20-24.9bigmem.img
title Red Hat Linux (2.4.20-8)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdd=ide-scsi
        initrd /initrd-2.4.20-8.img

(I see I need to upgrade that kernel again...)

The drive designations and numbering system take a little getting used to.
Because /boot is a partition (/dev/hda1 in this case) all file references
are relative to /boot.  I guess that's what the "root (hd0,0)" does.

Bill Davidson
bdavidso at supercity.ns.ca

More information about the nSLUG mailing list