Subject: Re: Boot Sequence, partitions, labels, etc.
To: K. Richard Pixley <K.Richard.Pixley@nominum.com>
From: Neil Ludban <nludban@columbus.rr.com>
List: port-i386
Date: 07/15/2003 17:28:37
"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
> 
> 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?

From what I remember of biosboot (sys/arch/i386/stand/biosboot/),
the disklabel is the second sector in the netbsd partition.  If the
disk is dedicated (netbsd partition == entire disk) that would also
make it the second sector of the disk.  The first sector of the
netbsd partition can be used as a MBR (BIOS signature and dummy
partition table).

Just to fill in a piece missing from the old post, the code in the
first sector of the NetBSD partition blindly loads the first 15
sectors of the NetBSD partition to memory (0x1000:0000) (reloads
itself, then the disklabel, and another 13 sectors), this code
then reads more sectors using the offsets in the "fraglist" table
built by installboot(8), which correspond to the data blocks for
the "/boot" file.  (Note: moving "/boot" or the raw partition
will make the partition unbootable.)

> 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?

Looks like the MBR (/usr/src/sbin/fdisk/mbr/mbr.S) looks for the
first active partition, then the second stage uses the first netbsd
partition (/sys/arch/i386/stand/lib/crt/bootsect/start_bootsect.S).
Not necessarily the same thing...

> 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?

One per disk, given the NetBSD naming scheme.  Not sure how that's
created or stored, I don't have any multi-boot boxes :)

> 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?
> 
> 6) As I understand it, the "a" partition must be root and root must be
>    on the "a" partition in order to boot.  Furthermore, the "a"
>    partition must start at the beginning of the netbsd slice.
> 
>    Is this a requirement of the netbsd kernel?  Or only of the
>    standard primary and secondary boot blocks?

The kernel should be loadable from any partition.  The installboot
has to be used on the partition which physically starts at the
same offset as "c" (the disklabel partition corresponding to the
MBR partition for NetBSD), which is normally "a".

>    Put another way, can I duck this requirement if I use an alternate
>    boot loader like grub?
> 
> What I'm trying to accomplish is several, alternately bootable, netbsd
> root filesystems on the same disk.

I think the sanest way is a single MBR partition for NetBSD, and
configure each kernel with "root on wd0X" options.  You're probably
going to want to share swap and some filesystems anyway.

-Neil