createfiles.xml 7.6 KB

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