Contents
Stage 0: Master Boot Record
- MBR source:
sys/arch/i386/stand/mbr/mbr.S
- MBR binaries:
/usr/mdec/mbr_*
Error messages:
- "Error x"
- "No active partition" - use fdisk(8) to mark one of the MBR partitions as "active"
- "Disk read error"
- "No operating system" - PBR magic number was wrong
- "Invalid CHS read" - CHS vs LBA check selected LBA reads, but BIOS does not support them
MBR is read by the BIOS and then validated (checked for magic number 0xaa55 at the end). If validation fails, BIOS may print evil error message and/or try next boot device; otherwise, BIOS passes control to MBR.
Unless it was compiled with NO_BANNER
, MBR displays its banner: "NetBSD MBR
Boot". Next, it checks if CHS or LBA addressing must be used in further BIOS
I/O calls. Since partition table entry stores both linear and CHS address,
linear address is computed from CHS address, and if it matches stored linear
address - MBR will use CHS addressing. LBA addressing will be tried otherwise,
even if it is not supported by BIOS.
PBR is then loaded from 1st sector of active partition (or, if boot selector was compiled into this MBR, it may be loaded from another partition or disk).
Stage 1: Partition Boot Record, bootxx
- PBR source:
sys/arch/i386/stand/bootxx/pbr.S
- bootxx source:
sys/arch/i386/stand/bootxx/bootxx.S
- combined PBR+bootxx binaries:
/usr/mdec/bootxx_*
Error messages:
- '2' or "Disk read"
- 'B' or "Not a bootxx image" - phase 1 bootstrap's magic number was wrong
- 'P' or "No NetBSD partition"
- 'L' or "Invalid CHS read" - see above
PBR loads phase 1 bootstrap (bootxx) from next 15 sectors on disk, validates and runs it.
bootxx displays its banner: NetBSD/(machine) (filesystem) Primary Bootstrap
and tries to load phase 2 bootstrap (boot2) from several locations:
- start of MBR partition; or
- start of MBR partition + RAIDframe offset; or
start of partition 'a' in disklabel.
bootxx error messages:
- "Boot failed (errno <...>): <...>"
- All further messages are printed by boot2. For example, a single "0" and no other messages on PC console means that boot2 has autodetected and is using serial console.
Stage 2
- boot2 source:
sys/arch/i386/stand/boot/
- boot2 binary:
/boot
Glossary
BIOS
Basic Input-Output System
MBR
Main Boot Record, stored at LBA 0
PBR
Partition Boot Record, stored in first sector of bootable partition
CHS
Cylinder, Head, Sector addressing
LBA
Linear Block Address[ing]