1.\" $OpenBSD: boot_amd64.8,v 1.6 2007/05/31 19:19:59 jmc 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: May 31 2007 $ 29.Dt BOOT_AMD64 8 amd64 30.Os 31.Sh NAME 32.Nm boot_amd64 33.Nd amd64 system bootstrapping procedures 34.Sh DESCRIPTION 35.Ss Cold starts 36The 37.Tn Athlon64 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 eventually load the 129.Ox -specific 130amd64 bootstrapping code. 131This versatile program is described in a separate document, 132.Xr boot 8 . 133Other bootstrapping software may be used, and can chain-load the 134.Ox 135bootstrapping code, or directly load the kernel. 136In the latter case, refer to your bootloader documentation to know which 137options are available. 138.Ss Abnormal system termination 139In case of system crashes, the kernel will usually enter the kernel 140debugger, 141.Xr ddb 4 , 142unless it is not present in the kernel, or it is disabled via the 143.Em ddb.panic 144sysctl. 145Upon leaving ddb, or if ddb was not entered, the kernel will halt the system 146if it was still in device configuration phase, or attempt a dump to the 147configured dump device, if possible. 148The crash dump will then be recovered by 149.Xr savecore 8 150during the next multi-user boot cycle. 151It is also possible to force other behaviours from ddb. 152.Sh FILES 153.Bl -tag -width /usr/mdec/biosboot -compact 154.It Pa /bsd 155default system kernel 156.It Pa /bsd.mp 157multi-processor capable kernel 158.It Pa /bsd.rd 159standalone installation kernel, suitable for disaster recovery 160.It Pa /usr/mdec/mbr 161system MBR image 162.It Pa /usr/mdec/biosboot 163system primary stage bootstrap (PBR) 164.It Pa /usr/mdec/boot 165system second stage bootstrap (usually also installed as 166.Pa /boot ) 167.It Pa /usr/mdec/pxeboot 168PXE bootstrap 169.El 170.Sh SEE ALSO 171.Xr ddb 4 , 172.Xr boot 8 , 173.Xr halt 8 , 174.Xr init 8 , 175.Xr installboot 8 , 176.Xr pxeboot 8 , 177.Xr reboot 8 , 178.Xr savecore 8 , 179.Xr shutdown 8 180.Sh BUGS 181The 182.Dq PC BIOS Architecture 183makes this process very prone to weird and 184wonderful interactions between different operating systems. 185.Pp 186There is no published standard to the MBR and PBR, 187which makes coding these a nightmare. 188