createfiles.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  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-tools-createfiles">
  8. <?dbhtml filename="createfiles.html"?>
  9. <title>Creating Essential Files and Symlinks</title>
  10. <indexterm zone="ch-tools-createfiles">
  11. <primary sortas="e-/etc/passwd">/etc/passwd</primary>
  12. </indexterm>
  13. <indexterm zone="ch-tools-createfiles">
  14. <primary sortas="e-/etc/group">/etc/group</primary>
  15. </indexterm>
  16. <indexterm zone="ch-tools-createfiles">
  17. <primary sortas="e-/var/run/utmp">/var/run/utmp</primary>
  18. </indexterm>
  19. <indexterm zone="ch-tools-createfiles">
  20. <primary sortas="e-/var/log/btmp">/var/log/btmp</primary>
  21. </indexterm>
  22. <indexterm zone="ch-tools-createfiles">
  23. <primary sortas="e-/var/log/lastlog">/var/log/lastlog</primary>
  24. </indexterm>
  25. <indexterm zone="ch-tools-createfiles">
  26. <primary sortas="e-/var/log/wtmp">/var/log/wtmp</primary>
  27. </indexterm>
  28. <para>Historically, Linux maintains a list of the mounted file systems in the
  29. file <filename>/etc/mtab</filename>. Modern kernels maintain this list
  30. internally and exposes it to the user via the <filename
  31. class="directory">/proc</filename> filesystem. To satisfy utilities that
  32. expect the presence of <filename>/etc/mtab</filename>, create the following
  33. symbolic link:</para>
  34. <screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
  35. <para>Create a basic <filename>/etc/hosts</filename> file to be
  36. referenced in some test suites, and in one of Perl's configuration files
  37. as well:</para>
  38. <screen><userinput>echo "127.0.0.1 localhost $(hostname)" &gt; /etc/hosts</userinput></screen>
  39. <para>In order for user <systemitem class="username">root</systemitem> to be
  40. able to login and for the name <quote>root</quote> to be recognized, there
  41. must be relevant entries in the <filename>/etc/passwd</filename> and
  42. <filename>/etc/group</filename> files.</para>
  43. <para>Create the <filename>/etc/passwd</filename> file by running the following
  44. command:</para>
  45. <screen revision="sysv"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  46. <literal>root:x:0:0:root:/root:/bin/bash
  47. bin:x:1:1:bin:/dev/null:/bin/false
  48. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  49. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  50. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  51. EOF</userinput></screen>
  52. <screen revision="systemd"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  53. <literal>root:x:0:0:root:/root:/bin/bash
  54. bin:x:1:1:bin:/dev/null:/bin/false
  55. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  56. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  57. systemd-bus-proxy:x:72:72:systemd Bus Proxy:/:/bin/false
  58. systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/bin/false
  59. systemd-journal-remote:x:74:74:systemd Journal Remote:/:/bin/false
  60. systemd-journal-upload:x:75:75:systemd Journal Upload:/:/bin/false
  61. systemd-network:x:76:76:systemd Network Management:/:/bin/false
  62. systemd-resolve:x:77:77:systemd Resolver:/:/bin/false
  63. systemd-timesync:x:78:78:systemd Time Synchronization:/:/bin/false
  64. systemd-coredump:x:79:79:systemd Core Dumper:/:/bin/false
  65. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  66. EOF</userinput></screen>
  67. <para>The actual password for <systemitem class="username">root</systemitem>
  68. will be set later.</para>
  69. <para>Create the <filename>/etc/group</filename> file by running the following
  70. command:</para>
  71. <screen revision="sysv"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  72. <literal>root:x:0:
  73. bin:x:1:daemon
  74. sys:x:2:
  75. kmem:x:3:
  76. tape:x:4:
  77. tty:x:5:
  78. daemon:x:6:
  79. floppy:x:7:
  80. disk:x:8:
  81. lp:x:9:
  82. dialout:x:10:
  83. audio:x:11:
  84. video:x:12:
  85. utmp:x:13:
  86. usb:x:14:
  87. cdrom:x:15:
  88. adm:x:16:
  89. messagebus:x:18:
  90. input:x:24:
  91. mail:x:34:
  92. kvm:x:61:
  93. wheel:x:97:
  94. nogroup:x:99:
  95. users:x:999:</literal>
  96. EOF</userinput></screen>
  97. <screen revision="systemd"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  98. <literal>root:x:0:
  99. bin:x:1:daemon
  100. sys:x:2:
  101. kmem:x:3:
  102. tape:x:4:
  103. tty:x:5:
  104. daemon:x:6:
  105. floppy:x:7:
  106. disk:x:8:
  107. lp:x:9:
  108. dialout:x:10:
  109. audio:x:11:
  110. video:x:12:
  111. utmp:x:13:
  112. usb:x:14:
  113. cdrom:x:15:
  114. adm:x:16:
  115. messagebus:x:18:
  116. systemd-journal:x:23:
  117. input:x:24:
  118. mail:x:34:
  119. kvm:x:61:
  120. systemd-bus-proxy:x:72:
  121. systemd-journal-gateway:x:73:
  122. systemd-journal-remote:x:74:
  123. systemd-journal-upload:x:75:
  124. systemd-network:x:76:
  125. systemd-resolve:x:77:
  126. systemd-timesync:x:78:
  127. systemd-coredump:x:79:
  128. wheel:x:97:
  129. nogroup:x:99:
  130. users:x:999:</literal>
  131. EOF</userinput></screen>
  132. <para>The created groups are not part of any standard&mdash;they are groups
  133. decided on in part by the requirements of the Udev configuration in Chapter
  134. 9, and in part by common convention employed by a number of existing Linux
  135. distributions. In addition, some test suites rely on specific users or
  136. groups. The Linux Standard Base (LSB, available at <ulink
  137. url="http://refspecs.linuxfoundation.org/lsb.shtml"/>) only recommends that,
  138. besides the group <systemitem class="groupname">root</systemitem> with a
  139. Group ID (GID) of 0, a group <systemitem class="groupname">bin</systemitem>
  140. with a GID of 1 be present. All other group names and GIDs can be chosen
  141. freely by the system administrator since well-written programs do not depend
  142. on GID numbers, but rather use the group's name.</para>
  143. <para>Some tests in <xref linkend="chapter-building-system"/> need a regular
  144. user. We add this user here and delete this account at the end of that
  145. chapter.</para>
  146. <screen><userinput>echo "tester:x:$(ls -n $(tty) | cut -d" " -f3):101::/home/tester:/bin/bash" &gt;&gt; /etc/passwd
  147. echo "tester:x:101:" &gt;&gt; /etc/group
  148. install -o tester -d /home/tester</userinput></screen>
  149. <para>To remove the <quote>I have no name!</quote> prompt, start a new
  150. shell. Since the
  151. <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
  152. files have been created, user name and group name resolution will now
  153. work:</para>
  154. <screen role="nodump"><userinput>exec /bin/bash --login +h</userinput></screen>
  155. <para>Note the use of the <parameter>+h</parameter> directive. This tells
  156. <command>bash</command> not to use its internal path hashing. Without this
  157. directive, <command>bash</command> would remember the paths to binaries it has
  158. executed. To ensure the use of the newly compiled binaries as soon as they are
  159. installed, the <parameter>+h</parameter> directive will be used for the duration
  160. of this and the next chapter.</para>
  161. <para>The <command>login</command>, <command>agetty</command>, and
  162. <command>init</command> programs (and others) use a number of log
  163. files to record information such as who was logged into the system and
  164. when. However, these programs will not write to the log files if they
  165. do not already exist. Initialize the log files and give them
  166. proper permissions:</para>
  167. <screen><userinput>touch /var/log/{btmp,lastlog,faillog,wtmp}
  168. chgrp -v utmp /var/log/lastlog
  169. chmod -v 664 /var/log/lastlog
  170. chmod -v 600 /var/log/btmp</userinput></screen>
  171. <para>The <filename>/var/log/wtmp</filename> file records all logins and
  172. logouts. The <filename>/var/log/lastlog</filename> file records when each
  173. user last logged in. The <filename>/var/log/faillog</filename> file records
  174. failed login attempts. The <filename>/var/log/btmp</filename> file records
  175. the bad login attempts.</para>
  176. <note><para>The <filename>/run/utmp</filename> file records the users that
  177. are currently logged in. This file is created dynamically in the boot
  178. scripts.</para></note>
  179. </sect1>