kernfs.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-system-kernfs">
  8. <?dbhtml filename="kernfs.html"?>
  9. <title>准备虚拟内核文件系统</title>
  10. <indexterm zone="ch-system-kernfs">
  11. <primary sortas="e-/dev/">/dev/*</primary>
  12. </indexterm>
  13. <!--para>Various file systems exported by the kernel are used to communicate to
  14. and from the kernel itself. These file systems are virtual in that no disk
  15. space is used for them. The content of the file systems resides in
  16. memory.</para-->
  17. <para>内核对外提供了一些文件系统,以便自己和用户空间进行通信。
  18. 它们是虚拟文件系统,并不占用磁盘空间,其内容保留在内存中。
  19. </para>
  20. <!--para>Begin by creating directories onto which the file systems will be
  21. mounted:</para-->
  22. <para>首先创建这些文件系统的挂载点:</para>
  23. <screen><userinput>mkdir -pv $LFS/{dev,proc,sys,run}</userinput></screen>
  24. <sect2>
  25. <title>创建初始设备节点</title>
  26. <!--para>When the kernel boots the system, it requires the presence of a few
  27. device nodes, in particular the <filename
  28. class="devicefile">console</filename> and <filename
  29. class="devicefile">null</filename> devices. The device nodes must be created
  30. on the hard disk so that they are available before <command>udevd</command>
  31. has been started, and additionally when Linux is started with
  32. <parameter>init=/bin/bash</parameter>. Create the devices by running the
  33. following commands:</para-->
  34. <para>在内核引导系统时,它需要一些设备节点,特别是
  35. <filename class="devicefile">console</filename>
  36. 和 <filename class="devicefile">null</filename> 两个设备。
  37. 它们需要创建在硬盘上,这样在 <command>udevd</command>
  38. 启动前即可使用,特别是在 Linux 使用
  39. <parameter>init=/bin/bash</parameter> 内核选项启动的时候。
  40. 运行以下命令创建它们:</para>
  41. <screen><userinput>mknod -m 600 $LFS/dev/console c 5 1
  42. mknod -m 666 $LFS/dev/null c 1 3</userinput></screen>
  43. </sect2>
  44. <sect2 id="ch-system-bindmount">
  45. <title>挂载和填充 /dev</title>
  46. <!--para>The recommended method of populating the <filename
  47. class="directory">/dev</filename> directory with devices is to mount a
  48. virtual filesystem (such as <systemitem
  49. class="filesystem">tmpfs</systemitem>) on the <filename
  50. class="directory">/dev</filename> directory, and allow the devices to be
  51. created dynamically on that virtual filesystem as they are detected or
  52. accessed. Device creation is generally done during the boot process
  53. by Udev. Since this new system does not yet have Udev and has not yet
  54. been booted, it is necessary to mount and populate <filename
  55. class="directory">/dev</filename> manually. This is accomplished by bind
  56. mounting the host system's <filename class="directory">/dev</filename>
  57. directory. A bind mount is a special type of mount that allows you to
  58. create a mirror of a directory or mount point to some other location. Use
  59. the following command to achieve this:</para-->
  60. <para>用设备文件填充 <filename class="directory">/dev</filename>
  61. 目录的推荐方法是挂载一个虚拟文件系统(例如
  62. <systemitem class="filesystem">tmpfs</systemitem>),
  63. 然后在设备被发现或访问时动态地创建设备文件。
  64. 这个工作通常由 Udev 在系统引导时完成,但我们的新系统还没有 Udev,
  65. 也没有被引导过,因此必须手工挂载和填充
  66. <filename class="directory">/dev</filename>。
  67. 这通过绑定挂载宿主系统的
  68. <filename class="directory">/dev</filename>
  69. 目录就可以实现,绑定挂载是一种特殊挂载类型,
  70. 它允许在另外的位置创建某个目录或挂载点的映像。
  71. 运行以下命令进行绑定挂载:</para>
  72. <screen><userinput>mount -v --bind /dev $LFS/dev</userinput></screen>
  73. </sect2>
  74. <sect2 id="ch-system-kernfsmount">
  75. <title>挂载虚拟内核文件系统</title>
  76. <para>现在挂载其他虚拟内核文件系统:</para>
  77. <screen><userinput>mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
  78. mount -vt proc proc $LFS/proc
  79. mount -vt sysfs sysfs $LFS/sys
  80. mount -vt tmpfs tmpfs $LFS/run</userinput></screen>
  81. <variablelist>
  82. <title>devpts 挂载选项的含义:</title>
  83. <varlistentry>
  84. <term><parameter>gid=5</parameter></term>
  85. <listitem>
  86. <!--para>This ensures that all devpts-created device nodes are owned by
  87. group ID 5. This is the ID we will use later on for the <systemitem
  88. class="groupname">tty</systemitem> group. We use the group ID instead
  89. of a name, since the host system might use a different ID for its
  90. <systemitem class="groupname">tty</systemitem> group.</para-->
  91. <para>这保证 devpts 创建的所有设备节点都属于 ID 为 5 的组,
  92. 我们之后会把这个 ID 分配给 <systemitem class="groupname">
  93. tty</systemitem> 组。这里使用组 ID 而不是名称,
  94. 因为宿主系统的 <systemitem class="groupname">tty</systemitem>
  95. 组可能有不同的 ID 。</para>
  96. </listitem>
  97. </varlistentry>
  98. <varlistentry>
  99. <term><parameter>mode=0620</parameter></term>
  100. <listitem>
  101. <!--para>This ensures that all devpts-created device nodes have mode 0620
  102. (user readable and writable, group writable). Together with the
  103. option above, this ensures that devpts will create device nodes that
  104. meet the requirements of grantpt(), meaning the Glibc
  105. <command>pt_chown</command> helper binary (which is not installed by
  106. default) is not necessary.</para-->
  107. <para>该选项确保 devpts 创建的所有设备节点具有权限码 0620
  108. (所有者可读写,组成员可写)。与上一个选项结合使用,
  109. 可以保证 devpts 创建符合 grantpt() 要求的设备节点,
  110. 摆脱对 Glibc <command>pt_chown</command> 辅助程序
  111. (默认不安装)的依赖。</para>
  112. </listitem>
  113. </varlistentry>
  114. </variablelist>
  115. <!--para>In some host systems, <filename>/dev/shm</filename> is a
  116. symbolic link to <filename class="directory">/run/shm</filename>.
  117. The /run tmpfs was mounted above so in this case only a
  118. directory needs to be created.</para-->
  119. <para>在某些宿主系统上,<filename>/dev/shm</filename>
  120. 是一个指向 <filename class="directory">/run/shm</filename>
  121. 的符号链接。我们已经在 /run 下挂载了 tmpfs 文件系统,
  122. 因此在这里只需要创建一个目录。</para>
  123. <screen><userinput>if [ -h $LFS/dev/shm ]; then
  124. mkdir -pv $LFS/$(readlink $LFS/dev/shm)
  125. fi</userinput></screen>
  126. </sect2>
  127. </sect1>