1.\" $OpenBSD: boot_i386.8,v 1.17 2016/02/25 09:43:52 tb Exp $ 2.\" 3.\" Copyright (c) 1997 Tobias Weingartner 4.\" 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd $Mdocdate: February 25 2016 $ 29.Dt BOOT_I386 8 i386 30.Os 31.Sh NAME 32.Nm boot_i386 33.Nd i386 system bootstrapping procedures 34.Sh DESCRIPTION 35.Ss Cold starts 36The 37.Tn IBM PC 38computers and clones will perform a POST (Power On Self Test) upon 39being booted cold. 40This test will find and initialize memory, keyboard, and other devices. 41It will search for and initialize any extension ROMs that are present, 42and then attempt to boot the operating system from an available boot 43drive. 44.Pp 45The boot drive is usually specified in the BIOS setup. 46.Ss Warm starts 47The BIOS loads the first block (at physical location: track 0, head 0, 48sector 1) off the boot device into memory, and if the last two bytes in the 49block match the signature 0xAA55, the BIOS considers the block a valid 50bootable drive. 51The BIOS then proceeds to call the machine code program in this block. 52If the BIOS is current, it will also pass the boot drive 53to the boot block in register %dl. 54.Pp 55There are two different types of boot blocks on devices. 56There is the 57MBR (master boot record) and the PBR (partition boot record). 58A digression 59into a little piece of history will quickly give light as to why this is so. 60In the beginning, the PC 61.Dq architecture 62came with single or dual floppy 63drives, and no hard drives. 64The only type of bootable sectors on any device were the PBRs. 65They were responsible for loading the rest of the operating 66system from the correct device. 67When hard disks came out, it was felt that 68such a huge space should be able to be partitioned into separate drives, 69and this is when the MBR was invented. 70.Pp 71The MBR relocates itself upon being loaded and invoked by the BIOS. 72Embedded within the MBR is a partition table, with four partition table 73entries. 74The MBR code traverses this table (which was loaded with the 75MBR by the BIOS), looking for an active entry, and then loads the MBR or 76PBR from the disk location specified by the partition table entry. 77So in reality, the MBR is nothing more than a fancy chaining PBR. 78.Pp 79Note: The MBR could load another MBR, which is the case when you are booting 80off an extended partition. 81In other words, the first block of an extended 82partition is really an MBR, which will then load the corresponding MBR or PBR 83out of its extended partition's partition table. 84.Ss Geometry translation 85.Em WARNING : 86This portion of the 87.Dq PC BIOS Architecture 88is a mess, and a compatibility nightmare. 89.Pp 90The PC BIOS has an API to manipulate any disk that the BIOS happens to 91support. 92This interface uses 10 bits to address the cylinder, 8 bits to 93address the head, and 6 bits to address the sector of a drive. 94This restricts any application using the BIOS to being able to address only 951024 cylinders, 256 heads, and 63 (since the sectors are 1 based) sectors 96on a disk. 97These limitations proved to be fine for roughly 3 years after 98the debut of hard disks on PC computers. 99.Pp 100Many (if not all) newer drives have many more cylinders than the BIOS API 101can support, and likely more sectors per track as well. 102To allow the BIOS the ability of accessing these large drives, the BIOS would 103.Dq re-map 104the 105cylinder/head/sector of the real drive geometry into something that would 106allow the applications using the BIOS to access a larger portion of the 107drive, still using the restricted BIOS API. 108.Pp 109The reason this has become a problem is that any modern OS will use its own 110drivers to access the disk drive, bypassing the BIOS completely. 111However, 112the MBR, PBR, and partition tables are all still written using the original 113BIOS access methods. 114This is for backwards compatibility to the original IBM PC! 115.Pp 116So the gist of it is, the MBR, PBR, and partition table need to have BIOS 117geometry offsets and cylinder/head/sector values for them to be able to 118load any type of operating system. 119This geometry can, and likely will, 120change whenever you move a disk from machine to machine, or from controller 121to controller. 122.Em They are controller and machine specific . 123.Ss Boot process options 124On most 125.Ox 126systems, booting 127.Ox 128from the BIOS will load the 129.Ox Ns -specific 130first-stage bootstrap, 131.Xr biosboot 8 , 132which in turn will locate and load the second-stage bootstrap, 133.Xr boot 8 . 134Other bootstrapping software may be used, and can chain-load the 135.Ox 136bootstrapping code, or directly load the kernel. 137In the latter case, refer to your bootloader documentation to know which 138options are available. 139.Ss Abnormal system termination 140In case of system crashes, the kernel will usually enter the kernel 141debugger, 142.Xr ddb 4 , 143unless it is not present in the kernel, or it is disabled via the 144.Em ddb.panic 145sysctl. 146Upon leaving ddb, or if ddb was not entered, the kernel will halt the system 147if it was still in device configuration phase, or attempt a dump to the 148configured dump device, if possible. 149The crash dump will then be recovered by 150.Xr savecore 8 151during the next multi-user boot cycle. 152It is also possible to force other behaviours from ddb. 153.Sh FILES 154.Bl -tag -width /usr/mdec/biosboot -compact 155.It Pa /bsd 156default system kernel 157.It Pa /bsd.sp 158single processor capable kernel 159.It Pa /bsd.mp 160multiprocessor capable kernel 161.It Pa /bsd.rd 162standalone installation kernel, suitable for disaster recovery 163.It Pa /usr/mdec/mbr 164system MBR image 165.It Pa /usr/mdec/biosboot 166system primary stage bootstrap (PBR) 167.It Pa /usr/mdec/boot 168system second stage bootstrap (usually also installed as 169.Pa /boot ) 170.It Pa /usr/mdec/pxeboot 171PXE bootstrap 172.El 173.Sh SEE ALSO 174.Xr ddb 4 , 175.Xr biosboot 8 , 176.Xr boot 8 , 177.Xr halt 8 , 178.Xr init 8 , 179.Xr installboot 8 , 180.Xr pxeboot 8 , 181.Xr reboot 8 , 182.Xr savecore 8 , 183.Xr shutdown 8 184.Sh BUGS 185The 186.Dq PC BIOS Architecture 187makes this process very prone to weird and 188wonderful interactions between different operating systems. 189.Pp 190There is no published standard to the MBR and PBR, 191which makes coding these a nightmare. 192.\" .Pp 193.\" Somebody *please* write me a decent BIOS, and make them (the masses) use it! 194