createfiles.xml 14 KB

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