Subject: Re: Booting to a device other than /dev/wd0a
To: <>
From: David Laight <david@l8s.co.uk>
List: port-i386
Date: 01/15/2003 18:15:23
> Now here's my understanding of what happens inside installboot:
> 
>   1) The installboot command looks at the biosboot.sym (or whatever)
>      and splits it up into two parts.
>   2) The first part it sticks up in the MBR (very first part of the
>      disk), whose sole purpose is to find out where the second part
>      is.
>   3) It then puts the second part wherever you specified (by the
>      second argument there).
> 
> When the system boots, that first part is stuck thinking that it
> needs to find the second part at wd0a, when it's perfectly capable
> of seeing it at wd0b (else I wouldn't be able to boot it by hand).

What actually happens is:

1) The bios reads sector zero of the disk (master boot record = mbr)
   to address 7c0:0 and jumps to the start of it.
   This code decides which of the 4 bios partitions is the active
   one, reads the first sector of it (the partition boot record = pbr)
   to address 7c0:0 and jumps to the start of it.

2) The pbr code re-reads sector zero in order to find the partition
   from which it was (probably) read (by searching the table for
   a partition of the correct type), and reads more of the bootcode
   from that partition.

for netbsd (the above is generic for x86 PCs)

2a) the first (IIRC) 16 sectors of the bios partition are read
   to address 0x1000:0.  The code jumps to further code in the
   3rd sector (the 2nd is the netbsd disklabel).

   At this point we start executing 32bit x86 code written in C.

3) A table of disk sector number/sector count pairs is used to
   read in the rest of the 'boot' program.  (This code has to be
   careful to only use code/data that was read in during 2a.)

4) The interactive 'boot' program decides which disk and kernel
   to read.  The kernel is read into memory using bios disk read
   commands.

5) The kernel startes running and re-reads sector 0 in order to
   find the netbsd partition and hence the disklabel.
   It also has to determine the mapping between the bios disk
   numbers and the disk controllers.

The mbr code is set by fdisk.

/usr/mdec/installboot extracts the code and data from biosboot.sym
and copies it to /boot.   The first 16 sectors are written to the
start of the filesystem partition (the fs reserves this space)
and the table for (3) above in it is updated.

This has the (maybe undocumented) restriction that root filesystem
(or at least the one that the kernel is loaded from) be at the
start of the bios partition.

	David

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