⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot-blocks.html

📁 这是很好的学习嵌入式LINUX的文章
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>The MBR, and Boot Stages One, Two, and Three</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="The FreeBSD Booting Process" href="boot.html" /><link rel="PREVIOUS" title="The Booting Problem" href="boot-introduction.html" /><link rel="NEXT" title="Kernel Interaction During Boot" href="boot-kernel.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="boot-introduction.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 12 The FreeBSD BootingProcess</td><td width="10%" align="right" valign="bottom"><a href="boot-kernel.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="BOOT-BLOCKS" name="BOOT-BLOCKS">12.3 The MBR, and Boot StagesOne, Two, and Three</a></h1><div class="SECT2"><h2 class="SECT2"><a id="BOOT-BOOT0" name="BOOT-BOOT0">12.3.1 MBR, <ttclass="FILENAME">/boot/boot0</tt></a></h2><p>The FreeBSD MBR is located in <tt class="FILENAME">/boot/boot0</tt>. This is a <spanclass="emphasis"><i class="EMPHASIS">copy</i></span> of the MBR, as the real MBR must beplaced on a special part of the disk, outside the FreeBSD area.</p><p><tt class="FILENAME">boot0</tt> is very simple, since the program in the <abbrclass="ABBREV">MBR</abbr> can only be 512 bytes in size. If you have installed theFreeBSD MBR and have installed multiple operating systems on your hard disks then youwill see a display similar to this one at boot time:</p><div class="EXAMPLE"><a id="BOOT-BOOT0-EXAMPLE" name="BOOT-BOOT0-EXAMPLE"></a><p><b>Example 12-1. <tt class="FILENAME">boot0</tt> Screenshot</b></p><pre class="SCREEN">F1 DOSF2 FreeBSDF3 LinuxF4 ??F5 Drive 1Default: F2</pre></div><p>Other operating systems, in particular <spanclass="TRADEMARK">Windows</span>&reg;&nbsp;95, have been known to overwrite an existingMBR with their own. If this happens to you, or you want to replace your existing MBR withthe FreeBSD MBR then use the following command:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">fdisk -B -b /boot/boot0 <varclass="REPLACEABLE">device</var></kbd></pre><p>Where <var class="REPLACEABLE">device</var> is the device that you boot from, such as<tt class="DEVICENAME">ad0</tt> for the first IDE disk, <tt class="DEVICENAME">ad2</tt>for the first IDE disk on a second IDE controller, <tt class="DEVICENAME">da0</tt> forthe first SCSI disk, and so on.</p><p>If you are a Linux user, however, and prefer that <b class="APPLICATION">LILO</b>control the boot process, you can edit the <tt class="FILENAME">/etc/lilo.conf</tt> filefor FreeBSD, or select <var class="OPTION">Leave The Master Boot Record Untouched</var>during the FreeBSD installation process. If you have installed the FreeBSD boot manager,you can boot back into Linux and modify the <b class="APPLICATION">LILO</b> configurationfile <tt class="FILENAME">/etc/lilo.conf</tt> and add the following option:</p><pre class="PROGRAMLISTING">other=/dev/hdXYtable=/dev/hdbloader=/boot/chain.blabel=FreeBSD</pre><p>which will permit the booting of FreeBSD and Linux via <bclass="APPLICATION">LILO</b>. In our example, we use <var class="REPLACEABLE">XY</var> todetermine drive number and partition. If you are using a <acronymclass="ACRONYM">SCSI</acronym> drive, you will want to change <varclass="REPLACEABLE">/dev/hdXY</var> to read something similar to <varclass="REPLACEABLE">/dev/sdXY</var>, which again uses the <varclass="REPLACEABLE">XY</var> syntax. The <var class="OPTION">loader=/boot/chain.b</var>can be omitted if you have both operating systems on the same drive. You can now run <ttclass="COMMAND">/sbin/lilo -v</tt> to commit your new changes to the system, this shouldbe verified with screen messages.</p></div><div class="SECT2"><h2 class="SECT2"><a id="BOOT-BOOT1" name="BOOT-BOOT1">12.3.2 Stage One, <ttclass="FILENAME">/boot/boot1</tt>, and Stage Two, <ttclass="FILENAME">/boot/boot2</tt></a></h2><p>Conceptually the first and second stages are part of the same program, on the samearea of the disk. Because of space constraints they have been split into two, but youwould always install them together.</p><p>They are found on the boot sector of the boot slice, which is where <ahref="boot-blocks.html#BOOT-BOOT0">boot0</a>, or any other program on the <abbrclass="ABBREV">MBR</abbr> expects to find the program to run to continue the bootprocess. The files in the <tt class="FILENAME">/boot</tt> directory are copies of thereal files, which are stored outside of the FreeBSD file system.</p><p><tt class="FILENAME">boot1</tt> is very simple, since it too can only be 512 bytes insize, and knows just enough about the FreeBSD <i class="FIRSTTERM">disklabel</i>, whichstores information about the slice, to find and execute <ttclass="FILENAME">boot2</tt>.</p><p><tt class="FILENAME">boot2</tt> is slightly more sophisticated, and understands theFreeBSD file system enough to find files on it, and can provide a simple interface tochoose the kernel or loader to run.</p><p>Since the <a href="boot-blocks.html#BOOT-LOADER">loader</a> is much moresophisticated, and provides a nice easy-to-use boot configuration, <ttclass="FILENAME">boot2</tt> usually runs it, but previously it was tasked to run thekernel directly.</p><div class="EXAMPLE"><a id="BOOT-BOOT2-EXAMPLE" name="BOOT-BOOT2-EXAMPLE"></a><p><b>Example 12-2. <tt class="FILENAME">boot2</tt> Screenshot</b></p><pre class="SCREEN">&gt;&gt; FreeBSD/i386 BOOTDefault: 0:ad(0,a)/kernelboot:</pre></div><p>If you ever need to replace the installed <tt class="FILENAME">boot1</tt> and <ttclass="FILENAME">boot2</tt> use <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=disklabel&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">disklabel</span>(8)</span></a>:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">disklabel -B <varclass="REPLACEABLE">diskslice</var></kbd></pre><p>where <var class="REPLACEABLE">diskslice</var> is the disk and slice you boot from,such as <tt class="DEVICENAME">ad0s1</tt> for the first slice on the first IDE disk.</p><div class="WARNING"><blockquote class="WARNING"><p><b>Dangerously Dedicated Mode:</b> If you use just the disk name, such as <ttclass="DEVICENAME">ad0</tt>, in the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=disklabel&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">disklabel</span>(8)</span></a> commandyou will create a dangerously dedicated disk, without slices. This is almost certainlynot what you want to do, so make sure you double check the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=disklabel&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">disklabel</span>(8)</span></a> commandbefore you press <b class="KEYCAP">Return</b>.</p></blockquote></div></div><div class="SECT2"><h2 class="SECT2"><a id="BOOT-LOADER" name="BOOT-LOADER">12.3.3 Stage Three, <ttclass="FILENAME">/boot/loader</tt></a></h2><p>The loader is the final stage of the three-stage bootstrap, and is located on the filesystem, usually as <tt class="FILENAME">/boot/loader</tt>.</p><p>The loader is intended as a user-friendly method for configuration, using aneasy-to-use built-in command set, backed up by a more powerful interpreter, with a morecomplex command set.</p><div class="SECT3"><h3 class="SECT3"><a id="BOOT-LOADER-FLOW" name="BOOT-LOADER-FLOW">12.3.3.1 LoaderProgram Flow</a></h3><p>During initialization, the loader will probe for a console and for disks, and figureout what disk it is booting from. It will set variables accordingly, and an interpreteris started where user commands can be passed from a script or interactively.</p><p>The loader will then read <tt class="FILENAME">/boot/loader.rc</tt>, which by defaultreads in <tt class="FILENAME">/boot/defaults/loader.conf</tt> which sets reasonabledefaults for variables and reads <tt class="FILENAME">/boot/loader.conf</tt> for localchanges to those variables. <tt class="FILENAME">loader.rc</tt> then acts on thesevariables, loading whichever modules and kernel are selected.</p><p>Finally, by default, the loader issues a 10 second wait for key presses, and boots thekernel if it is not interrupted. If interrupted, the user is presented with a promptwhich understands the easy-to-use command set, where the user may adjust variables,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -