createfiles.xml 14 KB

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