source: chapter07/createfiles.xml@ 490dc153

11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 490dc153 was 490dc153, checked in by Xi Ruoyao <xry111@…>, 2 years ago

remove "+h" in bash commands in chroot (#4998)

In the new cross-compilation approach, the $PATH in chroot does not
contain '/tools/bin'. So "+h" is useless in chroot as the newly
installed tools always replace the temporary counterpart at the same
location.

"+h" in chapter4/settingenviron.xml is kept deliberately. Currently
$LFS/tools/bin only contains programs prefixed with
"x86_64-lfs-linux-gnu-", and it's highly unlikely that any distro will
ever ship a program named with such prefix. So it may seems that we can
remove this "+h" as well. However, the situation may change in future
and we can take this oppertunity to teach the advantage and disvantage
of bash hash feature.

  • Property mode set to 100644
File size: 7.3 KB
Line 
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
8<sect1 id="ch-tools-createfiles">
9 <?dbhtml filename="createfiles.html"?>
10
11 <title>Creating Essential Files and Symlinks</title>
12
13 <indexterm zone="ch-tools-createfiles">
14 <primary sortas="e-/etc/passwd">/etc/passwd</primary>
15 </indexterm>
16
17 <indexterm zone="ch-tools-createfiles">
18 <primary sortas="e-/etc/group">/etc/group</primary>
19 </indexterm>
20
21 <indexterm zone="ch-tools-createfiles">
22 <primary sortas="e-/run/utmp">/run/utmp</primary>
23 </indexterm>
24
25 <indexterm zone="ch-tools-createfiles">
26 <primary sortas="e-/var/log/btmp">/var/log/btmp</primary>
27 </indexterm>
28
29 <indexterm zone="ch-tools-createfiles">
30 <primary sortas="e-/var/log/lastlog">/var/log/lastlog</primary>
31 </indexterm>
32
33 <indexterm zone="ch-tools-createfiles">
34 <primary sortas="e-/var/log/wtmp">/var/log/wtmp</primary>
35 </indexterm>
36
37 <para>Historically, Linux maintains a list of the mounted file systems in the
38 file <filename>/etc/mtab</filename>. Modern kernels maintain this list
39 internally and exposes it to the user via the <filename
40 class="directory">/proc</filename> filesystem. To satisfy utilities that
41 expect the presence of <filename>/etc/mtab</filename>, create the following
42 symbolic link:</para>
43
44<screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
45
46 <para>Create a basic <filename>/etc/hosts</filename> file to be
47 referenced in some test suites, and in one of Perl's configuration files
48 as well:</para>
49
50<screen><userinput>cat &gt; /etc/hosts &lt;&lt; EOF
51127.0.0.1 localhost $(hostname)
52::1 localhost
53EOF</userinput></screen>
54
55 <para>In order for user <systemitem class="username">root</systemitem> to be
56 able to login and for the name <quote>root</quote> to be recognized, there
57 must be relevant entries in the <filename>/etc/passwd</filename> and
58 <filename>/etc/group</filename> files.</para>
59
60 <para>Create the <filename>/etc/passwd</filename> file by running the following
61 command:</para>
62
63<screen revision="sysv"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
64<literal>root:x:0:0:root:/root:/bin/bash
65bin:x:1:1:bin:/dev/null:/usr/bin/false
66daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
67messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
68uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
69nobody:x:99:99:Unprivileged User:/dev/null:/usr/bin/false</literal>
70EOF</userinput></screen>
71
72<screen revision="systemd"><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"
73<literal>root:x:0:0:root:/root:/bin/bash
74bin:x:1:1:bin:/dev/null:/usr/bin/false
75daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
76messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
77systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/usr/bin/false
78systemd-journal-remote:x:74:74:systemd Journal Remote:/:/usr/bin/false
79systemd-journal-upload:x:75:75:systemd Journal Upload:/:/usr/bin/false
80systemd-network:x:76:76:systemd Network Management:/:/usr/bin/false
81systemd-resolve:x:77:77:systemd Resolver:/:/usr/bin/false
82systemd-timesync:x:78:78:systemd Time Synchronization:/:/usr/bin/false
83systemd-coredump:x:79:79:systemd Core Dumper:/:/usr/bin/false
84uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
85systemd-oom:x:81:81:systemd Out Of Memory Daemon:/:/usr/bin/false
86nobody:x:99:99:Unprivileged User:/dev/null:/usr/bin/false</literal>
87EOF</userinput></screen>
88
89 <para>The actual password for <systemitem class="username">root</systemitem>
90 will be set later.</para>
91
92 <para>Create the <filename>/etc/group</filename> file by running the following
93 command:</para>
94
95<screen revision="sysv"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
96<literal>root:x:0:
97bin:x:1:daemon
98sys:x:2:
99kmem:x:3:
100tape:x:4:
101tty:x:5:
102daemon:x:6:
103floppy:x:7:
104disk:x:8:
105lp:x:9:
106dialout:x:10:
107audio:x:11:
108video:x:12:
109utmp:x:13:
110usb:x:14:
111cdrom:x:15:
112adm:x:16:
113messagebus:x:18:
114input:x:24:
115mail:x:34:
116kvm:x:61:
117uuidd:x:80:
118wheel:x:97:
119nogroup:x:99:
120users:x:999:</literal>
121EOF</userinput></screen>
122
123<screen revision="systemd"><userinput>cat &gt; /etc/group &lt;&lt; "EOF"
124<literal>root:x:0:
125bin:x:1:daemon
126sys:x:2:
127kmem:x:3:
128tape:x:4:
129tty:x:5:
130daemon:x:6:
131floppy:x:7:
132disk:x:8:
133lp:x:9:
134dialout:x:10:
135audio:x:11:
136video:x:12:
137utmp:x:13:
138usb:x:14:
139cdrom:x:15:
140adm:x:16:
141messagebus:x:18:
142systemd-journal:x:23:
143input:x:24:
144mail:x:34:
145kvm:x:61:
146systemd-bus-proxy:x:72:
147systemd-journal-gateway:x:73:
148systemd-journal-remote:x:74:
149systemd-journal-upload:x:75:
150systemd-network:x:76:
151systemd-resolve:x:77:
152systemd-timesync:x:78:
153systemd-coredump:x:79:
154uuidd:x:80:
155systemd-oom:x:81:81:
156wheel:x:97:
157nogroup:x:99:
158users:x:999:</literal>
159EOF</userinput></screen>
160
161 <para>The created groups are not part of any standard&mdash;they are groups
162 decided on in part by the requirements of the Udev configuration in Chapter
163 9, and in part by common convention employed by a number of existing Linux
164 distributions. In addition, some test suites rely on specific users or
165 groups. The Linux Standard Base (LSB, available at <ulink
166 url="http://refspecs.linuxfoundation.org/lsb.shtml"/>) only recommends that,
167 besides the group <systemitem class="groupname">root</systemitem> with a
168 Group ID (GID) of 0, a group <systemitem class="groupname">bin</systemitem>
169 with a GID of 1 be present. All other group names and GIDs can be chosen
170 freely by the system administrator since well-written programs do not depend
171 on GID numbers, but rather use the group's name.</para>
172
173 <para>Some tests in <xref linkend="chapter-building-system"/> need a regular
174 user. We add this user here and delete this account at the end of that
175 chapter.</para>
176
177<screen><userinput>echo "tester:x:101:101::/home/tester:/bin/bash" &gt;&gt; /etc/passwd
178echo "tester:x:101:" &gt;&gt; /etc/group
179install -o tester -d /home/tester</userinput></screen>
180
181 <para>To remove the <quote>I have no name!</quote> prompt, start a new
182 shell. Since the
183 <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
184 files have been created, user name and group name resolution will now
185 work:</para>
186
187<screen role="nodump"><userinput>exec /usr/bin/bash --login</userinput></screen>
188
189 <para>The <command>login</command>, <command>agetty</command>, and
190 <command>init</command> programs (and others) use a number of log
191 files to record information such as who was logged into the system and
192 when. However, these programs will not write to the log files if they
193 do not already exist. Initialize the log files and give them
194 proper permissions:</para>
195
196<screen><userinput>touch /var/log/{btmp,lastlog,faillog,wtmp}
197chgrp -v utmp /var/log/lastlog
198chmod -v 664 /var/log/lastlog
199chmod -v 600 /var/log/btmp</userinput></screen>
200
201 <para>The <filename>/var/log/wtmp</filename> file records all logins and
202 logouts. The <filename>/var/log/lastlog</filename> file records when each
203 user last logged in. The <filename>/var/log/faillog</filename> file records
204 failed login attempts. The <filename>/var/log/btmp</filename> file records
205 the bad login attempts.</para>
206
207 <note><para>The <filename>/run/utmp</filename> file records the users that
208 are currently logged in. This file is created dynamically in the boot
209 scripts.</para></note>
210
211</sect1>
Note: See TracBrowser for help on using the repository browser.