📄 makeworld.html
字号:
Base System</a></h3><p>You must be in the <tt class="FILENAME">/usr/src</tt> directory:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/src</kbd></pre><p>(unless, of course, your source code is elsewhere, in which case change to thatdirectory instead).</p><p>To rebuild the world you use the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a> command. Thiscommand reads instructions from the <tt class="FILENAME">Makefile</tt>, which describeshow the programs that comprise FreeBSD should be rebuilt, the order in which they shouldbe built, and so on.</p><p>The general format of the command line you will type is as follows:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make -<varclass="REPLACEABLE">x</var> -D<var class="REPLACEABLE">VARIABLE</var> <varclass="REPLACEABLE">target</var></kbd></pre><p>In this example, <var class="OPTION">-<var class="REPLACEABLE">x</var></var> is anoption that you would pass to <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a>. See the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a> manual pagefor an example of the options you can pass.</p><p><var class="OPTION">-D<var class="REPLACEABLE">VARIABLE</var></var> passes a variableto the <tt class="FILENAME">Makefile</tt>. The behavior of the <ttclass="FILENAME">Makefile</tt> is controlled by these variables. These are the samevariables as are set in <tt class="FILENAME">/etc/make.conf</tt>, and this providesanother way of setting them.</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make -DNOPROFILE <varclass="REPLACEABLE">target</var></kbd></pre><p>is another way of specifying that profiled libraries should not be built, andcorresponds with the</p><pre class="PROGRAMLISTING">NOPROFILE= true # Avoid compiling profiled libraries</pre><p>line in <tt class="FILENAME">/etc/make.conf</tt>.</p><p><var class="REPLACEABLE">target</var> tells <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a> what you wantto do. Each <tt class="FILENAME">Makefile</tt> defines a number of different ``targets'',and your choice of target determines what happens.</p><p>Some targets are listed in the <tt class="FILENAME">Makefile</tt>, but are not meantfor you to run. Instead, they are used by the build process to break out the stepsnecessary to rebuild the system into a number of sub-steps.</p><p>Most of the time you will not need to pass any parameters to <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a>, and so yourcommand like will look like this:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make <varclass="REPLACEABLE">target</var></kbd></pre><p>Beginning with version 2.2.5 of FreeBSD (actually, it was first created on theFreeBSD-CURRENT branch, and then retrofitted to FreeBSD-STABLE midway between 2.2.2 and2.2.5) the <tt class="MAKETARGET">world</tt> target has been split in two: <ttclass="MAKETARGET">buildworld</tt> and <tt class="MAKETARGET">installworld</tt>.Beginning with version 5.3 of FreeBSD the <tt class="MAKETARGET">world</tt> target willbe changed so it will not work at all by default because it is actually dangerous formost users.</p><p>As the names imply, <tt class="MAKETARGET">buildworld</tt> builds a complete new treeunder <tt class="FILENAME">/usr/obj</tt>, and <tt class="MAKETARGET">installworld</tt>installs this tree on the current machine.</p><p>This is very useful for 2 reasons. First, it allows you to do the build safe in theknowledge that no components of your running system will be affected. The build is ``selfhosted''. Because of this, you can safely run <tt class="MAKETARGET">buildworld</tt> on amachine running in multi-user mode with no fear of ill-effects. It is still recommendedthat you run the <tt class="MAKETARGET">installworld</tt> part in single user mode,though.</p><p>Secondly, it allows you to use NFS mounts to upgrade multiple machines on yournetwork. If you have three machines, <tt class="HOSTID">A</tt>, <tt class="HOSTID">B</tt>and <tt class="HOSTID">C</tt> that you want to upgrade, run <tt class="COMMAND">makebuildworld</tt> and <tt class="COMMAND">make installworld</tt> on <ttclass="HOSTID">A</tt>. <tt class="HOSTID">B</tt> and <tt class="HOSTID">C</tt> shouldthen NFS mount <tt class="FILENAME">/usr/src</tt> and <tt class="FILENAME">/usr/obj</tt>from <tt class="HOSTID">A</tt>, and you can then run <tt class="COMMAND">makeinstallworld</tt> to install the results of the build on <tt class="HOSTID">B</tt> and<tt class="HOSTID">C</tt>.</p><p>Although the <tt class="MAKETARGET">world</tt> target still exists, you are stronglyencouraged not to use it.</p><p>Run</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make buildworld</kbd></pre><p>It is now possible to specify a <var class="OPTION">-j</var> option to <ttclass="COMMAND">make</tt> which will cause it to spawn several simultaneous processes.This is most useful on multi-CPU machines. However, since much of the compiling processis IO bound rather than CPU bound it is also useful on single CPU machines.</p><p>On a typical single-CPU machine you would run:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make -j4 buildworld</kbd></pre><p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=make&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">make</span>(1)</span></a> will then haveup to 4 processes running at any one time. Empirical evidence posted to the mailing listsshows this generally gives the best performance benefit.</p><p>If you have a multi-CPU machine and you are using an SMP configured kernel try valuesbetween 6 and 10 and see how they speed things up.</p><p>Be aware that this is still somewhat experimental, and commits to the source tree mayoccasionally break this feature. If the world fails to compile using this parameter tryagain without it before you report any problems.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN27762" name="AEN27762">19.4.7.3 Timings</a></h3><p>Many factors influence the build time, but currently a 500 MHz <spanclass="TRADEMARK">Pentium</span>® III with 128 MB of RAM takes about2 hours to build the FreeBSD-STABLE tree, with no tricks or shortcuts used duringthe process. A FreeBSD-CURRENT tree will take somewhat longer.</p></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN27770" name="AEN27770">19.4.8 Compile and Install a NewKernel</a></h2><p>To take full advantage of your new system you should recompile the kernel. This ispractically a necessity, as certain memory structures may have changed, and programs like<a href="http://www.FreeBSD.org/cgi/man.cgi?query=ps&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ps</span>(1)</span></a> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=top&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">top</span>(1)</span></a> will fail towork until the kernel and source code versions are the same.</p><p>The simplest, safest way to do this is to build and install a kernel based on <ttclass="FILENAME">GENERIC</tt>. While <tt class="FILENAME">GENERIC</tt> may not have allthe necessary devices for your system, it should contain everything necessary to bootyour system back to single user mode. This is a good test that the new system worksproperly. After booting from <tt class="FILENAME">GENERIC</tt> and verifying that yoursystem works you can then build a new kernel based on your normal kernel configurationfile.</p><p>On modern versions of FreeBSD it is important to <ahref="makeworld.html#MAKE-BUILDWORLD">build world</a> before building a new kernel.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> If you want to build a custom kernel, and already have a configurationfile, just use <var class="LITERAL">KERNCONF=<varclass="REPLACEABLE">MYKERNEL</var></var> like this:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/src</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make buildkernel KERNCONF=<varclass="REPLACEABLE">MYKERNEL</var></kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make installkernel KERNCONF=<varclass="REPLACEABLE">MYKERNEL</var></kbd></pre><p>In FreeBSD 4.2 and older you must replace <var class="LITERAL">KERNCONF=</var>with <var class="LITERAL">KERNEL=</var>. 4.2-STABLE that was fetched before Feb 2nd, 2001does not recognize <var class="LITERAL">KERNCONF=</var>.</p></blockquote></div><p>Note that if you have raised <var class="LITERAL">kern.securelevel</var> above 1 <spanclass="emphasis"><i class="EMPHASIS">and</i></span> you have set either the <varclass="LITERAL">noschg</var> or similar flags to your kernel binary, you might find itnecessary to drop into single user mode to use <tt class="MAKETARGET">installkernel</tt>.Otherwise you should be able to run both these commands from multi user mode withoutproblems. See <a href="http://www.FreeBSD.org/cgi/man.cgi?query=init&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">init</span>(8)</span></a> for detailsabout <var class="LITERAL">kern.securelevel</var> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=chflags&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">chflags</span>(1)</span></a> for detailsabout the various file flags.</p><p>If you are upgrading to a version of FreeBSD below 4.0 you should use the old kernelbuild procedure. However, it is recommended that you use the new version of <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=config&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">config</span>(8)</span></a>, using acommand line like this.</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">/usr/obj/usr/src/usr.sbin/config/config <varclass="REPLACEABLE">KERNELNAME</var></kbd></pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN27825" name="AEN27825">19.4.9 Reboot into Single UserMode</a></h2><p>You should reboot into single user mode to test the new kernel works. Do this byfollowing the instructions in <a href="makeworld.html#MAKEWORLD-SINGLEUSER">Section19.4.5</a>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN27831" name="AEN27831">19.4.10 Install the New SystemBinaries</a></h2><p>If you were building a version of FreeBSD recent enough to have used <ttclass="COMMAND">make buildworld</tt> then you should now use <ttclass="MAKETARGET">installworld</tt> to install the new system binaries.</p><p>Run</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/src</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make installworld</kbd></pre><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> If you specified variables on the <tt class="COMMAND">makebuildworld</tt> command line, you must specify the same variables in the <ttclass="COMMAND">make installworld</tt> command line. This does not necessarily hold truefor other options; for example, <var class="OPTION">-j</var> must never be used with <ttclass="MAKETARGET">installworld</tt>.</p><p>For example, if you ran:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make -DNOPROFILE buildworld</kbd></pre><p>you must install the results with:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make -DNOPROFILE installworld</kbd></pre><p>otherwise it would try to install profiled libraries that had not been built duringthe <tt class="COMMAND">make buildworld</tt> phase.</p></blockquote></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN27858" name="AEN27858">19.4.11 Update Files Not Updated by<tt class="COMMAND">make installworld</tt></a></h2><p>Remaking the world will not update certain directories (in particular, <ttclass="FILENAME">/etc</tt>, <tt class="FILENAME">/var</tt> and <ttclass="FILENAME">/usr</tt>) with new or changed configuration files.</p><p>The simplest way to update these files is to use <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a>, thoughit is possible to do it manually if you would prefer to do that. Regardless of which wayyou choose, be sure to make a backup of <tt class="FILENAME">/etc</tt> in case anythinggoes wrong.</p><div class="SECT3"><h3 class="SECT3"><a id="MERGEMASTER" name="MERGEMASTER">19.4.11.1 <ttclass="COMMAND">mergemaster</tt></a></h3><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Tom Rhodes.</i> <p>The <a href="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a> utilityis a Bourne script that will aid you in determining the differences between yourconfiguration files in <tt class="FILENAME">/etc</tt>, and the configuration files in thesource tree <tt class="FILENAME">/usr/src/etc</tt>. This is the recommended solution forkeeping the system configuration files up to date with those located in the sourcetree.</p><p><tt class="COMMAND">mergemaster</tt> was integrated into the FreeBSD base systembetween 3.3-RELEASE and 3.4-RELEASE, which means it is present in all -STABLE and-CURRENT systems since 3.3.</p><p>To begin simply type <tt class="COMMAND">mergemaster</tt> at your prompt, and watch itstart going. <tt class="COMMAND">mergemaster</tt> will then build a temporary rootenvironment, from <tt class="FILENAME">/</tt> down, and populate it with various systemconfiguration files. Those files are then compared to the ones currently installed inyour system. At this point, files that differ will be shown in <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=diff&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span></a> format, withthe <var class="OPTION">+</var> sign representing added or modified lines, and <varclass="OPTION">-</var> representing lines that will be either removed completely, orreplaced with a new line. See the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=diff&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span></a> manual pagefor more information about the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=diff&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span></a> syntax and howfile differences are shown.</p><p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a> willthen show you each file that displays variances, and at this point you will have theoption of either deleting the new file (referred to as the temporary file), installingthe temporary file in its unmodified state, merging the temporary file with the currentlyinstalled file, or viewing the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=diff&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span></a> resultsagain.</p><p>Choosing to delete the temporary file will tell <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a> that wewish to keep our current file unchanged, and to delete the new version. This option isnot recommended, unless you see no reason to change the current file. You can get help atany time by typing <b class="KEYCAP">?</b> at the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mergemaster&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mergemaster</span>(8)</span></a> prompt.If the user chooses to skip a file, it will be presented again after all other files havebeen dealt with.</p><p>Choosing to install the unmodified temporary file will replace the current file withthe new one. For most unmodified files, this is the best option.</p><p>Choosing to merge the file will present you with a text editor, and the contents of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -