createfiles.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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-system-createfiles">
  8. <?dbhtml filename="createfiles.html"?>
  9. <title>Creating Essential Files and Symlinks</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. <screen revision="sysv"><userinput>ln -sv /tools/bin/{bash,cat,dd,echo,ln,pwd,rm,stty} /bin
  33. ln -sv /tools/bin/{install,perl} /usr/bin
  34. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  35. ln -sv /tools/lib/libstdc++.{a,so{,.6}} /usr/lib
  36. sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
  37. ln -sv bash /bin/sh</userinput></screen>
  38. <screen revision="systemd"><userinput>ln -sv /tools/bin/{bash,cat,dd,echo,ln,pwd,rm,stty} /bin
  39. ln -sv /tools/bin/{install,perl} /usr/bin
  40. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  41. ln -sv /tools/lib/libstdc++.{a,so{,.6}} /usr/lib
  42. sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
  43. for lib in blkid lzma mount uuid
  44. do
  45. ln -sv /tools/lib/lib$lib.{a,so*} /usr/lib
  46. sed 's/tools/usr/' /tools/lib/lib${lib}.la > /usr/lib/lib${lib}.la
  47. done
  48. ln -sv bash /bin/sh</userinput></screen>
  49. <variablelist>
  50. <title>The purpose of each link:</title>
  51. <varlistentry>
  52. <term><parameter><filename>/bin/bash</filename></parameter></term>
  53. <listitem>
  54. <para>Many <command>bash</command> scripts specify
  55. <filename>/bin/bash</filename>.</para>
  56. </listitem>
  57. </varlistentry>
  58. <varlistentry>
  59. <term><parameter><filename>/bin/cat</filename></parameter></term>
  60. <listitem>
  61. <para>This pathname is hard-coded into Glibc's configure script.</para>
  62. </listitem>
  63. </varlistentry>
  64. <varlistentry>
  65. <term><parameter><filename>/bin/dd</filename></parameter></term>
  66. <listitem>
  67. <para>The path to <filename>dd</filename> will be hard-coded into the
  68. <filename>/usr/bin/libtool</filename> utility.</para>
  69. </listitem>
  70. </varlistentry>
  71. <varlistentry>
  72. <term><parameter><filename>/bin/echo</filename></parameter></term>
  73. <listitem>
  74. <para>This is to satisfy one of the tests in Glibc's test suite, which
  75. expects <filename>/bin/echo</filename>.</para>
  76. </listitem>
  77. </varlistentry>
  78. <varlistentry>
  79. <term><parameter><filename>/usr/bin/install</filename></parameter></term>
  80. <listitem>
  81. <para>The path to <filename>install</filename> will be hard-coded into
  82. the <filename>/usr/lib/bash/Makefile.inc</filename> file.</para>
  83. </listitem>
  84. </varlistentry>
  85. <varlistentry>
  86. <term><parameter><filename>/bin/ln</filename></parameter></term>
  87. <listitem>
  88. <para>The path to <filename>ln</filename> will be hard-coded into the
  89. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  90. file.</para>
  91. </listitem>
  92. </varlistentry>
  93. <varlistentry>
  94. <term><parameter><filename>/bin/pwd</filename></parameter></term>
  95. <listitem>
  96. <para>Some <command>configure</command> scripts, particularly Glibc's,
  97. have this pathname hard-coded.</para>
  98. </listitem>
  99. </varlistentry>
  100. <varlistentry>
  101. <term><parameter><filename>/bin/rm</filename></parameter></term>
  102. <listitem>
  103. <para>The path to <filename>rm</filename> will be hard-coded into the
  104. <filename>/usr/lib/perl5/&perl-version;/&lt;target-triplet&gt;/Config_heavy.pl</filename>
  105. file.</para>
  106. </listitem>
  107. </varlistentry>
  108. <varlistentry>
  109. <term><parameter><filename>/bin/stty</filename></parameter></term>
  110. <listitem>
  111. <para>This pathname is hard-coded into Expect, therefore it is needed
  112. for Binutils and GCC test suites to pass.</para>
  113. </listitem>
  114. </varlistentry>
  115. <varlistentry>
  116. <term><parameter><filename>/usr/bin/perl</filename></parameter></term>
  117. <listitem>
  118. <para>Many Perl scripts hard-code this path to the
  119. <command>perl</command> program.</para>
  120. </listitem>
  121. </varlistentry>
  122. <varlistentry>
  123. <term><parameter><filename>/usr/lib/libgcc_s.so{,.1}</filename></parameter></term>
  124. <listitem>
  125. <para>Glibc needs this for the pthreads library to work.</para>
  126. </listitem>
  127. </varlistentry>
  128. <varlistentry>
  129. <term><parameter><filename>/usr/lib/libstdc++{,.6}</filename></parameter></term>
  130. <listitem>
  131. <para>This is needed by several tests in Glibc's test suite, as well as
  132. for C++ support in GMP.</para>
  133. </listitem>
  134. </varlistentry>
  135. <varlistentry>
  136. <term><parameter><filename>/usr/lib/libstdc++.la</filename></parameter></term>
  137. <listitem>
  138. <para>This prevents a <filename class="directory">/tools</filename>
  139. reference that would otherwise be in
  140. <filename>/usr/lib/libstdc++.la</filename> after GCC is installed.</para>
  141. </listitem>
  142. </varlistentry>
  143. <varlistentry revision="systemd">
  144. <term><parameter><filename>/usr/lib/lib{blkid,lzma,mount,uuid}.{a,la,so*}</filename></parameter></term>
  145. <listitem>
  146. <para>These links prevent systemd utilities from acquiring an
  147. unnecessary reference to the
  148. <filename class="directory">/tools</filename> directory.</para>
  149. </listitem>
  150. </varlistentry>
  151. <varlistentry>
  152. <term><parameter><filename>/bin/sh</filename></parameter></term>
  153. <listitem>
  154. <para>Many shell scripts hard-code <filename>/bin/sh</filename>.</para>
  155. </listitem>
  156. </varlistentry>
  157. </variablelist>
  158. <para>Historically, Linux maintains a list of the mounted file systems in the
  159. file <filename>/etc/mtab</filename>. Modern kernels maintain this list
  160. internally and exposes it to the user via the <filename
  161. class="directory">/proc</filename> filesystem. To satisfy utilities that
  162. expect the presence of <filename>/etc/mtab</filename>, create the following
  163. symbolic link:</para>
  164. <screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
  165. <para>In order for user <systemitem class="username">root</systemitem> to be
  166. able to login and for the name <quote>root</quote> to be recognized, there
  167. must be relevant entries in the <filename>/etc/passwd</filename> and
  168. <filename>/etc/group</filename> files.</para>
  169. <para>Create the <filename>/etc/passwd</filename> file by running the following
  170. command:</para>
  171. <screen revision="sysv"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  172. <literal>root:x:0:0:root:/root:/bin/bash
  173. bin:x:1:1:bin:/dev/null:/bin/false
  174. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  175. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  176. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  177. EOF</userinput></screen>
  178. <screen revision="systemd"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  179. <literal>root:x:0:0:root:/root:/bin/bash
  180. bin:x:1:1:bin:/dev/null:/bin/false
  181. daemon:x:6:6:Daemon User:/dev/null:/bin/false
  182. messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
  183. systemd-bus-proxy:x:72:72:systemd Bus Proxy:/:/bin/false
  184. systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/bin/false
  185. systemd-journal-remote:x:74:74:systemd Journal Remote:/:/bin/false
  186. systemd-journal-upload:x:75:75:systemd Journal Upload:/:/bin/false
  187. systemd-network:x:76:76:systemd Network Management:/:/bin/false
  188. systemd-resolve:x:77:77:systemd Resolver:/:/bin/false
  189. systemd-timesync:x:78:78:systemd Time Synchronization:/:/bin/false
  190. systemd-coredump:x:79:79:systemd Core Dumper:/:/bin/false
  191. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  192. EOF</userinput></screen>
  193. <para>The actual password for <systemitem class="username">root</systemitem>
  194. (the <quote>x</quote> used here is just a placeholder) will be set later.</para>
  195. <para>Create the <filename>/etc/group</filename> file by running the following
  196. command:</para>
  197. <screen revision="sysv"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  198. <literal>root:x:0:
  199. bin:x:1:daemon
  200. sys:x:2:
  201. kmem:x:3:
  202. tape:x:4:
  203. tty:x:5:
  204. daemon:x:6:
  205. floppy:x:7:
  206. disk:x:8:
  207. lp:x:9:
  208. dialout:x:10:
  209. audio:x:11:
  210. video:x:12:
  211. utmp:x:13:
  212. usb:x:14:
  213. cdrom:x:15:
  214. adm:x:16:
  215. messagebus:x:18:
  216. systemd-journal:x:23:
  217. input:x:24:
  218. mail:x:34:
  219. nogroup:x:99:
  220. users:x:999:</literal>
  221. EOF</userinput></screen>
  222. <screen revision="systemd"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  223. <literal>root:x:0:
  224. bin:x:1:daemon
  225. sys:x:2:
  226. kmem:x:3:
  227. tape:x:4:
  228. tty:x:5:
  229. daemon:x:6:
  230. floppy:x:7:
  231. disk:x:8:
  232. lp:x:9:
  233. dialout:x:10:
  234. audio:x:11:
  235. video:x:12:
  236. utmp:x:13:
  237. usb:x:14:
  238. cdrom:x:15:
  239. adm:x:16:
  240. messagebus:x:18:
  241. systemd-journal:x:23:
  242. input:x:24:
  243. mail:x:34:
  244. systemd-bus-proxy:x:72:
  245. systemd-journal-gateway:x:73:
  246. systemd-journal-remote:x:74:
  247. systemd-journal-upload:x:75:
  248. systemd-network:x:76:
  249. systemd-resolve:x:77:
  250. systemd-timesync:x:78:
  251. systemd-coredump:x:79:
  252. nogroup:x:99:
  253. users:x:999:</literal>
  254. EOF</userinput></screen>
  255. <para>The created groups are not part of any standard&mdash;they are groups
  256. decided on in part by the requirements of the Udev configuration in this
  257. chapter, and in part by common convention employed by a number of existing
  258. Linux distributions. In addition, some test suites rely on specific users
  259. or groups. The Linux Standard Base (LSB, available at <ulink
  260. url="http://www.linuxbase.org"/>) recommends only that, besides the group
  261. <systemitem class="groupname">root</systemitem> with a Group ID (GID) of 0,
  262. a group <systemitem class="groupname">bin</systemitem> with a GID of 1 be
  263. present. All other group names and GIDs can be chosen freely by the system
  264. administrator since well-written programs do not depend on GID numbers, but
  265. rather use the group's name.</para>
  266. <para>To remove the <quote>I have no name!</quote> prompt, start a new
  267. shell. Since a full Glibc was installed in <xref
  268. linkend="chapter-temporary-tools"/> and the
  269. <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
  270. files have been created, user name and group name resolution will now
  271. work:</para>
  272. <screen role="nodump"><userinput>exec /tools/bin/bash --login +h</userinput></screen>
  273. <para>Note the use of the <parameter>+h</parameter> directive. This tells
  274. <command>bash</command> not to use its internal path hashing. Without this
  275. directive, <command>bash</command> would remember the paths to binaries it has
  276. executed. To ensure the use of the newly compiled binaries as soon as they are
  277. installed, the <parameter>+h</parameter> directive will be used for the duration
  278. of this chapter.</para>
  279. <para>The <command>login</command>, <command>agetty</command>, and
  280. <command>init</command> programs (and others) use a number of log
  281. files to record information such as who was logged into the system and
  282. when. However, these programs will not write to the log files if they
  283. do not already exist. Initialize the log files and give them
  284. proper permissions:</para>
  285. <screen><userinput>touch /var/log/{btmp,lastlog,faillog,wtmp}
  286. chgrp -v utmp /var/log/lastlog
  287. chmod -v 664 /var/log/lastlog
  288. chmod -v 600 /var/log/btmp</userinput></screen>
  289. <para>The <filename>/var/log/wtmp</filename> file records all logins and
  290. logouts. The <filename>/var/log/lastlog</filename> file records when each
  291. user last logged in. The <filename>/var/log/faillog</filename> file records
  292. failed login attempts. The <filename>/var/log/btmp</filename> file records
  293. the bad login attempts.</para>
  294. <note><para>The <filename>/run/utmp</filename> file records the users that
  295. are currently logged in. This file is created dynamically in the boot
  296. scripts.</para></note>
  297. </sect1>