createfiles.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. In
  29. order to satisfy these programs, create a number of symbolic links which will be
  30. replaced by real files throughout the course of this chapter after the software
  31. has been installed:</para>
  32. <screen><userinput>ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
  33. ln -sv /tools/bin/perl /usr/bin
  34. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  35. ln -sv /tools/lib/libstdc++.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. <para>Historically, Linux maintains a list of the mounted file systems in the
  39. file <filename>/etc/mtab</filename>. Modern kernels maintain this list
  40. internally and exposes it to the user via the <filename
  41. class="directory">/proc</filename> filesystem. To satisfy utilities that
  42. expect the presence of <filename>/etc/mtab</filename>, create the following
  43. symbolic link:</para>
  44. <screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
  45. <para>In order for user <systemitem class="username">root</systemitem> to be
  46. able to login and for the name <quote>root</quote> to be recognized, there
  47. must be relevant entries in the <filename>/etc/passwd</filename> and
  48. <filename>/etc/group</filename> files.</para>
  49. <para>Create the <filename>/etc/passwd</filename> file by running the following
  50. command:</para>
  51. <screen><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
  52. <literal>root:x:0:0:root:/root:/bin/bash
  53. bin:x:1:1:bin:/dev/null:/bin/false
  54. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false</literal>
  55. EOF</userinput></screen>
  56. <para>The actual password for <systemitem class="username">root</systemitem>
  57. (the <quote>x</quote> used here is just a placeholder) will be set later.</para>
  58. <para>Create the <filename>/etc/group</filename> file by running the following
  59. command:</para>
  60. <screen><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
  61. <literal>root:x:0:
  62. bin:x:1:
  63. sys:x:2:
  64. kmem:x:3:
  65. tape:x:4:
  66. tty:x:5:
  67. daemon:x:6:
  68. floppy:x:7:
  69. disk:x:8:
  70. lp:x:9:
  71. dialout:x:10:
  72. audio:x:11:
  73. video:x:12:
  74. utmp:x:13:
  75. usb:x:14:
  76. cdrom:x:15:
  77. mail:x:34:
  78. nogroup:x:99:</literal>
  79. EOF</userinput></screen>
  80. <para>The created groups are not part of any standard&mdash;they are groups
  81. decided on in part by the requirements of the Udev configuration in this
  82. chapter, and in part by common convention employed by a number of existing
  83. Linux distributions. The Linux Standard Base (LSB, available at <ulink
  84. url="http://www.linuxbase.org"/>) recommends only that, besides the group
  85. <systemitem class="groupname">root</systemitem> with a Group ID (GID) of 0,
  86. a group <systemitem class="groupname">bin</systemitem> with a GID of 1 be
  87. present. All other group names and GIDs can be chosen freely by the system
  88. administrator since well-written programs do not depend on GID numbers, but
  89. rather use the group's name.</para>
  90. <para>To remove the <quote>I have no name!</quote> prompt, start a new
  91. shell. Since a full Glibc was installed in <xref
  92. linkend="chapter-temporary-tools"/> and the
  93. <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
  94. files have been created, user name and group name resolution will now
  95. work:</para>
  96. <screen role="nodump"><userinput>exec /tools/bin/bash --login +h</userinput></screen>
  97. <para>Note the use of the <parameter>+h</parameter> directive. This tells
  98. <command>bash</command> not to use its internal path hashing. Without this
  99. directive, <command>bash</command> would remember the paths to binaries it has
  100. executed. To ensure the use of the newly compiled binaries as soon as they are
  101. installed, the <parameter>+h</parameter> directive will be used for the duration
  102. of this chapter.</para>
  103. <para>The <command>login</command>, <command>agetty</command>, and
  104. <command>init</command> programs (and others) use a number of log
  105. files to record information such as who was logged into the system and
  106. when. However, these programs will not write to the log files if they
  107. do not already exist. Initialize the log files and give them
  108. proper permissions:</para>
  109. <screen><userinput>touch /var/log/{btmp,lastlog,wtmp}
  110. chgrp -v utmp /var/log/lastlog
  111. chmod -v 664 /var/log/lastlog
  112. chmod -v 600 /var/log/btmp</userinput></screen>
  113. <para>The <filename>/var/log/wtmp</filename> file records all logins and
  114. logouts. The <filename>/var/log/lastlog</filename> file records when each
  115. user last logged in. The <filename>/var/log/btmp</filename> file records the
  116. bad login attempts.</para>
  117. <note><para>The <filename>/run/utmp</filename> file records the users that
  118. are currently logged in. This file is created dynamically in the boot
  119. scripts.</para></note>
  120. </sect1>