createfiles.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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-createfiles">
  8. <?dbhtml filename="createfiles.html"?>
  9. <title>创建必要的文件和符号链接</title>
  10. <indexterm zone="ch-system-createfiles">
  11. <primary sortas="e-/etc/passwd">/etc/passwd</primary>
  12. </indexterm>
  13. <indexterm zone="ch-system-createfiles">
  14. <primary sortas="e-/etc/group">/etc/group</primary>
  15. </indexterm>
  16. <indexterm zone="ch-system-createfiles">
  17. <primary sortas="e-/var/run/utmp">/var/run/utmp</primary>
  18. </indexterm>
  19. <indexterm zone="ch-system-createfiles">
  20. <primary sortas="e-/var/log/btmp">/var/log/btmp</primary>
  21. </indexterm>
  22. <indexterm zone="ch-system-createfiles">
  23. <primary sortas="e-/var/log/lastlog">/var/log/lastlog</primary>
  24. </indexterm>
  25. <indexterm zone="ch-system-createfiles">
  26. <primary sortas="e-/var/log/wtmp">/var/log/wtmp</primary>
  27. </indexterm>
  28. <!--para>Some programs use hard-wired paths to programs which do not exist yet.
  29. In order to satisfy these programs, create a number of symbolic links which
  30. will be replaced by real files throughout the course of this chapter after the
  31. software has been installed:</para-->
  32. <para>有些程序使用硬编码的路径访问当前还不存在的程序。
  33. 为了满足它们的要求,需要创建一些符号链接。在本章的后续内容中,
  34. 它们将被安装好的软件包中真正的文件替代:</para>
  35. <screen revision="sysv"><userinput>ln -sv /tools/bin/{bash,cat,dd,echo,ln,pwd,rm,stty} /bin
  36. ln -sv /tools/bin/{install,perl} /usr/bin
  37. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  38. ln -sv /tools/lib/libstdc++.{a,so{,.6}} /usr/lib
  39. ln -sv bash /bin/sh</userinput></screen>
  40. <!--sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la -->
  41. <screen revision="systemd"><userinput>ln -sv /tools/bin/{bash,cat,dd,echo,ln,pwd,rm,stty} /bin
  42. ln -sv /tools/bin/{env,install,perl} /usr/bin
  43. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  44. ln -sv /tools/lib/libstdc++.{a,so{,.6}} /usr/lib
  45. for lib in blkid lzma mount uuid
  46. do
  47. ln -sv /tools/lib/lib$lib.so* /usr/lib
  48. done
  49. ln -svf /tools/include/blkid /usr/include
  50. ln -svf /tools/include/libmount /usr/include
  51. ln -svf /tools/include/uuid /usr/include
  52. install -vdm755 /usr/lib/pkgconfig
  53. for pc in blkid mount uuid
  54. do
  55. sed 's@tools@usr@g' /tools/lib/pkgconfig/${pc}.pc \
  56. > /usr/lib/pkgconfig/${pc}.pc
  57. done
  58. ln -sv bash /bin/sh</userinput></screen>
  59. <!--sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
  60. sed 's/tools/usr/' /tools/lib/lib${lib}.la > /usr/lib/lib${lib}.la-->
  61. <variablelist>
  62. <title>每个链接的目的:</title>
  63. <varlistentry>
  64. <term><parameter><filename>/bin/bash</filename></parameter></term>
  65. <listitem>
  66. <para>许多 <command>bash</command> 脚本指定了
  67. <filename>/bin/bash</filename>。</para>
  68. </listitem>
  69. </varlistentry>
  70. <varlistentry>
  71. <term><parameter><filename>/bin/cat</filename></parameter></term>
  72. <listitem>
  73. <para>这个路径硬编码在 Glibc 配置脚本中。</para>
  74. </listitem>
  75. </varlistentry>
  76. <varlistentry>
  77. <term><parameter><filename>/bin/dd</filename></parameter></term>
  78. <listitem>
  79. <para>指向 <filename>dd</filename> 的路径会被硬编码在
  80. <filename>/usr/bin/libtool</filename> 工具中。</para>
  81. </listitem>
  82. </varlistentry>
  83. <varlistentry>
  84. <term><parameter><filename>/bin/echo</filename></parameter></term>
  85. <listitem>
  86. <!--para>This is to satisfy one of the tests in Glibc's test suite, which
  87. expects <filename>/bin/echo</filename>.</para-->
  88. <para>这是为了满足 Glibc 测试套件中的一项测试,它需要
  89. <filename>/bin/echo</filename>。</para>
  90. </listitem>
  91. </varlistentry>
  92. <varlistentry>
  93. <term><parameter><filename>/usr/bin/install</filename></parameter></term>
  94. <listitem>
  95. <!--para>The path to <filename>install</filename> will be hard-coded into
  96. the <filename>/usr/lib/bash/Makefile.inc</filename> file.</para-->
  97. <para>指向 <filename>install</filename> 的路径会被硬编码到
  98. <filename>/usr/lib/bash/Makefile.inc</filename> 文件中。</para>
  99. </listitem>
  100. </varlistentry>
  101. <varlistentry>
  102. <term><parameter><filename>/bin/ln</filename></parameter></term>
  103. <listitem>
  104. <!--para>The path to <filename>ln</filename> will be hard-coded into the
  105. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  106. file.</para-->
  107. <para>指向 <filename>ln</filename> 的路径会被硬编码到
  108. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  109. 文件中。</para>
  110. </listitem>
  111. </varlistentry>
  112. <varlistentry>
  113. <term><parameter><filename>/bin/pwd</filename></parameter></term>
  114. <listitem>
  115. <para>某些 <command>configure</command> 脚本,特别是 Glibc 的,
  116. 硬编码了这个路径。</para>
  117. </listitem>
  118. </varlistentry>
  119. <varlistentry>
  120. <term><parameter><filename>/bin/rm</filename></parameter></term>
  121. <listitem>
  122. <para>指向 <filename>rm</filename> 的路径会被硬编码到
  123. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  124. 文件中。</para>
  125. <!--para>The path to <filename>rm</filename> will be hard-coded into the
  126. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  127. file.</para-->
  128. </listitem>
  129. </varlistentry>
  130. <varlistentry>
  131. <term><parameter><filename>/bin/stty</filename></parameter></term>
  132. <listitem>
  133. <!--para>This pathname is hard-coded into Expect, therefore it is needed
  134. for Binutils and GCC test suites to pass.</para-->
  135. <para>这个路径被硬编码到 Expect 中,创建该链接才能使得
  136. Binutils 和 GCC 通过测试套件测试。</para>
  137. </listitem>
  138. </varlistentry>
  139. <varlistentry>
  140. <term><parameter><filename>/usr/bin/perl</filename></parameter></term>
  141. <listitem>
  142. <para>许多 Perl 脚本硬编码
  143. <command>perl</command> 程序的路径。</para>
  144. </listitem>
  145. </varlistentry>
  146. <varlistentry>
  147. <term><parameter><filename>/usr/lib/libgcc_s.so{,.1}</filename></parameter></term>
  148. <listitem>
  149. <para>Glibc 需要它才能让 pthread 库正常工作。</para>
  150. </listitem>
  151. </varlistentry>
  152. <varlistentry>
  153. <term><parameter><filename>/usr/lib/libstdc++{,.6}</filename></parameter></term>
  154. <listitem>
  155. <para>Glibc 测试套件中的若干项测试需要它, 另外构建 GMP 的 C++
  156. 支持也需要它。</para>
  157. </listitem>
  158. </varlistentry>
  159. <!--
  160. <varlistentry>
  161. <term><parameter><filename>/usr/lib/libstdc++.la</filename></parameter></term>
  162. <listitem>
  163. <para>This prevents a <filename class="directory">/tools</filename>
  164. reference that would otherwise be in
  165. <filename>/usr/lib/libstdc++.la</filename> after GCC is installed.</para>
  166. </listitem>
  167. </varlistentry>
  168. -->
  169. <varlistentry revision="systemd">
  170. <term><parameter><filename>/usr/lib/lib{blkid,lzma,mount,uuid}.{a,la,so*}</filename></parameter></term>
  171. <listitem>
  172. <!--para>These links prevent systemd utilities from acquiring an
  173. unnecessary reference to the
  174. <filename class="directory">/tools</filename> directory.</para-->
  175. <para>这些链接防止 systemd 工具获得指向
  176. <filename class="directory">/tools</filename>
  177. 目录的不必要的引用。</para>
  178. </listitem>
  179. </varlistentry>
  180. <varlistentry>
  181. <term><parameter><filename>/bin/sh</filename></parameter></term>
  182. <listitem>
  183. <para>许多 shell 脚本硬编码路径
  184. <filename>/bin/sh</filename>。</para>
  185. </listitem>
  186. </varlistentry>
  187. </variablelist>
  188. <!--para>Historically, Linux maintains a list of the mounted file systems in the
  189. file <filename>/etc/mtab</filename>. Modern kernels maintain this list
  190. internally and exposes it to the user via the <filename
  191. class="directory">/proc</filename> filesystem. To satisfy utilities that
  192. expect the presence of <filename>/etc/mtab</filename>, create the following
  193. symbolic link:</para-->
  194. <para>历史上,Linux 在 <filename>/etc/mtab</filename>
  195. 维护已经挂载的文件系统的列表。现代内核在内部维护该列表,并通过
  196. <filename class="directory">/proc</filename> 文件系统将它展示给用户。
  197. 为了满足那些需要 <filename>/etc/mtab</filename> 的工具,
  198. 执行下列命令,创建符号链接:</para>
  199. <screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
  200. <!--para>In order for user <systemitem class="username">root</systemitem> to be
  201. able to login and for the name <quote>root</quote> to be recognized, there
  202. must be relevant entries in the <filename>/etc/passwd</filename> and
  203. <filename>/etc/group</filename> files.</para>
  204. <para>Create the <filename>/etc/passwd</filename> file by running the following
  205. command:</para-->
  206. <para>为了使得 <systemitem class="username">root</systemitem>
  207. 能正常登录,而且它的用户名能被正常识别,必须在文件
  208. <filename>/etc/passwd</filename> 和 <filename>/etc/groups</filename>
  209. 中写入相关的条目。</para>
  210. <para>执行下列命令创建 <filename>/etc/passwd</filename> 文件:</para>
  211. <screen revision="sysv"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  212. <literal>root:x:0:0:root:/root:/bin/bash
  213. bin:x:1:1:bin:/dev/null:/bin/false
  214. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  215. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  216. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  217. EOF</userinput></screen>
  218. <screen revision="systemd"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  219. <literal>root:x:0:0:root:/root:/bin/bash
  220. bin:x:1:1:bin:/dev/null:/bin/false
  221. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  222. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  223. systemd-bus-proxy:x:72:72:systemd Bus Proxy:/:/bin/false
  224. systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/bin/false
  225. systemd-journal-remote:x:74:74:systemd Journal Remote:/:/bin/false
  226. systemd-journal-upload:x:75:75:systemd Journal Upload:/:/bin/false
  227. systemd-network:x:76:76:systemd Network Management:/:/bin/false
  228. systemd-resolve:x:77:77:systemd Resolver:/:/bin/false
  229. systemd-timesync:x:78:78:systemd Time Synchronization:/:/bin/false
  230. systemd-coredump:x:79:79:systemd Core Dumper:/:/bin/false
  231. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  232. EOF</userinput></screen>
  233. <!--para>The actual password for <systemitem class="username">root</systemitem>
  234. (the <quote>x</quote> used here is just a placeholder) will be set later.</para-->
  235. <para>我们以后再设置 <systemitem class="username">root</systemitem>
  236. 用户的实际密码(这里的 <quote>x</quote> 只是一个占位符)。</para>
  237. <!--para>Create the <filename>/etc/group</filename> file by running the following
  238. command:</para-->
  239. <para>执行下列命令,创建 <filename>/etc/group</filename> 文件:</para>
  240. <screen revision="sysv"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  241. <literal>root:x:0:
  242. bin:x:1:daemon
  243. sys:x:2:
  244. kmem:x:3:
  245. tape:x:4:
  246. tty:x:5:
  247. daemon:x:6:
  248. floppy:x:7:
  249. disk:x:8:
  250. lp:x:9:
  251. dialout:x:10:
  252. audio:x:11:
  253. video:x:12:
  254. utmp:x:13:
  255. usb:x:14:
  256. cdrom:x:15:
  257. adm:x:16:
  258. messagebus:x:18:
  259. systemd-journal:x:23:
  260. input:x:24:
  261. mail:x:34:
  262. nogroup:x:99:
  263. users:x:999:</literal>
  264. EOF</userinput></screen>
  265. <screen revision="systemd"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  266. <literal>root:x:0:
  267. bin:x:1:daemon
  268. sys:x:2:
  269. kmem:x:3:
  270. tape:x:4:
  271. tty:x:5:
  272. daemon:x:6:
  273. floppy:x:7:
  274. disk:x:8:
  275. lp:x:9:
  276. dialout:x:10:
  277. audio:x:11:
  278. video:x:12:
  279. utmp:x:13:
  280. usb:x:14:
  281. cdrom:x:15:
  282. adm:x:16:
  283. messagebus:x:18:
  284. systemd-journal:x:23:
  285. input:x:24:
  286. mail:x:34:
  287. kvm:x:61:
  288. systemd-bus-proxy:x:72:
  289. systemd-journal-gateway:x:73:
  290. systemd-journal-remote:x:74:
  291. systemd-journal-upload:x:75:
  292. systemd-network:x:76:
  293. systemd-resolve:x:77:
  294. systemd-timesync:x:78:
  295. systemd-coredump:x:79:
  296. nogroup:x:99:
  297. users:x:999:</literal>
  298. EOF</userinput></screen>
  299. <!--para>The created groups are not part of any standard&mdash;they are groups
  300. decided on in part by the requirements of the Udev configuration in this
  301. chapter, and in part by common convention employed by a number of existing
  302. Linux distributions. In addition, some test suites rely on specific users
  303. or groups. The Linux Standard Base (LSB, available at <ulink
  304. url="http://www.linuxbase.org"/>) recommends only that, besides the group
  305. <systemitem class="groupname">root</systemitem> with a Group ID (GID) of 0,
  306. a group <systemitem class="groupname">bin</systemitem> with a GID of 1 be
  307. present. All other group names and GIDs can be chosen freely by the system
  308. administrator since well-written programs do not depend on GID numbers, but
  309. rather use the group's name.</para-->
  310. <para>这里创建的用户组并不属于任何标准 —— 它们一部分是为了满足本章中
  311. Udev 配置的需要,另一部分借鉴了一些 Linux 发行版的通用惯例。
  312. 另外,某些测试套件需要特定的用户或组。Linux Standard Base
  313. (LSB,可以在 <ulink url="http://www.linuxbase.org"/> 查看)
  314. 标准只推荐以组 ID 0 创建用户组
  315. <systemitem class="groupname">root</systemitem>,
  316. 以及以组 ID 1 创建用户组
  317. <systemitem class="groupname">bin</systemitem>,
  318. 其他组名和组 ID 由系统管理员自由分配,因为好的程序不会依赖组 ID 数字,
  319. 而是使用组名。</para>
  320. <!--para>To remove the <quote>I have no name!</quote> prompt, start a new
  321. shell. Since a full Glibc was installed in <xref
  322. linkend="chapter-temporary-tools"/> and the
  323. <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
  324. files have been created, user name and group name resolution will now
  325. work:</para-->
  326. <para>为了移除 <quote>I have no name!</quote> 提示符,需要打开一个新
  327. shell。由于在 <xref linkend="chapter-temporary-tools"/>
  328. 中已经安装了一份完整的 Glibc,而且刚才创建了文件
  329. <filename>/etc/passwd</filename> 和 <filename>/etc/group</filename>,
  330. 用户名和组名现在就可以正常解析了。</para>
  331. <screen role="nodump"><userinput>exec /tools/bin/bash --login +h</userinput></screen>
  332. <!--para>Note the use of the <parameter>+h</parameter> directive. This tells
  333. <command>bash</command> not to use its internal path hashing. Without this
  334. directive, <command>bash</command> would remember the paths to binaries it has
  335. executed. To ensure the use of the newly compiled binaries as soon as they are
  336. installed, the <parameter>+h</parameter> directive will be used for the duration
  337. of this chapter.</para-->
  338. <para>注意这里使用了 <parameter>+h</parameter> 参数,
  339. 它告诉 <command>bash</command> 不要使用内部的路径散列机制。
  340. 如果没有指定该参数,<command>bash</command> 会记忆它执行过程序的路径。
  341. 为了在安装新编译好的程序后马上使用它们,在本章中总是使用
  342. <parameter>+h</parameter>。</para>
  343. <!--para>The <command>login</command>, <command>agetty</command>, and
  344. <command>init</command> programs (and others) use a number of log
  345. files to record information such as who was logged into the system and
  346. when. However, these programs will not write to the log files if they
  347. do not already exist. Initialize the log files and give them
  348. proper permissions:</para-->
  349. <para><command>login</command>、<command>agetty</command> 和
  350. <command>init</command> 等程序使用一些日志文件,
  351. 以记录登录系统的用户和登录时间等信息。
  352. 然而,这些程序不会创建不存在的日志文件。初始化日志文件,
  353. 并为它们设置合适的权限:</para>
  354. <screen><userinput>touch /var/log/{btmp,lastlog,faillog,wtmp}
  355. chgrp -v utmp /var/log/lastlog
  356. chmod -v 664 /var/log/lastlog
  357. chmod -v 600 /var/log/btmp</userinput></screen>
  358. <!--para>The <filename>/var/log/wtmp</filename> file records all logins and
  359. logouts. The <filename>/var/log/lastlog</filename> file records when each
  360. user last logged in. The <filename>/var/log/faillog</filename> file records
  361. failed login attempts. The <filename>/var/log/btmp</filename> file records
  362. the bad login attempts.</para-->
  363. <para>文件 <filename>/var/log/wtmp</filename> 记录所有的登录和登出,
  364. 文件 <filename>/var/log/lastlog</filename>
  365. 记录每个用户最后登录的时间,文件 <filename>/var/log/faillog</filename>
  366. 记录所有失败的登录尝试,文件 <filename>/var/log/btmp</filename>
  367. 记录所有错误的登录尝试。</para>
  368. <note><!--para>The <filename>/run/utmp</filename> file records the users that
  369. are currently logged in. This file is created dynamically in the boot
  370. scripts.</para-->
  371. <para> 文件 <filename>/run/utmp</filename> 记录当前登录的用户,
  372. 它由启动脚本动态创建。</para>
  373. </note>
  374. </sect1>