1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
.\" $OpenBSD: biosboot.8,v 1.18 2004/01/26 23:21:49 tom Exp $
.\"
.\" Copyright (c) 2003 Tom Cosgrove <tom.cosgrove@arches-consulting.com>
.\" Copyright (c) 1997 Michael Shalayeff
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 23, 2003
.Dt BIOSBOOT 8 i386
.Os
.Sh NAME
.Nm biosboot
.Nd
i386-specific first-stage system bootstrap
.Sh DESCRIPTION
This small program (roughly 512 bytes of code) is responsible for
loading the second-stage
.Xr boot 8
program (typically /boot), which in turn will load the kernel.
.Pp
.Nm
must be installed by
.Xr installboot 8 .
As part of the installation,
.Xr installboot 8
patches
.Nm
with information about the location of
.Xr boot 8
on disk.
Specifically, it writes the filesystem block number of
.Xr boot 8 's
inode,
the offset within this block of the inode,
and various filesystem parameters (taken from the superblock)
required to convert filesystem blocks to disk sectors.
.Pp
You must re-run
.Xr installboot 8
whenever
.Xr boot 8
is changed, as its inode may change.
While it should not be necessary,
it may also be advisable to re-run
.Xr installboot 8
if you move your disk between machines and/or controllers.
.Pp
When
.Nm
receives control from either the BIOS or the
master boot record (MBR) it will print the message:
.Pp
.Dl Loading
.Pp
followed by a dot for every filesystem block it attempts to load.
If /boot is loaded successfully,
.Nm
will put the cursor on the next line just before
transferring control to the newly-loaded program.
.Pp
If possible,
.Nm
will read disk sectors using calls detailed in the Phoenix
Enhanced Disk Drive Specification (EDD, sometimes known as LBA, reads).
It will fall back to CHS reads only if EDD calls are not available.
However, to allow users to boot on hardware that claims LBA capability,
but which requires CHS reads in order to boot,
the user may hold down either Shift key during boot.
If
.Nm
detects this, it will force itself to use CHS calls, ignoring
any LBA capability.
This will of course prevent booting if /boot lies above the 8 GB
CHS limit.
There is an exported symbol
.Dq force_chs
of type u_int8_t
which may be set to 1 to force CHS reads always.
(However, no tool is currently provided to set this flag.)
.Sh DIAGNOSTICS
.Nm
prints a
.Sq !\&
before the
.Dq Loading
message if it is being forced to use CHS rather than LBA reads
(by the user holding down either Shift key during boot,
or having set the
.Dq force_chs
flag in the boot sector).
.Pp
.Nm
prints a
.Sq ;\&
after the
.Dq Loading
message if it is going to use CHS reads for any reason.
For example, when booting from floppy or CD-ROM.
.Pp
.Nm
may fail with any of the following error messages:
.Bl -tag -width ERR_X__
.It Er ERR I
Too many indirect blocks.
.Nm
is capable of reading the direct blocks in
.Xr boot 8 's
inode (the location of which is patched into
.Nm
by
.Xr installboot 8 )
and the first indirect block,
but it is not capable of reading further indirect blocks.
This error indicates that further such indirect blocks were found.
The system will not be able to boot.
.Pp
This is unlikely to ever happen in practice, as
.Xr boot 8
has to be quite large for this to be an issue.
The smallest possible filesystem block size is 512 bytes
(one sector per filesystem block).
On such a system, there are 140 filesystem blocks that
.Nm
can read, so
.Xr boot 8
can be up to 70 KB.
.Pp
However, even on floppy disks the filesystem block size is 1024 bytes.
This allows
.Xr boot 8
to occupy up to 268 disk blocks,
i.e. to be 268 KB.
On hard disks (default filesystem block size 16 KB)
4,108 disk blocks are available, to allow
.Xr boot 8
to be over 64 MB in size!
(Only direct blocks are required for
.Xr boot 8 s
of up to 192 KB.)
.It Er ERR M
Bad magic.
The ELF
.Dq magic number
\e7fELF in
.Xr boot 8 's
header was not found.
This indicates that the first block of
.Xr boot 8
was not read correctly.
This could be due to disk corruption,
failing to run
.Xr installboot 8 ,
giving an invalid
.Xr boot 8
program as the
.Ar boot
argument to
.Xr installboot 8 ,
or
incorrect geometry translation.
.It Er ERR R
Read error.
The BIOS returned an error indication when
.Nm
attempted to read a disk sector.
This might be any media error, including bad sectors (common on floppy disks),
and invalid sectors (can occur with bad geometry translations).
.Pp
If this error occurs during an LBA boot (no
.Sq ;\&
after
.Dq Loading ) ,
then a CHS boot may succeed.
To do this, you should reboot, then hold down either Shift key
before
.Nm
starts.
You should see a
.Sq !\&
before
.Dq Loading
as confirmation that your
override was accepted.
.It Er ERR X
Can't boot.
Issued when trying to read sectors in CHS mode,
but the BIOS call
.Em get\ drive\ parameters
failed or gave a value of 0 for the number of sectors per track.
In either case, it is not possible for
.Nm
to calculate the (cylinder, head, sector) values required to
read any sectors.
.Sh NOTES
Using
.Nm
as the MBR,
as has been done in the past,
is not recommended, and is not supported.
Instead, create a single
.Xr fdisk 8
partition that spans the entire disk.
.Pp
Despite the support for
.Xr boot 8
over the 8 GB boundary,
good
.Xr disklabel 8
partitioning practices should still be followed.
.Sh FILES
.Bl -tag -width /usr/mdec/biosbootxx -compact
.It Pa /usr/mdec/mbr
Master Boot Record block
.It Pa /usr/mdec/biosboot
primary bootstrap
.It Pa /boot
secondary bootstrap
.It Pa /bsd
.Ox
kernel
.El
.Sh SEE ALSO
.Xr boot 8 ,
.Xr boot_i386 8 ,
.Xr disklabel 8 ,
.Xr fdisk 8 ,
.Xr installboot 8
.Sh HISTORY
.Nm
was originally written by Michael Shalayeff for
.Ox 2.1 .
However it was based on bootstrap code from older versions of this
operating system, other operating systems, other programs, and
other people's work.
.Pp
It was significantly revised in December 2003 by Tom Cosgrove,
in order to support LBA disk access (via the Phoenix Enhanced Disk
Drive Specification API).
At that time the internal table of disk blocks was removed, and
.Nm
modified to read filesystem block numbers from the inode.
.Sh BUGS
.Nm
should perform and verify a checksum across the entire loaded
.Xr boot 8
image,
rather than just checking the magic number in the first block.
.Pp
There is no BIOS error number reported nor is the location of the error
reported.
.Pp
You can pick your motherboard, and you can pick your BIOS,
but you can't pick your motherboard's BIOS.
|