123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
- "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
- <!ENTITY % general-entities SYSTEM "../general.ent">
- %general-entities;
- ]>
- <sect1 id="ch-system-kernfs">
- <?dbhtml filename="kernfs.html"?>
- <title>准备虚拟内核文件系统</title>
- <indexterm zone="ch-system-kernfs">
- <primary sortas="e-/dev/">/dev/*</primary>
- </indexterm>
- <!--para>Various file systems exported by the kernel are used to communicate to
- and from the kernel itself. These file systems are virtual in that no disk
- space is used for them. The content of the file systems resides in
- memory.</para-->
- <para>内核对外提供了一些文件系统,以便自己和用户空间进行通信。
- 它们是虚拟文件系统,并不占用磁盘空间,其内容保留在内存中。
- </para>
- <!--para>Begin by creating directories onto which the file systems will be
- mounted:</para-->
- <para>首先创建这些文件系统的挂载点:</para>
- <screen><userinput>mkdir -pv $LFS/{dev,proc,sys,run}</userinput></screen>
- <sect2>
- <title>创建初始设备节点</title>
- <!--para>When the kernel boots the system, it requires the presence of a few
- device nodes, in particular the <filename
- class="devicefile">console</filename> and <filename
- class="devicefile">null</filename> devices. The device nodes must be created
- on the hard disk so that they are available before <command>udevd</command>
- has been started, and additionally when Linux is started with
- <parameter>init=/bin/bash</parameter>. Create the devices by running the
- following commands:</para-->
- <para>在内核引导系统时,它需要一些设备节点,特别是
- <filename class="devicefile">console</filename>
- 和 <filename class="devicefile">null</filename> 两个设备。
- 它们需要创建在硬盘上,这样在 <command>udevd</command>
- 启动前即可使用,特别是在 Linux 使用
- <parameter>init=/bin/bash</parameter> 内核选项启动的时候。
- 运行以下命令创建它们:</para>
- <screen><userinput>mknod -m 600 $LFS/dev/console c 5 1
- mknod -m 666 $LFS/dev/null c 1 3</userinput></screen>
- </sect2>
- <sect2 id="ch-system-bindmount">
- <title>挂载和填充 /dev</title>
- <!--para>The recommended method of populating the <filename
- class="directory">/dev</filename> directory with devices is to mount a
- virtual filesystem (such as <systemitem
- class="filesystem">tmpfs</systemitem>) on the <filename
- class="directory">/dev</filename> directory, and allow the devices to be
- created dynamically on that virtual filesystem as they are detected or
- accessed. Device creation is generally done during the boot process
- by Udev. Since this new system does not yet have Udev and has not yet
- been booted, it is necessary to mount and populate <filename
- class="directory">/dev</filename> manually. This is accomplished by bind
- mounting the host system's <filename class="directory">/dev</filename>
- directory. A bind mount is a special type of mount that allows you to
- create a mirror of a directory or mount point to some other location. Use
- the following command to achieve this:</para-->
- <para>用设备文件填充 <filename class="directory">/dev</filename>
- 目录的推荐方法是挂载一个虚拟文件系统(例如
- <systemitem class="filesystem">tmpfs</systemitem>),
- 然后在设备被发现或访问时动态地创建设备文件。
- 这个工作通常由 Udev 在系统引导时完成,但我们的新系统还没有 Udev,
- 也没有被引导过,因此必须手工挂载和填充
- <filename class="directory">/dev</filename>。
- 这通过绑定挂载宿主系统的
- <filename class="directory">/dev</filename>
- 目录就可以实现,绑定挂载是一种特殊挂载类型,
- 它允许在另外的位置创建某个目录或挂载点的映像。
- 运行以下命令进行绑定挂载:</para>
- <screen><userinput>mount -v --bind /dev $LFS/dev</userinput></screen>
- </sect2>
- <sect2 id="ch-system-kernfsmount">
- <title>挂载虚拟内核文件系统</title>
- <para>现在挂载其他虚拟内核文件系统:</para>
- <screen><userinput>mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
- mount -vt proc proc $LFS/proc
- mount -vt sysfs sysfs $LFS/sys
- mount -vt tmpfs tmpfs $LFS/run</userinput></screen>
- <variablelist>
- <title>devpts 挂载选项的含义:</title>
- <varlistentry>
- <term><parameter>gid=5</parameter></term>
- <listitem>
- <!--para>This ensures that all devpts-created device nodes are owned by
- group ID 5. This is the ID we will use later on for the <systemitem
- class="groupname">tty</systemitem> group. We use the group ID instead
- of a name, since the host system might use a different ID for its
- <systemitem class="groupname">tty</systemitem> group.</para-->
- <para>这保证 devpts 创建的所有设备节点都属于 ID 为 5 的组,
- 我们之后会把这个 ID 分配给 <systemitem class="groupname">
- tty</systemitem> 组。这里使用组 ID 而不是名称,
- 因为宿主系统的 <systemitem class="groupname">tty</systemitem>
- 组可能有不同的 ID 。</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><parameter>mode=0620</parameter></term>
- <listitem>
- <!--para>This ensures that all devpts-created device nodes have mode 0620
- (user readable and writable, group writable). Together with the
- option above, this ensures that devpts will create device nodes that
- meet the requirements of grantpt(), meaning the Glibc
- <command>pt_chown</command> helper binary (which is not installed by
- default) is not necessary.</para-->
- <para>该选项确保 devpts 创建的所有设备节点具有权限码 0620
- (所有者可读写,组成员可写)。与上一个选项结合使用,
- 可以保证 devpts 创建符合 grantpt() 要求的设备节点,
- 摆脱对 Glibc <command>pt_chown</command> 辅助程序
- (默认不安装)的依赖。</para>
- </listitem>
- </varlistentry>
- </variablelist>
- <!--para>In some host systems, <filename>/dev/shm</filename> is a
- symbolic link to <filename class="directory">/run/shm</filename>.
- The /run tmpfs was mounted above so in this case only a
- directory needs to be created.</para-->
- <para>在某些宿主系统上,<filename>/dev/shm</filename>
- 是一个指向 <filename class="directory">/run/shm</filename>
- 的符号链接。我们已经在 /run 下挂载了 tmpfs 文件系统,
- 因此在这里只需要创建一个目录。</para>
- <screen><userinput>if [ -h $LFS/dev/shm ]; then
- mkdir -pv $LFS/$(readlink $LFS/dev/shm)
- fi</userinput></screen>
- </sect2>
- </sect1>
|