2 The FreeBSD Documentation Project
4 $FreeBSD: /usr/local/www/cvsroot/FreeBSD/doc/en_US.ISO8859-1/books/handbook/boot/chapter.sgml,v 1.64 2006/02/17 17:17:17 marck Exp $
5 $DragonFly: doc/en/books/handbook/boot/chapter.sgml,v 1.4 2006/03/09 04:42:28 justin Exp $
9 <title>The &os; Booting Process</title>
11 <sect1 id="boot-synopsis">
12 <title>Synopsis</title>
13 <indexterm><primary>booting</primary></indexterm>
14 <indexterm><primary>bootstrap</primary></indexterm>
16 <para>The process of starting a computer and loading the operating system
17 is referred to as <quote>the bootstrap process</quote>, or simply
18 <quote>booting</quote>. &os;'s boot process provides a great deal of
19 flexibility in customizing what happens when you start the system,
20 allowing you to select from different operating systems installed on the
21 same computer, or even different versions of the same operating system
22 or installed kernel.</para>
24 <para>This chapter details the configuration options you can set and how
25 to customize the &os; boot process. This includes everything that
26 happens until the &os; kernel has started, probed for devices, and
27 started &man.init.8;. If you are not quite sure when this happens, it
28 occurs when the text color changes from bright white to grey.</para>
30 <para>After reading this chapter, you will know:</para>
34 <para>What the components of the &os; bootstrap system are, and how
39 <para>The options you can give to the components in the &os;
40 bootstrap to control the boot process.</para>
44 <para>The basics of &man.device.hints.5;.</para>
49 <title>x86 Only</title>
51 <para>This chapter only describes the boot process for &os; running
52 on x86 systems.</para>
56 <sect1 id="boot-introduction">
57 <title>The Booting Problem</title>
59 <para>Turning on a computer and starting the operating system poses an
60 interesting dilemma. By definition, the computer does not know how to
61 do anything until the operating system is started. This includes
62 running programs from the disk. So if the computer can not run a
63 program from the disk without the operating system, and the operating
64 system programs are on the disk, how is the operating system
67 <para>This problem parallels one in the book <citetitle>The Adventures of
68 Baron Munchausen</citetitle>. A character had fallen part way down a
69 manhole, and pulled himself out by grabbing his bootstraps, and
70 lifting. In the early days of computing the term
71 <firstterm>bootstrap</firstterm> was applied to the mechanism used to
72 load the operating system, which has become shortened to
73 <quote>booting</quote>.</para>
75 <indexterm><primary>BIOS</primary></indexterm>
77 <indexterm><primary>Basic Input/Output
78 System</primary><see>BIOS</see></indexterm>
80 <para>On x86 hardware the Basic Input/Output System (BIOS) is responsible
81 for loading the operating system. To do this, the BIOS looks on the
82 hard disk for the Master Boot Record (MBR), which must be located on a
83 specific place on the disk. The BIOS has enough knowledge to load and
84 run the MBR, and assumes that the MBR can then carry out the rest of the
85 tasks involved in loading the operating system
86 possibly with the help of the BIOS.</para>
88 <indexterm><primary>Master Boot Record (MBR)</primary></indexterm>
90 <indexterm><primary>Boot Manager</primary></indexterm>
92 <indexterm><primary>Boot Loader</primary></indexterm>
94 <para>The code within the MBR is usually referred to as a <emphasis>boot
95 manager</emphasis>, especially when it interacts with the user. In this
96 case the boot manager usually has more code in the first
97 <emphasis>track</emphasis> of the disk or within some OS's file system.
98 (A boot manager is sometimes also called a <emphasis>boot
99 loader</emphasis>, but FreeBSD uses that term for a later stage of
100 booting.) Popular boot managers include <application>boot0</application>
101 (a.k.a. <application>Boot Easy</application>, the standard &os; boot
102 manager), <application>Grub</application>,
103 <application>GAG</application>, and <application>LILO</application>.
104 (Only <application>boot0</application> fits within the MBR.)</para>
106 <para>If you have only one operating system installed on your disks then
107 a standard PC MBR will suffice. This MBR searches for the first bootable
108 (a.k.a. active) slice on the disk, and then runs the code on that slice to
109 load the remainder of the operating system. The MBR installed by
110 &man.fdisk.8;, by default, is such an MBR. It is based on
111 <filename>/boot/mbr</filename>.</para>
113 <para>If you have installed multiple operating systems on your disks then
114 you can install a different boot manager, one that can display a list of
115 different operating systems, and allows you to choose the one to boot
116 from. Two of these are discussed in the next subsection.</para>
118 <para>The remainder of the &os; bootstrap system is divided into three
119 stages. The first stage is run by the MBR, which knows just enough to
120 get the computer into a specific state and run the second stage. The
121 second stage can do a little bit more, before running the third stage.
122 The third stage finishes the task of loading the operating system. The
123 work is split into these three stages because the PC standards put
124 limits on the size of the programs that can be run at stages one and
125 two. Chaining the tasks together allows &os; to provide a more
126 flexible loader.</para>
128 <indexterm><primary>kernel</primary></indexterm>
129 <indexterm><primary><command>init</command></primary></indexterm>
131 <para>The kernel is then started and it begins to probe for devices
132 and initialize them for use. Once the kernel boot
133 process is finished, the kernel passes control to the user process
134 &man.init.8;, which then makes sure the disks are in a usable state.
135 &man.init.8; then starts the user-level resource configuration which
136 mounts file systems, sets up network cards to communicate on the
137 network, and generally starts all the processes that usually
138 are run on a &os; system at startup.</para>
141 <sect1 id="boot-blocks">
142 <title>The Boot Manager and Boot Stages</title>
144 <indexterm><primary>Boot Manager</primary></indexterm>
146 <sect2 id="boot-boot0">
147 <title>The Boot Manager</title>
148 <indexterm><primary>Master Boot Record (MBR)</primary></indexterm>
150 <para>The code in the MBR or boot manager is sometimes referred to as
151 <emphasis>stage zero</emphasis> of the boot process. This subsection
152 discusses two of the boot managers previously mentioned:
153 <application>boot0</application> and <application>LILO</application>.</para>
155 <formalpara><title>The <application>boot0</application> Boot Manager:</title>
156 <para>The MBR installed by FreeBSD's installer or &man.boot0cfg.8;, by
157 default, is based on <filename>/boot/boot0</filename>.
158 (The <application>boot0</application> program is very simple, since the
159 program in the <abbrev>MBR</abbrev> can only be 446 bytes long because of the slice
160 table and <literal>0x55AA</literal> identifier at the end of the MBR.)
161 If you have installed <application>boot0</application> and
162 multiple operating systems on your hard disks, then you will see a
163 display similar to this one at boot time:</para></formalpara>
165 <example id="boot-boot0-example">
166 <title><filename>boot0</filename> Screenshot</title>
168 <!-- todo: reed: what should be here? -->
178 <para>Other operating systems, in particular &windows;, have been known
179 to overwrite an existing MBR with their own. If this happens to you,
180 or you want to replace your existing MBR with the &os; MBR then use
181 the following command:</para>
183 <screen>&prompt.root; <userinput>fdisk -B -b /boot/boot0 <replaceable>device</replaceable></userinput></screen>
185 <para>where <replaceable>device</replaceable> is the device that you
186 boot from, such as <devicename>ad0</devicename> for the first IDE
187 disk, <devicename>ad2</devicename> for the first IDE disk on a second
188 IDE controller, <devicename>da0</devicename> for the first SCSI disk,
189 and so on. Or, if you want a custom configuration of the MBR,
190 use &man.boot0cfg.8;.</para>
192 <formalpara><title>The LILO Boot Manager:</title>
194 <para>To install this boot manager so it will also boot &os;, first
195 start Linux and add the following to your existing
196 <filename>/etc/lilo.conf</filename> configuration file:</para></formalpara>
198 <programlisting>other=/dev/hdXY
201 label=&os;</programlisting>
203 <para>In the above, specify &os;'s primary partition and drive using
204 Linux specifiers, replacing <replaceable>X</replaceable> with the Linux
205 drive letter and <replaceable>Y</replaceable> with the Linux primary
206 partition number. If you are using a <acronym>SCSI</acronym> drive, you
207 will need to change <replaceable>/dev/hd</replaceable> to read something
208 similar to <replaceable>/dev/sd</replaceable>. The
209 <option>loader=/boot/chain.b</option> line can be omitted if you have
210 both operating systems on the same drive. Now run
211 <command>/sbin/lilo -v</command> to commit your new changes to the
212 system; this should be verified by checking its screen messages.</para>
215 <sect2 id="boot-boot1">
216 <title>Stage One, <filename>/boot/boot1</filename>, and Stage Two,
217 <filename>/boot/boot2</filename></title>
219 <para>Conceptually the first and second stages are part of the same
220 program, on the same area of the disk. Because of space constraints
221 they have been split into two, but you would always install them
222 together. They are copied from the combined file
223 <filename>/boot/boot</filename> by the installer or
224 <application>disklabel</application> (see below).</para>
226 <para>They are located outside file systems, in the first track of
227 the boot slice, starting with the first sector. This is where <link
228 linkend="boot-boot0">boot0</link>, or any other boot manager,
229 expects to find a program to run which will
230 continue the boot process. The number of sectors used is easily
231 determined from the size of <filename>/boot/boot</filename>.</para>
233 <para>They are found on the boot sector of
234 the boot slice, which is where <link
235 linkend="boot-boot0">boot0</link>, or any other program on the
236 <abbrev>MBR</abbrev> expects to find the program to run to
237 continue the boot process. The files in the
238 <filename>/boot</filename> directory are copies of the real files,
239 which are stored outside of the &os; file system.</para>
241 <para><filename>boot1</filename> is very simple, since it
242 can only be 512 bytes
243 in size, and knows just enough about the &os;
244 <firstterm>disklabel</firstterm>, which stores information
245 about the slice, to find and execute <filename>boot2</filename>.</para>
247 <para><filename>boot2</filename> is slightly more sophisticated, and understands
248 the &os; file system enough to find files on it, and can
249 provide a simple interface to choose the kernel or loader to
252 <para>Since the <link linkend="boot-loader">loader</link> is
253 much more sophisticated, and provides a nice easy-to-use
254 boot configuration, <filename>boot2</filename> usually runs
255 it, but previously it
256 was tasked to run the kernel directly.</para>
258 <example id="boot-boot2-example">
259 <title><filename>boot2</filename> Screenshot</title>
261 <screen>>> DragonFly/i386 BOOT
262 Default: 0:ad(0,a)/boot/loader
266 <para>If you ever need to replace the installed
267 <filename>boot1</filename> and <filename>boot2</filename> use
268 &man.disklabel.8;:</para>
270 <screen>&prompt.root; <userinput>disklabel -B <replaceable>diskslice</replaceable></userinput></screen>
272 <para>where <replaceable>diskslice</replaceable> is the disk and slice
273 you boot from, such as <devicename>ad0s1</devicename> for the first
274 slice on the first IDE disk.</para>
278 <sect2 id="boot-loader">
279 <title>Stage Three, <filename>/boot/loader</filename></title>
281 <indexterm><primary>boot-loader</primary></indexterm>
282 <para>The loader is the final stage of the three-stage
283 bootstrap, and is located on the file system, usually as
284 <filename>/boot/loader</filename>.</para>
286 <para>The loader is intended as a user-friendly method for
287 configuration, using an easy-to-use built-in command set,
288 backed up by a more powerful interpreter, with a more complex
291 <sect3 id="boot-loader-flow">
292 <title>Loader Program Flow</title>
294 <para>During initialization, the loader will probe for a
295 console and for disks, and figure out what disk it is
296 booting from. It will set variables accordingly, and an
297 interpreter is started where user commands can be passed from
298 a script or interactively.</para>
299 <indexterm><primary>loader</primary></indexterm>
300 <indexterm><primary>loader configuration</primary></indexterm>
302 <para>The loader will then read
303 <filename>/boot/loader.rc</filename>, which by default reads
304 in <filename>/boot/defaults/loader.conf</filename> which
305 sets reasonable defaults for variables and reads
306 <filename>/boot/loader.conf</filename> for local changes to
307 those variables. <filename>loader.rc</filename> then acts
308 on these variables, loading whichever modules and kernel are
311 <para>Finally, by default, the loader issues a 10 second wait
312 for key presses, and boots the kernel if it is not interrupted.
313 If interrupted, the user is presented with a prompt which
314 understands the easy-to-use command set, where the user may
315 adjust variables, unload all modules, load modules, and then
316 finally boot or reboot.</para>
320 <sect3 id="boot-loader-commands">
321 <title>Loader Built-In Commands</title>
323 <para>These are the most commonly used loader commands. For a
324 complete discussion of all available commands, please see
325 &man.loader.8;.</para>
329 <term>autoboot <replaceable>seconds</replaceable></term>
332 <para>Proceeds to boot the kernel if not interrupted
333 within the time span given, in seconds. It displays a
334 countdown, and the default time span is 10
341 <optional><replaceable>-options</replaceable></optional>
342 <optional><replaceable>kernelname</replaceable></optional></term>
345 <para>Immediately proceeds to boot the kernel, with the
346 given options, if any, and with the kernel name given,
352 <term>boot-conf</term>
355 <para>Goes through the same automatic configuration of
356 modules based on variables as what happens at boot.
357 This only makes sense if you use
358 <command>unload</command> first, and change some
359 variables, most commonly <envar>kernel</envar>.</para>
365 <optional><replaceable>topic</replaceable></optional></term>
368 <para>Shows help messages read from
369 <filename>/boot/loader.help</filename>. If the topic
370 given is <literal>index</literal>, then the list of
371 available topics is given.</para>
376 <term>include <replaceable>filename</replaceable>
380 <para>Processes the file with the given filename. The
381 file is read in, and interpreted line by line. An
382 error immediately stops the include command.</para>
386 <term>load <optional><option>-t</option>
387 <replaceable>type</replaceable></optional>
388 <replaceable>filename</replaceable></term>
391 <para>Loads the kernel, kernel module, or file of the
392 type given, with the filename given. Any arguments
393 after filename are passed to the file.</para>
397 <term>ls <optional><option>-l</option></optional>
398 <optional><replaceable>path</replaceable></optional></term>
401 <para>Displays a listing of files in the given path, or
402 the root directory, if the path is not specified. If
403 <option>-l</option> is specified, file sizes will be
408 <term>lsdev <optional><option>-v</option></optional></term>
411 <para>Lists all of the devices from which it may be
412 possible to load modules. If <option>-v</option> is
413 specified, more details are printed.</para>
418 <term>lsmod <optional><option>-v</option></optional></term>
421 <para>Displays loaded modules. If <option>-v</option> is
422 specified, more details are shown.</para>
427 <term>more <replaceable>filename</replaceable></term>
430 <para>Displays the files specified, with a pause at each
431 <varname>LINES</varname> displayed.</para>
439 <para>Immediately reboots the system.</para>
444 <term>set <replaceable>variable</replaceable></term>
446 <replaceable>variable</replaceable>=<replaceable>value</replaceable></term>
449 <para>Sets the loader's environment variables.</para>
457 <para>Removes all loaded modules.</para>
463 <sect3 id="boot-loader-examples">
464 <title>Loader Examples</title>
466 <para>Here are some practical examples of loader usage:</para>
469 <indexterm><primary>single-user mode</primary></indexterm>
471 <para>To simply boot your usual kernel, but in single-user
474 <screen><userinput>boot -s</userinput></screen>
478 <para>To unload your usual kernel and modules, and then
479 load just your old (or another) kernel:</para>
481 <primary><filename>kernel.old</filename></primary>
484 <screen><userinput>unload</userinput>
485 <userinput>load <replaceable>kernel.old</replaceable></userinput></screen>
487 <para>You can use <filename>kernel.GENERIC</filename> to
488 refer to the generic kernel that comes on the install
489 disk, or <filename>kernel.old</filename> to refer to
490 your previously installed kernel (when you have upgraded
491 or configured your own kernel, for example).</para>
494 <para>Use the following to load your usual modules with
495 another kernel:</para>
497 <screen><userinput>unload</userinput>
498 <userinput>set kernel="<replaceable>kernel.old</replaceable>"</userinput>
499 <userinput>boot-conf</userinput></screen></note>
503 <para>To load a kernel configuration script (an automated
504 script which does the things you would normally do in the
505 kernel boot-time configurator):</para>
507 <screen><userinput>load -t userconfig_script <replaceable>/boot/kernel.conf</replaceable></userinput></screen>
514 <sect1 id="boot-kernel">
515 <title>Kernel Interaction During Boot</title>
517 <primary>kernel</primary>
518 <secondary>boot interaction</secondary>
521 <para>Once the kernel is loaded by either <link
522 linkend="boot-loader">loader</link> (as usual) or <link
523 linkend="boot-boot1">boot2</link> (bypassing the loader), it
524 examines its boot flags, if any, and adjusts its behavior as
527 <sect2 id="boot-kernel-bootflags">
529 <primary>kernel</primary>
530 <secondary>bootflags</secondary>
532 <title>Kernel Boot Flags</title>
534 <para>Here are the more common boot flags:</para>
536 <variablelist id="boot-kernel-bootflags-list">
538 <term><option>-a</option></term>
541 <para>during kernel initialization, ask for the device
542 to mount as the root file system.</para>
547 <term><option>-C</option></term>
550 <para>boot from CDROM.</para>
555 <term><option>-c</option></term>
558 <para>run UserConfig, the boot-time kernel
564 <term><option>-s</option></term>
567 <para>boot into single-user mode</para>
572 <term><option>-v</option></term>
575 <para>be more verbose during kernel startup</para>
581 <para>There are other boot flags; read &man.boot.8; for more
582 information on them.</para></note>
587 <sect1 id="boot-init">
589 <primary><command>init</command></primary>
591 <title>Init: Process Control Initialization</title>
593 <para>Once the kernel has finished booting, it passes control to
594 the user process &man.init.8;, which is located at
595 <filename>/sbin/init</filename>, or the program path specified
596 in the <envar>init_path</envar> variable in
597 <command>loader</command>.</para>
599 <sect2 id="boot-autoreboot">
600 <title>Automatic Reboot Sequence</title>
602 <para>The automatic reboot sequence makes sure that the
603 file systems available on the system are consistent. If they
604 are not, and &man.fsck.8; cannot fix the
605 inconsistencies, &man.init.8; drops the system
606 into <link linkend="boot-singleuser">single-user mode</link>
607 for the system administrator to take care of the problems
611 <sect2 id="boot-singleuser">
612 <title>Single-User Mode</title>
613 <indexterm><primary>single-user mode</primary></indexterm>
614 <indexterm><primary>console</primary></indexterm>
616 <para>This mode can be reached through the <link
617 linkend="boot-autoreboot">automatic reboot
618 sequence</link>, or by the user booting with the
619 <option>-s</option> option or setting the
620 <envar>boot_single</envar> variable in
621 <command>loader</command>.</para>
623 <para>It can also be reached by calling
624 &man.shutdown.8; without the reboot
625 (<option>-r</option>) or halt (<option>-h</option>) options,
626 from <link linkend="boot-multiuser">multi-user
629 <para>If the system <literal>console</literal> is set
630 to <literal>insecure</literal> in <filename>/etc/ttys</filename>,
631 then the system prompts for the <username>root</username> password
632 before initiating single-user mode.</para>
634 <example id="boot-insecure-console">
635 <title>An Insecure Console in <filename>/etc/ttys</filename></title>
637 <programlisting># name getty type status comments
639 # If console is marked "insecure", then init will ask for the root password
640 # when going to single-user mode.
641 console none unknown off insecure</programlisting>
645 <para>An <literal>insecure</literal> console means that you
646 consider your physical security to the console to be
647 insecure, and want to make sure only someone who knows the
648 <username>root</username> password may use single-user mode, and it
649 does not mean that you want to run your console insecurely. Thus,
650 if you want security, choose <literal>insecure</literal>,
651 not <literal>secure</literal>.</para>
655 <sect2 id="boot-multiuser">
656 <title>Multi-User Mode</title>
657 <indexterm><primary>multi-user mode</primary></indexterm>
659 <para>If &man.init.8; finds your file systems to be
660 in order, or once the user has finished in <link
661 linkend="boot-singleuser">single-user mode</link>, the
662 system enters multi-user mode, in which it starts the
663 resource configuration of the system.</para>
666 <indexterm><primary>rc files</primary></indexterm>
667 <title>Resource Configuration (rc)</title>
669 <para>The resource configuration system reads in
670 configuration defaults from
671 <filename>/etc/defaults/rc.conf</filename>, and
672 system-specific details from
673 <filename>/etc/rc.conf</filename>, and then proceeds to
674 mount the system file systems mentioned in
675 <filename>/etc/fstab</filename>, start up networking
676 services, start up miscellaneous system daemons, and
677 finally runs the startup scripts of locally installed
680 <para>The &man.rc.8; manual page is a good reference to the resource
681 configuration system, as is examining the scripts
687 <sect1 id="boot-shutdown">
688 <title>Shutdown Sequence</title>
690 <primary><command>shutdown</command></primary>
693 <para>Upon controlled shutdown, via &man.shutdown.8;,
694 &man.init.8; will attempt to run the script
695 <filename>/etc/rc.shutdown</filename>, and then proceed to send
696 all processes the <literal>TERM</literal> signal, and subsequently
697 the <literal>KILL</literal> signal to any that do not terminate
700 <para>To power down a &os; machine on architectures and systems
701 that support power management, simply use the command
702 <command>shutdown -p now</command> to turn the power off
703 immediately. To just reboot a &os; system, just use
704 <command>shutdown -r now</command>. You need to be
705 <username>root</username> or a member of
706 <groupname>operator</groupname> group to run &man.shutdown.8;.
707 The &man.halt.8; and &man.reboot.8; commands can also be used,
708 please refer to their manual pages and to &man.shutdown.8;'s one
709 for more information.</para>
712 <para>Power management requires &man.acpi.4; support in the kernel
713 or loaded as a module, or &man.apm.4; support.</para>
722 sgml-declaration: "../chapter.decl"
725 sgml-always-quote-attributes: t
726 sgml-parent-document: ("../book.sgml" "part" "chapter")