createfiles.xml 7.3 KB

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