2 The FreeBSD Documentation Project
4 $FreeBSD: doc/en_US.ISO8859-1/books/handbook/boot/chapter.sgml,v 1.56 2004/04/11 07:53:49 blackend Exp $
5 $DragonFly: doc/en/books/handbook/boot/chapter.sgml,v 1.3 2005/06/27 23:20:42 reed 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 <para>On x86 hardware the Basic Input/Output System (BIOS) is responsible
76 for loading the operating system. To do this, the BIOS looks on the
77 hard disk for the Master Boot Record (MBR), which must be located on a
78 specific place on the disk. The BIOS has enough knowledge to load and
79 run the MBR, and assumes that the MBR can then carry out the rest of the
80 tasks involved in loading the operating system.</para>
83 <primary>BIOS</primary>
84 <secondary>Basic Input/Output System</secondary>
87 <para>If you only have one operating system installed on your disks then
88 the standard MBR will suffice. This MBR searches for the first bootable
89 slice on the disk, and then runs the code on that slice to load the
90 remainder of the operating system.</para>
92 <para>If you have installed multiple operating systems on your disks then
93 you can install a different MBR, one that can display a list of
94 different operating systems, and allows you to choose the one to boot
95 from. &os; comes with one such MBR which can be installed, and other
96 operating system vendors also provide alternative MBRs.</para>
98 <para>The remainder of the &os; bootstrap system is divided into three
99 stages. The first stage is run by the MBR, which knows just enough to
100 get the computer into a specific state and run the second stage. The
101 second stage can do a little bit more, before running the third stage.
102 The third stage finishes the task of loading the operating system. The
103 work is split into these three stages because the PC standards put
104 limits on the size of the programs that can be run at stages one and
105 two. Chaining the tasks together allows &os; to provide a more
106 flexible loader.</para>
108 <indexterm><primary>kernel</primary></indexterm>
109 <indexterm><primary><command>init</command></primary></indexterm>
111 <para>The kernel is then started and it begins to probe for devices
112 and initialize them for use. Once the kernel boot
113 process is finished, the kernel passes control to the user process
114 &man.init.8;, which then makes sure the disks are in a usable state.
115 &man.init.8; then starts the user-level resource configuration which
116 mounts file systems, sets up network cards to communicate on the
117 network, and generally starts all the processes that usually
118 are run on a &os; system at startup.</para>
121 <sect1 id="boot-blocks">
122 <title>The MBR, and Boot Stages One, Two, and Three</title>
124 <sect2 id="boot-boot0">
125 <title>MBR, <filename>/boot/boot0</filename></title>
126 <indexterm><primary>Master Boot Record (MBR)</primary></indexterm>
128 <para>The &os; MBR is located in <filename>/boot/boot0</filename>.
129 This is a <emphasis>copy</emphasis> of the MBR, as the real MBR must
130 be placed on a special part of the disk, outside the &os;
133 <para><filename>boot0</filename> is very simple, since the
134 program in the <abbrev>MBR</abbrev> can only be 512 bytes in
135 size. If you have installed the &os; MBR and have installed
136 multiple operating systems on your hard disks then you will see a
137 display similar to this one at boot time:</para>
139 <example id="boot-boot0-example">
140 <title><filename>boot0</filename> Screenshot</title>
142 <!-- todo: reed: what should be here? -->
152 <para>Other operating systems, in particular &windows; 95, have been known
153 to overwrite an existing MBR with their own. If this happens to you,
154 or you want to replace your existing MBR with the &os; MBR then use
155 the following command:</para>
157 <screen>&prompt.root; <userinput>fdisk -B -b /boot/boot0 <replaceable>device</replaceable></userinput></screen>
159 <para>Where <replaceable>device</replaceable> is the device that you
160 boot from, such as <devicename>ad0</devicename> for the first IDE
161 disk, <devicename>ad2</devicename> for the first IDE disk on a second
162 IDE controller, <devicename>da0</devicename> for the first SCSI disk,
165 <para>If you are a Linux user, however, and prefer that
166 <application>LILO</application> control the boot process, you can
167 edit the <filename>/etc/lilo.conf</filename> file for &os;.
168 If you have installed the
169 &os; boot manager, you can boot back into Linux and modify the
170 <application>LILO</application> configuration file
171 <filename>/etc/lilo.conf</filename> and add the following
174 <programlisting>other=/dev/hdXY
177 label=&os;</programlisting>
179 <para>which will permit the booting of &os; and Linux via
180 <application>LILO</application>. In our example, we use
181 <replaceable>XY</replaceable> to determine drive number and
182 partition. If you are using a <acronym>SCSI</acronym> drive, you
183 will want to change <replaceable>/dev/hdXY</replaceable> to read
184 something similar to <replaceable>/dev/sdXY</replaceable>, which
185 again uses the <replaceable>XY</replaceable> syntax. The
186 <option>loader=/boot/chain.b</option> can be omitted if you have
187 both operating systems on the same drive. You can now run
188 <command>/sbin/lilo -v</command> to commit your new changes to the
189 system, this should be verified with screen messages.</para>
192 <sect2 id="boot-boot1">
193 <title>Stage One, <filename>/boot/boot1</filename>, and Stage Two,
194 <filename>/boot/boot2</filename></title>
196 <para>Conceptually the first and second stages are part of the same
197 program, on the same area of the disk. Because of space constraints
198 they have been split into two, but you would always install them
201 <para>They are found on the boot sector of
202 the boot slice, which is where <link
203 linkend="boot-boot0">boot0</link>, or any other program on the
204 <abbrev>MBR</abbrev> expects to find the program to run to
205 continue the boot process. The files in the
206 <filename>/boot</filename> directory are copies of the real files,
207 which are stored outside of the &os; file system.</para>
209 <para><filename>boot1</filename> is very simple, since it too
210 can only be 512 bytes
211 in size, and knows just enough about the &os;
212 <firstterm>disklabel</firstterm>, which stores information
213 about the slice, to find and execute <filename>boot2</filename>.</para>
215 <para><filename>boot2</filename> is slightly more sophisticated, and understands
216 the &os; file system enough to find files on it, and can
217 provide a simple interface to choose the kernel or loader to
220 <para>Since the <link linkend="boot-loader">loader</link> is
221 much more sophisticated, and provides a nice easy-to-use
222 boot configuration, <filename>boot2</filename> usually runs
223 it, but previously it
224 was tasked to run the kernel directly.</para>
226 <example id="boot-boot2-example">
227 <title><filename>boot2</filename> Screenshot</title>
229 <screen>>> DragonFly/i386 BOOT
230 Default: 0:ad(0,a)/kernel
234 <para>If you ever need to replace the installed
235 <filename>boot1</filename> and <filename>boot2</filename> use
236 &man.disklabel.8;:</para>
238 <screen>&prompt.root; <userinput>disklabel -B <replaceable>diskslice</replaceable></userinput></screen>
240 <para>where <replaceable>diskslice</replaceable> is the disk and slice
241 you boot from, such as <devicename>ad0s1</devicename> for the first
242 slice on the first IDE disk.</para>
246 <sect2 id="boot-loader">
247 <title>Stage Three, <filename>/boot/loader</filename></title>
249 <indexterm><primary>boot-loader</primary></indexterm>
250 <para>The loader is the final stage of the three-stage
251 bootstrap, and is located on the file system, usually as
252 <filename>/boot/loader</filename>.</para>
254 <para>The loader is intended as a user-friendly method for
255 configuration, using an easy-to-use built-in command set,
256 backed up by a more powerful interpreter, with a more complex
259 <sect3 id="boot-loader-flow">
260 <title>Loader Program Flow</title>
262 <para>During initialization, the loader will probe for a
263 console and for disks, and figure out what disk it is
264 booting from. It will set variables accordingly, and an
265 interpreter is started where user commands can be passed from
266 a script or interactively.</para>
267 <indexterm><primary>loader</primary></indexterm>
268 <indexterm><primary>loader configuration</primary></indexterm>
270 <para>The loader will then read
271 <filename>/boot/loader.rc</filename>, which by default reads
272 in <filename>/boot/defaults/loader.conf</filename> which
273 sets reasonable defaults for variables and reads
274 <filename>/boot/loader.conf</filename> for local changes to
275 those variables. <filename>loader.rc</filename> then acts
276 on these variables, loading whichever modules and kernel are
279 <para>Finally, by default, the loader issues a 10 second wait
280 for key presses, and boots the kernel if it is not interrupted.
281 If interrupted, the user is presented with a prompt which
282 understands the easy-to-use command set, where the user may
283 adjust variables, unload all modules, load modules, and then
284 finally boot or reboot.</para>
288 <sect3 id="boot-loader-commands">
289 <title>Loader Built-In Commands</title>
291 <para>These are the most commonly used loader commands. For a
292 complete discussion of all available commands, please see
293 &man.loader.8;.</para>
297 <term>autoboot <replaceable>seconds</replaceable></term>
300 <para>Proceeds to boot the kernel if not interrupted
301 within the time span given, in seconds. It displays a
302 countdown, and the default time span is 10
309 <optional><replaceable>-options</replaceable></optional>
310 <optional><replaceable>kernelname</replaceable></optional></term>
313 <para>Immediately proceeds to boot the kernel, with the
314 given options, if any, and with the kernel name given,
320 <term>boot-conf</term>
323 <para>Goes through the same automatic configuration of
324 modules based on variables as what happens at boot.
325 This only makes sense if you use
326 <command>unload</command> first, and change some
327 variables, most commonly <envar>kernel</envar>.</para>
333 <optional><replaceable>topic</replaceable></optional></term>
336 <para>Shows help messages read from
337 <filename>/boot/loader.help</filename>. If the topic
338 given is <literal>index</literal>, then the list of
339 available topics is given.</para>
344 <term>include <replaceable>filename</replaceable>
348 <para>Processes the file with the given filename. The
349 file is read in, and interpreted line by line. An
350 error immediately stops the include command.</para>
354 <term>load <optional><option>-t</option>
355 <replaceable>type</replaceable></optional>
356 <replaceable>filename</replaceable></term>
359 <para>Loads the kernel, kernel module, or file of the
360 type given, with the filename given. Any arguments
361 after filename are passed to the file.</para>
365 <term>ls <optional><option>-l</option></optional>
366 <optional><replaceable>path</replaceable></optional></term>
369 <para>Displays a listing of files in the given path, or
370 the root directory, if the path is not specified. If
371 <option>-l</option> is specified, file sizes will be
376 <term>lsdev <optional><option>-v</option></optional></term>
379 <para>Lists all of the devices from which it may be
380 possible to load modules. If <option>-v</option> is
381 specified, more details are printed.</para>
386 <term>lsmod <optional><option>-v</option></optional></term>
389 <para>Displays loaded modules. If <option>-v</option> is
390 specified, more details are shown.</para>
395 <term>more <replaceable>filename</replaceable></term>
398 <para>Displays the files specified, with a pause at each
399 <varname>LINES</varname> displayed.</para>
407 <para>Immediately reboots the system.</para>
412 <term>set <replaceable>variable</replaceable></term>
414 <replaceable>variable</replaceable>=<replaceable>value</replaceable></term>
417 <para>Sets the loader's environment variables.</para>
425 <para>Removes all loaded modules.</para>
431 <sect3 id="boot-loader-examples">
432 <title>Loader Examples</title>
434 <para>Here are some practical examples of loader usage:</para>
437 <indexterm><primary>single-user mode</primary></indexterm>
439 <para>To simply boot your usual kernel, but in single-user
442 <screen><userinput>boot -s</userinput></screen>
446 <para>To unload your usual kernel and modules, and then
447 load just your old (or another) kernel:</para>
449 <primary><filename>kernel.old</filename></primary>
452 <screen><userinput>unload</userinput>
453 <userinput>load <replaceable>kernel.old</replaceable></userinput></screen>
455 <para>You can use <filename>kernel.GENERIC</filename> to
456 refer to the generic kernel that comes on the install
457 disk, or <filename>kernel.old</filename> to refer to
458 your previously installed kernel (when you have upgraded
459 or configured your own kernel, for example).</para>
462 <para>Use the following to load your usual modules with
463 another kernel:</para>
465 <screen><userinput>unload</userinput>
466 <userinput>set kernel="<replaceable>kernel.old</replaceable>"</userinput>
467 <userinput>boot-conf</userinput></screen></note>
471 <para>To load a kernel configuration script (an automated
472 script which does the things you would normally do in the
473 kernel boot-time configurator):</para>
475 <screen><userinput>load -t userconfig_script <replaceable>/boot/kernel.conf</replaceable></userinput></screen>
482 <sect1 id="boot-kernel">
483 <title>Kernel Interaction During Boot</title>
485 <primary>kernel</primary>
486 <secondary>boot interaction</secondary>
489 <para>Once the kernel is loaded by either <link
490 linkend="boot-loader">loader</link> (as usual) or <link
491 linkend="boot-boot1">boot2</link> (bypassing the loader), it
492 examines its boot flags, if any, and adjusts its behavior as
495 <sect2 id="boot-kernel-bootflags">
497 <primary>kernel</primary>
498 <secondary>bootflags</secondary>
500 <title>Kernel Boot Flags</title>
502 <para>Here are the more common boot flags:</para>
504 <variablelist id="boot-kernel-bootflags-list">
506 <term><option>-a</option></term>
509 <para>during kernel initialization, ask for the device
510 to mount as the root file system.</para>
515 <term><option>-C</option></term>
518 <para>boot from CDROM.</para>
523 <term><option>-c</option></term>
526 <para>run UserConfig, the boot-time kernel
532 <term><option>-s</option></term>
535 <para>boot into single-user mode</para>
540 <term><option>-v</option></term>
543 <para>be more verbose during kernel startup</para>
549 <para>There are other boot flags; read &man.boot.8; for more
550 information on them.</para></note>
555 <sect1 id="boot-init">
557 <primary><command>init</command></primary>
559 <title>Init: Process Control Initialization</title>
561 <para>Once the kernel has finished booting, it passes control to
562 the user process &man.init.8;, which is located at
563 <filename>/sbin/init</filename>, or the program path specified
564 in the <envar>init_path</envar> variable in
565 <command>loader</command>.</para>
567 <sect2 id="boot-autoreboot">
568 <title>Automatic Reboot Sequence</title>
570 <para>The automatic reboot sequence makes sure that the
571 file systems available on the system are consistent. If they
572 are not, and &man.fsck.8; cannot fix the
573 inconsistencies, &man.init.8; drops the system
574 into <link linkend="boot-singleuser">single-user mode</link>
575 for the system administrator to take care of the problems
579 <sect2 id="boot-singleuser">
580 <title>Single-User Mode</title>
581 <indexterm><primary>single-user mode</primary></indexterm>
582 <indexterm><primary>console</primary></indexterm>
584 <para>This mode can be reached through the <link
585 linkend="boot-autoreboot">automatic reboot
586 sequence</link>, or by the user booting with the
587 <option>-s</option> option or setting the
588 <envar>boot_single</envar> variable in
589 <command>loader</command>.</para>
591 <para>It can also be reached by calling
592 &man.shutdown.8; without the reboot
593 (<option>-r</option>) or halt (<option>-h</option>) options,
594 from <link linkend="boot-multiuser">multi-user
597 <para>If the system <literal>console</literal> is set
598 to <literal>insecure</literal> in <filename>/etc/ttys</filename>,
599 then the system prompts for the <username>root</username> password
600 before initiating single-user mode.</para>
602 <example id="boot-insecure-console">
603 <title>An Insecure Console in <filename>/etc/ttys</filename></title>
605 <programlisting># name getty type status comments
607 # If console is marked "insecure", then init will ask for the root password
608 # when going to single-user mode.
609 console none unknown off insecure</programlisting>
613 <para>An <literal>insecure</literal> console means that you
614 consider your physical security to the console to be
615 insecure, and want to make sure only someone who knows the
616 <username>root</username> password may use single-user mode, and it
617 does not mean that you want to run your console insecurely. Thus,
618 if you want security, choose <literal>insecure</literal>,
619 not <literal>secure</literal>.</para>
623 <sect2 id="boot-multiuser">
624 <title>Multi-User Mode</title>
625 <indexterm><primary>multi-user mode</primary></indexterm>
627 <para>If &man.init.8; finds your file systems to be
628 in order, or once the user has finished in <link
629 linkend="boot-singleuser">single-user mode</link>, the
630 system enters multi-user mode, in which it starts the
631 resource configuration of the system.</para>
634 <indexterm><primary>rc files</primary></indexterm>
635 <title>Resource Configuration (rc)</title>
637 <para>The resource configuration system reads in
638 configuration defaults from
639 <filename>/etc/defaults/rc.conf</filename>, and
640 system-specific details from
641 <filename>/etc/rc.conf</filename>, and then proceeds to
642 mount the system file systems mentioned in
643 <filename>/etc/fstab</filename>, start up networking
644 services, start up miscellaneous system daemons, and
645 finally runs the startup scripts of locally installed
648 <para>The &man.rc.8; manual page is a good reference to the resource
649 configuration system, as is examining the scripts
655 <sect1 id="boot-shutdown">
656 <title>Shutdown Sequence</title>
658 <primary><command>shutdown</command></primary>
661 <para>Upon controlled shutdown, via &man.shutdown.8;,
662 &man.init.8; will attempt to run the script
663 <filename>/etc/rc.shutdown</filename>, and then proceed to send
664 all processes the <literal>TERM</literal> signal, and subsequently
665 the <literal>KILL</literal> signal to any that do not terminate
668 <para>To power down a &os; machine on architectures and systems
669 that support power management, simply use the command
670 <command>shutdown -p now</command> to turn the power off
671 immediately. To just reboot a &os; system, just use
672 <command>shutdown -r now</command>. You need to be
673 <username>root</username> or a member of
674 <groupname>operator</groupname> group to run &man.shutdown.8;.
675 The &man.halt.8; and &man.reboot.8; commands can also be used,
676 please refer to their manual pages and to &man.shutdown.8;'s one
677 for more informations.</para>
680 <para>Power management requires &man.acpi.4; support in the kernel
681 or loaded as a module, or &man.apm.4; support.</para>
690 sgml-declaration: "../chapter.decl"
693 sgml-always-quote-attributes: t
694 sgml-parent-document: ("../book.sgml" "part" "chapter")