Files
master/chapter06/chroot.html
2015-05-23 18:50:06 +08:00

121 lines
6.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content=
"application/xhtml+xml; charset=utf-8" />
<title>
6.4.&nbsp;进入Chroot环境
</title>
<link rel="stylesheet" type="text/css" href="../stylesheets/lfs.css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css"
media="print" />
</head>
<body class="lfs" id="lfs-7.7-systemd">
<div class="navheader">
<h4>
Linux From Scratch - Version 7.7-systemd
</h4>
<h3>
Chapter&nbsp;6.&nbsp;Installing Basic System Software
</h3>
<ul>
<li class="prev">
<a accesskey="p" href="pkgmgt.html" title=
"管理软件包">下一页</a>
<p>
管理软件包
</p>
</li>
<li class="next">
<a accesskey="n" href="creatingdirs.html" title=
"创建目录">下一页</a>
<p>
创建目录
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title=
"第6章 安装基本的系统软件">返回</a>
</li>
<li class="home">
<a accesskey="h" href="../index.html" title=
"Linux From Scratch - Version 7.7-systemd">首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="en" xml:lang="en">
<h1 class="sect1">
<a id="ch-system-chroot" name="ch-system-chroot"></a>6.4. 进入Chroot环境
</h1>
<p>
现在可以切换到chroot环境开始构建和安装最终的LFS系统了。使用<code class="systemitem">root</code>用户,运行下面的命令进入这个空间,目前,里面只入住了之前准备的临时工具:
</p>
<pre class="userinput">
<kbd class="command">chroot "$LFS" /tools/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash --login +h</kbd>
</pre>
<p>
<span class="command"><strong>env</strong></span>命令的<em class="parameter"><code>-i</code></em>选项会清除chroot切换进去的环境里所有变量。随后只重新设定了<code class="envar">HOME</code><code class="envar">TERM</code><code class="envar">PS1</code><code class="envar">PATH</code>变量。<em class="parameter"><code>TERM=$TERM</code></em>语句会设定chroot进入的环境里的<code class="envar">TERM</code>变量为进入前该变量同样的值。许多程序需要这个变量才能正常工作,比如<span class="command"><strong>vim</strong></span><span class="command"><strong>less</strong></span>。如果还需要设定其他变量,比如<code class="envar">CFLAGS</code><code class="envar">CXXFLAGS</code>,就在这里一起设定比较合适。
</p>
<p>
从这以后,不再需要<code class="envar">LFS</code>变量了因为后面所有工作都将被限定在LFS文件系统里。这是因为我们已经告诉Bash终端<code class="filename">$LFS</code>就是当前的根目录(<code class="filename">/</code>)。
</p>
<p>
请注意<code class="filename">/tools/bin</code>放在了<code class="envar">PATH</code>变量的最后。意思是在每个软件的最后版本编译安装好后就不再使用的临时工具。这还需要shell不能<span class="quote">&ldquo;<span class="quote">记住</span>&rdquo;</span>每个可执行文件的位置&mdash;这样的话,还要给<span class="command"><strong>bash</strong></span>加上<em class="parameter"><code>+h</code></em>选项来关闭哈希功能。
</p>
<p>
注意一下<span class="command"><strong>bash</strong></span>的提示符是<code class="computeroutput">I have no name!</code>。这是正常的,因为这个时候<code class="filename">/etc/passwd</code>文件还没有被创建。
</p>
<div class="admon note">
<img alt="[Note]" src="../images/note.png" />
<h3>
注意
</h3>
<p>
非常重要本章从这以后的命令以及后续章节里的命令都要在chroot环境下运行。如果因为某种原因比如说重启离开了这个环境请保证要按照<a class="xref" href="kernfs.html#ch-system-bindmount" title="6.2.2.&nbsp;挂载和激活/dev">6.2.2,&ldquo;挂载和激活/dev&rdquo;</a><a class="xref" href="kernfs.html#ch-system-kernfsmount" title="6.2.3.&nbsp;挂载虚拟内核文件系统">6.2.3,&ldquo;挂载虚拟内核文件系统&rdquo;</a>里所说的那样挂载虚拟内核文件系统然后在继续构建之前重新运行chroot进入环境。
</p>
</div>
</div>
<div class="navfooter">
<div class="book">
<div class="titlepage">
<div class="author">
<span class="firstname">翻译团队:<a href="http://lctt.github.io/" target="_blank">LCTT</a></span>
<span class="surname">译者/校对:<a href="http://github.com/zpl1025" target="_blank">zpl1025</a>/</span>
</div>
</div>
</div>
<ul>
<li class="prev">
<a accesskey="p" href="pkgmgt.html" title=
"管理软件包">下一页</a>
<p>
管理软件包
</p>
</li>
<li class="next">
<a accesskey="n" href="creatingdirs.html" title=
"创建目录">下一页</a>
<p>
创建目录
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title=
"第6章 安装基本的系统软件">返回</a>
</li>
<li class="home">
<a accesskey="h" href="../index.html" title=
"Linux From Scratch - Version 7.7-systemd">首页</a>
</li>
</ul>
</div>
</body>
</html>