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.5 2006/09/17 18:45:52 victor 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>
45 <title>x86 Only</title>
47 <para>This chapter only describes the boot process for &os; running
48 on x86 systems.</para>
52 <sect1 id="boot-introduction">
53 <title>The Booting Problem</title>
55 <para>Turning on a computer and starting the operating system poses an
56 interesting dilemma. By definition, the computer does not know how to
57 do anything until the operating system is started. This includes
58 running programs from the disk. So if the computer can not run a
59 program from the disk without the operating system, and the operating
60 system programs are on the disk, how is the operating system
63 <para>This problem parallels one in the book <citetitle>The Adventures of
64 Baron Munchausen</citetitle>. A character had fallen part way down a
65 manhole, and pulled himself out by grabbing his bootstraps, and
66 lifting. In the early days of computing the term
67 <firstterm>bootstrap</firstterm> was applied to the mechanism used to
68 load the operating system, which has become shortened to
69 <quote>booting</quote>.</para>
71 <indexterm><primary>BIOS</primary></indexterm>
73 <indexterm><primary>Basic Input/Output
74 System</primary><see>BIOS</see></indexterm>
76 <para>On x86 hardware the Basic Input/Output System (BIOS) is responsible
77 for loading the operating system. To do this, the BIOS looks on the
78 hard disk for the Master Boot Record (MBR), which must be located on a
79 specific place on the disk. The BIOS has enough knowledge to load and
80 run the MBR, and assumes that the MBR can then carry out the rest of the
81 tasks involved in loading the operating system
82 possibly with the help of the BIOS.</para>
84 <indexterm><primary>Master Boot Record (MBR)</primary></indexterm>
86 <indexterm><primary>Boot Manager</primary></indexterm>
88 <indexterm><primary>Boot Loader</primary></indexterm>
90 <para>The code within the MBR is usually referred to as a <emphasis>boot
91 manager</emphasis>, especially when it interacts with the user. In this
92 case the boot manager usually has more code in the first
93 <emphasis>track</emphasis> of the disk or within some OS's file system.
94 (A boot manager is sometimes also called a <emphasis>boot
95 loader</emphasis>, but &os; uses that term for a later stage of
96 booting.) Popular boot managers include <application>boot0</application>
97 (a.k.a. <application>Boot Easy</application>, the standard &os; boot
98 manager), <application>Grub</application>,
99 <application>GAG</application>, and <application>LILO</application>.
100 (Only <application>boot0</application> fits within the MBR.)</para>
102 <para>If you have only one operating system installed on your disks then
103 a standard PC MBR will suffice. This MBR searches for the first bootable
104 (a.k.a. active) slice on the disk, and then runs the code on that slice to
105 load the remainder of the operating system. The MBR installed by
106 &man.fdisk.8;, by default, is such an MBR. It is based on
107 <filename>/boot/mbr</filename>.</para>
109 <para>If you have installed multiple operating systems on your disks then
110 you can install a different boot manager, one that can display a list of
111 different operating systems, and allows you to choose the one to boot
112 from. Two of these are discussed in the next subsection.</para>
114 <para>The remainder of the &os; bootstrap system is divided into three
115 stages. The first stage is run by the MBR, which knows just enough to
116 get the computer into a specific state and run the second stage. The
117 second stage can do a little bit more, before running the third stage.
118 The third stage finishes the task of loading the operating system. The
119 work is split into these three stages because the PC standards put
120 limits on the size of the programs that can be run at stages one and
121 two. Chaining the tasks together allows &os; to provide a more
122 flexible loader.</para>
124 <indexterm><primary>kernel</primary></indexterm>
125 <indexterm><primary><command>init</command></primary></indexterm>
127 <para>The kernel is then started and it begins to probe for devices
128 and initialize them for use. Once the kernel boot
129 process is finished, the kernel passes control to the user process
130 &man.init.8;, which then makes sure the disks are in a usable state.
131 &man.init.8; then starts the user-level resource configuration which
132 mounts file systems, sets up network cards to communicate on the
133 network, and generally starts all the processes that usually
134 are run on a &os; system at startup.</para>
137 <sect1 id="boot-blocks">
138 <title>The Boot Manager and Boot Stages</title>
140 <indexterm><primary>Boot Manager</primary></indexterm>
142 <sect2 id="boot-boot0">
143 <title>The Boot Manager</title>
144 <indexterm><primary>Master Boot Record (MBR)</primary></indexterm>
146 <para>The code in the MBR or boot manager is sometimes referred to as
147 <emphasis>stage zero</emphasis> of the boot process. This subsection
148 discusses two of the boot managers previously mentioned:
149 <application>boot0</application> and <application>LILO</application>.</para>
151 <formalpara><title>The <application>boot0</application> Boot Manager:</title>
152 <para>The MBR installed by &os;'s installer or &man.boot0cfg.8;, by
153 default, is based on <filename>/boot/boot0</filename>.
154 (The <application>boot0</application> program is very simple, since the
155 program in the <abbrev>MBR</abbrev> can only be 446 bytes long because of the slice
156 table and <literal>0x55AA</literal> identifier at the end of the MBR.)
157 If you have installed <application>boot0</application> and
158 multiple operating systems on your hard disks, then you will see a
159 display similar to this one at boot time:</para></formalpara>
161 <example id="boot-boot0-example">
162 <title><filename>boot0</filename> Screenshot</title>
173 <para>Other operating systems, in particular &windows;, have been known
174 to overwrite an existing MBR with their own. If this happens to you,
175 or you want to replace your existing MBR with the &os; MBR then use
176 the following command:</para>
178 <screen>&prompt.root; <userinput>fdisk -B -b /boot/boot0 <replaceable>device</replaceable></userinput></screen>
180 <para>where <replaceable>device</replaceable> is the device that you
181 boot from, such as <devicename>ad0</devicename> for the first IDE
182 disk, <devicename>ad2</devicename> for the first IDE disk on a second
183 IDE controller, <devicename>da0</devicename> for the first SCSI disk,
184 and so on. Or, if you want a custom configuration of the MBR,
185 use &man.boot0cfg.8;.</para>
187 <formalpara><title>The LILO Boot Manager:</title>
189 <para>To install this boot manager so it will also boot &os;, first
190 start Linux and add the following to your existing
191 <filename>/etc/lilo.conf</filename> configuration file:</para></formalpara>
193 <programlisting>other=/dev/hdXY
196 label=&os;</programlisting>
198 <para>In the above, specify &os;'s primary partition and drive using
199 Linux specifiers, replacing <replaceable>X</replaceable> with the Linux
200 drive letter and <replaceable>Y</replaceable> with the Linux primary
201 partition number. If you are using a <acronym>SCSI</acronym> drive, you
202 will need to change <replaceable>/dev/hd</replaceable> to read something
203 similar to <replaceable>/dev/sd</replaceable>. The
204 <option>loader=/boot/chain.b</option> line can be omitted if you have
205 both operating systems on the same drive. Now run
206 <command>/sbin/lilo -v</command> to commit your new changes to the
207 system; this should be verified by checking its screen messages.</para>
210 <sect2 id="boot-boot1">
211 <title>Stage One, <filename>/boot/boot1</filename>, and Stage Two,
212 <filename>/boot/boot2</filename></title>
214 <para>Conceptually the first and second stages are part of the same
215 program, on the same area of the disk. Because of space constraints
216 they have been split into two, but you would always install them
217 together. They are copied from the combined file
218 <filename>/boot/boot</filename> by the installer or
219 <application>disklabel</application> (see below).</para>
221 <para>They are located outside file systems, in the first track of
222 the boot slice, starting with the first sector. This is where <link
223 linkend="boot-boot0">boot0</link>, or any other boot manager,
224 expects to find a program to run which will
225 continue the boot process. The number of sectors used is easily
226 determined from the size of <filename>/boot/boot</filename>.</para>
228 <para>They are found on the boot sector of
229 the boot slice, which is where <link
230 linkend="boot-boot0">boot0</link>, or any other program on the
231 <abbrev>MBR</abbrev> expects to find the program to run to
232 continue the boot process. The files in the
233 <filename>/boot</filename> directory are copies of the real files,
234 which are stored outside of the &os; file system.</para>
236 <para><filename>boot1</filename> is very simple, since it
237 can only be 512 bytes
238 in size, and knows just enough about the &os;
239 <firstterm>disklabel</firstterm>, which stores information
240 about the slice, to find and execute <filename>boot2</filename>.</para>
242 <para><filename>boot2</filename> is slightly more sophisticated, and understands
243 the &os; file system enough to find files on it, and can
244 provide a simple interface to choose the kernel or loader to
247 <para>Since the <link linkend="boot-loader">loader</link> is
248 much more sophisticated, and provides a nice easy-to-use
249 boot configuration, <filename>boot2</filename> usually runs
250 it, but previously it
251 was tasked to run the kernel directly.</para>
253 <example id="boot-boot2-example">
254 <title><filename>boot2</filename> Screenshot</title>
256 <screen>>> DragonFly/i386 BOOT
257 Default: 0:ad(0,a)/boot/loader
261 <para>If you ever need to replace the installed
262 <filename>boot1</filename> and <filename>boot2</filename> use
263 &man.disklabel.8;:</para>
265 <screen>&prompt.root; <userinput>disklabel -B <replaceable>diskslice</replaceable></userinput></screen>
267 <para>where <replaceable>diskslice</replaceable> is the disk and slice
268 you boot from, such as <devicename>ad0s1</devicename> for the first
269 slice on the first IDE disk.</para>
273 <sect2 id="boot-loader">
274 <title>Stage Three, <filename>/boot/loader</filename></title>
276 <indexterm><primary>boot-loader</primary></indexterm>
277 <para>The loader is the final stage of the three-stage
278 bootstrap, and is located on the file system, usually as
279 <filename>/boot/loader</filename>.</para>
281 <para>The loader is intended as a user-friendly method for
282 configuration, using an easy-to-use built-in command set,
283 backed up by a more powerful interpreter, with a more complex
286 <sect3 id="boot-loader-flow">
287 <title>Loader Program Flow</title>
289 <para>During initialization, the loader will probe for a
290 console and for disks, and figure out what disk it is
291 booting from. It will set variables accordingly, and an
292 interpreter is started where user commands can be passed from
293 a script or interactively.</para>
294 <indexterm><primary>loader</primary></indexterm>
295 <indexterm><primary>loader configuration</primary></indexterm>
297 <!-- XXX talk about the boot menu -->
298 <para>The loader will then read
299 <filename>/boot/loader.rc</filename>, which by default reads
300 in <filename>/boot/defaults/loader.conf</filename> which
301 sets reasonable defaults for variables and reads
302 <filename>/boot/loader.conf</filename> for local changes to
303 those variables. <filename>loader.rc</filename> then acts
304 on these variables, loading whichever modules and kernel are
307 <para>Finally, by default, the loader will show you the booting
308 menu where you can select different options. This menu issues
309 a 10 second wait for key presses, and boots the kernel if it
310 is not interrupted. If the user selects
311 <option>"Escape to loader prompt"</option>, the user is presented
312 with a prompt which understands the easy-to-use command set,
313 where the user may adjust variables, unload all modules,
314 load modules, and then finally boot or reboot.</para>
318 <sect3 id="boot-loader-commands">
319 <title>Loader Built-In Commands</title>
321 <para>These are the most commonly used loader commands. For a
322 complete discussion of all available commands, please see
323 &man.loader.8;.</para>
327 <term>autoboot <replaceable>seconds</replaceable></term>
330 <para>Proceeds to boot the kernel if not interrupted
331 within the time span given, in seconds. It displays a
332 countdown, and the default time span is 10
339 <optional><replaceable>-options</replaceable></optional>
340 <optional><replaceable>kernelname</replaceable></optional></term>
343 <para>Immediately proceeds to boot the kernel, with the
344 given options, if any, and with the kernel name given,
350 <term>boot-conf</term>
353 <para>Goes through the same automatic configuration of
354 modules based on variables as what happens at boot.
355 This only makes sense if you use
356 <command>unload</command> first, and change some
357 variables, most commonly <envar>kernel</envar>.</para>
363 <optional><replaceable>topic</replaceable></optional></term>
366 <para>Shows help messages read from
367 <filename>/boot/loader.help</filename>. If the topic
368 given is <literal>index</literal>, then the list of
369 available topics is given.</para>
374 <term>include <replaceable>filename</replaceable>
378 <para>Processes the file with the given filename. The
379 file is read in, and interpreted line by line. An
380 error immediately stops the include command.</para>
384 <term>load <optional><option>-t</option>
385 <replaceable>type</replaceable></optional>
386 <replaceable>filename</replaceable></term>
389 <para>Loads the kernel, kernel module, or file of the
390 type given, with the filename given. Any arguments
391 after filename are passed to the file.</para>
395 <term>ls <optional><option>-l</option></optional>
396 <optional><replaceable>path</replaceable></optional></term>
399 <para>Displays a listing of files in the given path, or
400 the root directory, if the path is not specified. If
401 <option>-l</option> is specified, file sizes will be
406 <term>lsdev <optional><option>-v</option></optional></term>
409 <para>Lists all of the devices from which it may be
410 possible to load modules. If <option>-v</option> is
411 specified, more details are printed.</para>
416 <term>lsmod <optional><option>-v</option></optional></term>
419 <para>Displays loaded modules. If <option>-v</option> is
420 specified, more details are shown.</para>
425 <term>more <replaceable>filename</replaceable></term>
428 <para>Displays the files specified, with a pause at each
429 <varname>LINES</varname> displayed.</para>
437 <para>Immediately reboots the system.</para>
442 <term>set <replaceable>variable</replaceable></term>
444 <replaceable>variable</replaceable>=<replaceable>value</replaceable></term>
447 <para>Sets the loader's environment variables.</para>
455 <para>Removes all loaded modules.</para>
461 <sect3 id="boot-loader-examples">
462 <title>Loader Examples</title>
464 <para>Here are some practical examples of loader usage:</para>
467 <indexterm><primary>single-user mode</primary></indexterm>
469 <para>To simply boot your usual kernel, but in single-user
470 mode you can select the <option>"Boot DragonFly in single user mode"</option>.</para>
474 <para>To unload your usual kernel and modules, and then
475 load just your old (or another) kernel:</para>
477 <primary><filename>kernel.old</filename></primary>
480 <screen><userinput>unload</userinput>
481 <userinput>load <replaceable>kernel.old</replaceable></userinput></screen>
483 <para>You can use <filename>kernel.old</filename> to refer to
484 your previously installed kernel (when you have upgraded
485 or configured your own kernel, for example).</para>
488 <para>Use the following to load your usual modules with
489 another kernel:</para>
491 <screen><userinput>unload</userinput>
492 <userinput>set kernel="<replaceable>kernel.old</replaceable>"</userinput>
493 <userinput>boot-conf</userinput></screen></note>
497 <para>To load a kernel configuration script (an automated
498 script which does the things you would normally do in the
499 kernel boot-time configurator):</para>
501 <screen><userinput>load -t userconfig_script <replaceable>/boot/kernel.conf</replaceable></userinput></screen>
508 <sect1 id="boot-kernel">
509 <title>Kernel Interaction During Boot</title>
511 <primary>kernel</primary>
512 <secondary>boot interaction</secondary>
515 <para>Once the kernel is loaded by either <link
516 linkend="boot-loader">loader</link> (as usual) or <link
517 linkend="boot-boot1">boot2</link> (bypassing the loader), it
518 examines its boot flags, if any, and adjusts its behavior as
521 <sect2 id="boot-kernel-bootflags">
523 <primary>kernel</primary>
524 <secondary>bootflags</secondary>
526 <title>Kernel Boot Flags</title>
528 <para>Here are the more common boot flags:</para>
530 <variablelist id="boot-kernel-bootflags-list">
532 <term><option>-a</option></term>
535 <para>during kernel initialization, ask for the device
536 to mount as the root file system.</para>
541 <term><option>-C</option></term>
544 <para>boot from CDROM.</para>
549 <term><option>-c</option></term>
552 <para>run UserConfig, the boot-time kernel
558 <term><option>-s</option></term>
561 <para>boot into single-user mode</para>
566 <term><option>-v</option></term>
569 <para>be more verbose during kernel startup</para>
575 <para>There are other boot flags; read &man.boot.8; for more
576 information on them.</para></note>
581 <sect1 id="boot-init">
583 <primary><command>init</command></primary>
585 <title>Init: Process Control Initialization</title>
587 <para>Once the kernel has finished booting, it passes control to
588 the user process &man.init.8;, which is located at
589 <filename>/sbin/init</filename>, or the program path specified
590 in the <envar>init_path</envar> variable in
591 <command>loader</command>.</para>
593 <sect2 id="boot-autoreboot">
594 <title>Automatic Reboot Sequence</title>
596 <para>The automatic reboot sequence makes sure that the
597 file systems available on the system are consistent. If they
598 are not, and &man.fsck.8; cannot fix the
599 inconsistencies, &man.init.8; drops the system
600 into <link linkend="boot-singleuser">single-user mode</link>
601 for the system administrator to take care of the problems
605 <sect2 id="boot-singleuser">
606 <title>Single-User Mode</title>
607 <indexterm><primary>single-user mode</primary></indexterm>
608 <indexterm><primary>console</primary></indexterm>
610 <para>This mode can be reached through the <link
611 linkend="boot-autoreboot">automatic reboot
612 sequence</link>, with the
613 <option>"Boot DragonFly in single user mode"</option>
614 menu option, by the user booting with the
615 <option>-s</option> option from the loader prompt or setting the
616 <envar>boot_single</envar> variable in
617 <command>loader</command>.</para>
619 <para>It can also be reached by calling
620 &man.shutdown.8; without the reboot
621 (<option>-r</option>) or halt (<option>-h</option>) options,
622 from <link linkend="boot-multiuser">multi-user
625 <para>If the system <literal>console</literal> is set
626 to <literal>insecure</literal> in <filename>/etc/ttys</filename>,
627 then the system prompts for the <username>root</username> password
628 before initiating single-user mode.</para>
630 <example id="boot-insecure-console">
631 <title>An Insecure Console in <filename>/etc/ttys</filename></title>
633 <programlisting># name getty type status comments
635 # If console is marked "insecure", then init will ask for the root password
636 # when going to single-user mode.
637 console none unknown off insecure</programlisting>
641 <para>An <literal>insecure</literal> console means that you
642 consider your physical security to the console to be
643 insecure, and want to make sure only someone who knows the
644 <username>root</username> password may use single-user mode, and it
645 does not mean that you want to run your console insecurely. Thus,
646 if you want security, choose <literal>insecure</literal>,
647 not <literal>secure</literal>.</para>
651 <sect2 id="boot-multiuser">
652 <title>Multi-User Mode</title>
653 <indexterm><primary>multi-user mode</primary></indexterm>
655 <para>If &man.init.8; finds your file systems to be
656 in order, or once the user has finished in <link
657 linkend="boot-singleuser">single-user mode</link>, the
658 system enters multi-user mode, in which it starts the
659 resource configuration of the system.</para>
662 <indexterm><primary>rc files</primary></indexterm>
663 <title>Resource Configuration (rc)</title>
665 <para>The resource configuration system reads in
666 configuration defaults from
667 <filename>/etc/defaults/rc.conf</filename>, and
668 system-specific details from
669 <filename>/etc/rc.conf</filename>, and then proceeds to
670 mount the system file systems mentioned in
671 <filename>/etc/fstab</filename>, start up networking
672 services, start up miscellaneous system daemons, and
673 finally runs the startup scripts of locally installed
676 <para>The &man.rc.8; manual page is a good reference to the resource
677 configuration system, as is examining the scripts
683 <sect1 id="boot-shutdown">
684 <title>Shutdown Sequence</title>
686 <primary><command>shutdown</command></primary>
689 <para>Upon controlled shutdown, via &man.shutdown.8;,
690 &man.init.8; will attempt to run the script
691 <filename>/etc/rc.shutdown</filename>, and then proceed to send
692 all processes the <literal>TERM</literal> signal, and subsequently
693 the <literal>KILL</literal> signal to any that do not terminate
696 <para>To power down a &os; machine on architectures and systems
697 that support power management, simply use the command
698 <command>shutdown -p now</command> to turn the power off
699 immediately. To just reboot a &os; system, just use
700 <command>shutdown -r now</command>. You need to be
701 <username>root</username> or a member of
702 <groupname>operator</groupname> group to run &man.shutdown.8;.
703 The &man.halt.8; and &man.reboot.8; commands can also be used,
704 please refer to their manual pages and to &man.shutdown.8;'s one
705 for more information.</para>
708 <para>Power management requires &man.acpi.4; support in the kernel
709 or loaded as a module, or &man.apm.4; support.</para>
718 sgml-declaration: "../chapter.decl"
721 sgml-always-quote-attributes: t
722 sgml-parent-document: ("../book.sgml" "part" "chapter")