Subject: Re: Boot Sequence, partitions, labels, etc.
To: <>
From: David Laight <david@l8s.co.uk>
List: port-i386
Date: 07/16/2003 09:45:53
On Tue, Jul 15, 2003 at 10:32:20AM -0700, K. Richard Pixley wrote:
> I'm confused about the boot sequence, disk partitions, labels, etc.
> So before I go digging through code I have some questions.  If these
> are answered elsewhere, I'll be happy to follow any pointers offered.
> 
> 1) Aside from the "hard partition" type being now obsolete, (ie, we're
>    using NetBSD now rather than 386BSD), is this old post still pretty
>    current?
> 
>    http://mail-index.netbsd.org/port-i386/1995/07/20/0002.html

It is as inaccurate as it ever was :-)
The i386 boot process goes:
1) bios loads sector zero (the mbr) to 0x7c0:0 and jumps to it
2) mbr code looks at the mbr partition table, picks a partition
   (traditionally the 'active' one) and lodas its first sector
   (the pbr (partition boot record)) to 0x7c0:0 and jumps to it.
The rest is os dependant, but for netbsd it used to be like:
3a) pbr code re-reads sector zero to find the netbsd partition [1],
   reads sectors 0 to 13 of the netbsd partition to (IIRC) 0x1000:0
   and jumps to code in the 3rd sector.
4a) This code uses a sector number list to read the rest of itself from
   the sectors that contain the file /boot.
5a) You now have the interactive bootloader running.
Netbsd now does:
3b) pbr code re-reads sector zero to find the netbsd partition [1],
    reads sectors 0 to 14 to 0x600 and jumps to the start of the 3rd sector.
4b) the bootxx code (just loaded) now uses the filesystem structure to
    find the /boot file and reads it to 0x1000:0 and jumps into it.
5b) You now have the interactive bootloader running.

[1] Traditinally the pbr code cannot tell where it was loaded from,
restricting you to a single bootable fs of each type.  I've recently
changed this so that the start sector is passed through and the pbr
code looks for a netbsd partition that starts at the right place.

> 2) The above post suggests that the bsd disklabel is ordinarily stored
>    in the NetBSD slice, unless the disk is completely devoted to
>    NetBSD, in which case it's at the beginning of the disk.  I
>    couldn't find any other statements about this in any of the other
>    doc.
> 
>    Where is the bsd disklabel stored?  Is it at the beginning of the
>    disk?  At the beginning of the NetBSD "slice" in the MBR/dos
>    partition table?  Somewhere else?

On i386 the netbsd disklabel is stored in the second sector of the
first netbsd partition.
If the disk doesn't have a netbsd partition then the kerenl may look
for a disklabel in sector 1.

> 3) All the netbsd doc I could find, as well as the above post, refer
>    to "the netbsd" slice or hard partition.  I'm guessing that they
>    really mean, "the first netbsd" slice in the MBR.  Am I guessing
>    correctly?

souds right

> 4) It appears as though that assumption, "the first netbsd" slice,
>    implies that while there's room for a second bsd disklabel on a
>    second netbsd slice, it could never be read.  Is this correct?

Yes, and don't even try to create one! you will trash the contents
of your filesystems (or at least I did).
 
> 5) As far as I can tell, the MBR partition table is used for two
>    things.  First, to find the secondary boot block.  And second, to
>    find the bsd disklabel.  This implies that the size and ending
>    location of the netbsd slice are largely irrelevant, yes?

The start is important, the size/end not.  Except that you could
get confused about the allocated space if you run a different OS's
fdisk program

> 6) As I understand it, the "a" partition must be root and root must be
>    on the "a" partition in order to boot.

Not true:
$ df -k
Filesystem  1K-blocks     Used     Avail Capacity  Mounted on
/dev/wd0h     2087630  1593929    389319    80%    /

>    Furthermore, the "a"
>    partition must start at the beginning of the netbsd slice.

The boot code reads stuff from the filesystem that is at the start of
the netbsd slice, the interactive loader (the first code that actually
looks for the netbsd partition) will default to booting a kernel from
the same filesystem regardless as to which netbsd partition it is.

>    Is this a requirement of the netbsd kernel?  Or only of the
>    standard primary and secondary boot blocks?

Yes and no...

>    Put another way, can I duck this requirement if I use an alternate
>    boot loader like grub?

Grub won't let you do anything clever...

> What I'm trying to accomplish is several, alternately bootable, netbsd
> root filesystems on the same disk.

Why didn't you say so earlier :-)

If you are running 'current', just set up multiple netbsd partitions [2].
Put your root filesystem at the start of additional partition and
use the netbsd bootselect code to load it.
The systems will all share the same disklabel - read from the first
netbsd partition (maybe it should be written to all of them).

I think that sysinst will DTRT.

[2] You can use 'extended' partitions as well.

	David

-- 
David Laight: david@l8s.co.uk