[7152faa] | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
[fcc02767] | 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">
|
---|
[02776dff] | 22 | <primary sortas="e-/run/utmp">/run/utmp</primary>
|
---|
[fcc02767] | 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 |
|
---|
[ebecd08] | 37 | <para>Historically, Linux maintained a list of the mounted file systems in the
|
---|
[fcc02767] | 38 | file <filename>/etc/mtab</filename>. Modern kernels maintain this list
|
---|
[51a5442f] | 39 | internally and expose it to the user via the <filename
|
---|
[fcc02767] | 40 | class="directory">/proc</filename> filesystem. To satisfy utilities that
|
---|
[ebecd08] | 41 | expect to find <filename>/etc/mtab</filename>, create the following
|
---|
[fcc02767] | 42 | symbolic link:</para>
|
---|
| 43 |
|
---|
| 44 | <screen><userinput>ln -sv /proc/self/mounts /etc/mtab</userinput></screen>
|
---|
| 45 |
|
---|
[6e18f2f] | 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 |
|
---|
[2013a74] | 50 | <screen><userinput>cat > /etc/hosts << EOF
|
---|
[2e9e5b4] | 51 | <literal>127.0.0.1 localhost $(hostname)
|
---|
| 52 | ::1 localhost</literal>
|
---|
[2013a74] | 53 | EOF</userinput></screen>
|
---|
[6e18f2f] | 54 |
|
---|
[fcc02767] | 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 > /etc/passwd << "EOF"
|
---|
[095286b] | 64 | <literal>root:x:0:0:root:/root:/bin/bash
|
---|
[1f201845] | 65 | bin:x:1:1:bin:/dev/null:/usr/bin/false
|
---|
| 66 | daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
|
---|
| 67 | messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
|
---|
| 68 | uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
|
---|
[813ab55] | 69 | nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false</literal>
|
---|
[fcc02767] | 70 | EOF</userinput></screen>
|
---|
| 71 |
|
---|
| 72 | <screen revision="systemd"><userinput>cat > /etc/passwd << "EOF"
|
---|
[095286b] | 73 | <literal>root:x:0:0:root:/root:/bin/bash
|
---|
[1f201845] | 74 | bin:x:1:1:bin:/dev/null:/usr/bin/false
|
---|
| 75 | daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
|
---|
| 76 | messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
|
---|
| 77 | systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/usr/bin/false
|
---|
| 78 | systemd-journal-remote:x:74:74:systemd Journal Remote:/:/usr/bin/false
|
---|
| 79 | systemd-journal-upload:x:75:75:systemd Journal Upload:/:/usr/bin/false
|
---|
| 80 | systemd-network:x:76:76:systemd Network Management:/:/usr/bin/false
|
---|
| 81 | systemd-resolve:x:77:77:systemd Resolver:/:/usr/bin/false
|
---|
| 82 | systemd-timesync:x:78:78:systemd Time Synchronization:/:/usr/bin/false
|
---|
| 83 | systemd-coredump:x:79:79:systemd Core Dumper:/:/usr/bin/false
|
---|
| 84 | uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
|
---|
| 85 | systemd-oom:x:81:81:systemd Out Of Memory Daemon:/:/usr/bin/false
|
---|
[813ab55] | 86 | nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false</literal>
|
---|
[fcc02767] | 87 | EOF</userinput></screen>
|
---|
| 88 |
|
---|
| 89 | <para>The actual password for <systemitem class="username">root</systemitem>
|
---|
[387a32af] | 90 | will be set later.</para>
|
---|
[fcc02767] | 91 |
|
---|
| 92 | <para>Create the <filename>/etc/group</filename> file by running the following
|
---|
| 93 | command:</para>
|
---|
| 94 |
|
---|
| 95 | <screen revision="sysv"><userinput>cat > /etc/group << "EOF"
|
---|
| 96 | <literal>root:x:0:
|
---|
| 97 | bin:x:1:daemon
|
---|
| 98 | sys:x:2:
|
---|
| 99 | kmem:x:3:
|
---|
| 100 | tape:x:4:
|
---|
| 101 | tty:x:5:
|
---|
| 102 | daemon:x:6:
|
---|
| 103 | floppy:x:7:
|
---|
| 104 | disk:x:8:
|
---|
| 105 | lp:x:9:
|
---|
| 106 | dialout:x:10:
|
---|
| 107 | audio:x:11:
|
---|
| 108 | video:x:12:
|
---|
| 109 | utmp:x:13:
|
---|
| 110 | cdrom:x:15:
|
---|
| 111 | adm:x:16:
|
---|
| 112 | messagebus:x:18:
|
---|
| 113 | input:x:24:
|
---|
| 114 | mail:x:34:
|
---|
| 115 | kvm:x:61:
|
---|
[742c6324] | 116 | uuidd:x:80:
|
---|
[fcc02767] | 117 | wheel:x:97:
|
---|
[8469f02] | 118 | users:x:999:
|
---|
| 119 | nogroup:x:65534:</literal>
|
---|
[fcc02767] | 120 | EOF</userinput></screen>
|
---|
| 121 |
|
---|
| 122 | <screen revision="systemd"><userinput>cat > /etc/group << "EOF"
|
---|
| 123 | <literal>root:x:0:
|
---|
| 124 | bin:x:1:daemon
|
---|
| 125 | sys:x:2:
|
---|
| 126 | kmem:x:3:
|
---|
| 127 | tape:x:4:
|
---|
| 128 | tty:x:5:
|
---|
| 129 | daemon:x:6:
|
---|
| 130 | floppy:x:7:
|
---|
| 131 | disk:x:8:
|
---|
| 132 | lp:x:9:
|
---|
| 133 | dialout:x:10:
|
---|
| 134 | audio:x:11:
|
---|
| 135 | video:x:12:
|
---|
| 136 | utmp:x:13:
|
---|
| 137 | cdrom:x:15:
|
---|
| 138 | adm:x:16:
|
---|
| 139 | messagebus:x:18:
|
---|
| 140 | systemd-journal:x:23:
|
---|
| 141 | input:x:24:
|
---|
| 142 | mail:x:34:
|
---|
| 143 | kvm:x:61:
|
---|
| 144 | systemd-journal-gateway:x:73:
|
---|
| 145 | systemd-journal-remote:x:74:
|
---|
| 146 | systemd-journal-upload:x:75:
|
---|
| 147 | systemd-network:x:76:
|
---|
| 148 | systemd-resolve:x:77:
|
---|
| 149 | systemd-timesync:x:78:
|
---|
| 150 | systemd-coredump:x:79:
|
---|
[742c6324] | 151 | uuidd:x:80:
|
---|
[8dd179b] | 152 | systemd-oom:x:81:
|
---|
[fcc02767] | 153 | wheel:x:97:
|
---|
[8469f02] | 154 | users:x:999:
|
---|
| 155 | nogroup:x:65534:</literal>
|
---|
[fcc02767] | 156 | EOF</userinput></screen>
|
---|
| 157 |
|
---|
| 158 | <para>The created groups are not part of any standard—they are groups
|
---|
[387a32af] | 159 | decided on in part by the requirements of the Udev configuration in Chapter
|
---|
[ebecd08] | 160 | 9, and in part by common conventions employed by a number of existing Linux
|
---|
[387a32af] | 161 | distributions. In addition, some test suites rely on specific users or
|
---|
| 162 | groups. The Linux Standard Base (LSB, available at <ulink
|
---|
[fb66c4c] | 163 | url="https://refspecs.linuxfoundation.org/lsb.shtml"/>) only recommends that,
|
---|
[387a32af] | 164 | besides the group <systemitem class="groupname">root</systemitem> with a
|
---|
| 165 | Group ID (GID) of 0, a group <systemitem class="groupname">bin</systemitem>
|
---|
[ebecd08] | 166 | with a GID of 1 be present. The GID of 5 is widely used for the
|
---|
[7c862ea] | 167 | <systemitem class="groupname">tty</systemitem> group, and the number 5 is
|
---|
| 168 | also used in <phrase revision="systemd">systemd</phrase>
|
---|
| 169 | <phrase revision="sysv"><filename>/etc/fstab</filename></phrase> for the
|
---|
| 170 | <systemitem class="filesystem">devpts</systemitem> filesystem.
|
---|
| 171 | All other group names and GIDs can be chosen freely by the system
|
---|
| 172 | administrator since well-written programs do not depend on GID numbers,
|
---|
| 173 | but rather use the group's name.</para>
|
---|
[fcc02767] | 174 |
|
---|
[14de455] | 175 | <para>The ID 65534 is used by the kernel for NFS and separate user
|
---|
[0414633] | 176 | namespaces for unmapped users and groups (those exist on the NFS server
|
---|
| 177 | or the parent user namespace, but <quote>do not exist</quote> on the local
|
---|
| 178 | machine or in the separate namespace). We assign
|
---|
[14de455] | 179 | <systemitem class="username">nobody</systemitem> and
|
---|
[ebecd08] | 180 | <systemitem class="groupname">nogroup</systemitem> to avoid an
|
---|
[14de455] | 181 | unnamed ID. But other distros may treat this ID differently, so any
|
---|
| 182 | portable program should not depend on this assignment.</para>
|
---|
| 183 |
|
---|
[5818041] | 184 | <para>Some packages need a locale.</para>
|
---|
| 185 |
|
---|
| 186 | <screen><userinput>localedef -i C -f UTF-8 C.UTF-8</userinput></screen>
|
---|
| 187 |
|
---|
[fcc02767] | 188 | <para>Some tests in <xref linkend="chapter-building-system"/> need a regular
|
---|
| 189 | user. We add this user here and delete this account at the end of that
|
---|
| 190 | chapter.</para>
|
---|
| 191 |
|
---|
[095286b] | 192 | <screen><userinput>echo "tester:x:101:101::/home/tester:/bin/bash" >> /etc/passwd
|
---|
[fcc02767] | 193 | echo "tester:x:101:" >> /etc/group
|
---|
| 194 | install -o tester -d /home/tester</userinput></screen>
|
---|
| 195 |
|
---|
| 196 | <para>To remove the <quote>I have no name!</quote> prompt, start a new
|
---|
| 197 | shell. Since the
|
---|
| 198 | <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
|
---|
| 199 | files have been created, user name and group name resolution will now
|
---|
| 200 | work:</para>
|
---|
| 201 |
|
---|
[490dc153] | 202 | <screen role="nodump"><userinput>exec /usr/bin/bash --login</userinput></screen>
|
---|
[fcc02767] | 203 |
|
---|
| 204 | <para>The <command>login</command>, <command>agetty</command>, and
|
---|
| 205 | <command>init</command> programs (and others) use a number of log
|
---|
| 206 | files to record information such as who was logged into the system and
|
---|
| 207 | when. However, these programs will not write to the log files if they
|
---|
| 208 | do not already exist. Initialize the log files and give them
|
---|
| 209 | proper permissions:</para>
|
---|
| 210 |
|
---|
| 211 | <screen><userinput>touch /var/log/{btmp,lastlog,faillog,wtmp}
|
---|
| 212 | chgrp -v utmp /var/log/lastlog
|
---|
| 213 | chmod -v 664 /var/log/lastlog
|
---|
| 214 | chmod -v 600 /var/log/btmp</userinput></screen>
|
---|
| 215 |
|
---|
| 216 | <para>The <filename>/var/log/wtmp</filename> file records all logins and
|
---|
| 217 | logouts. The <filename>/var/log/lastlog</filename> file records when each
|
---|
| 218 | user last logged in. The <filename>/var/log/faillog</filename> file records
|
---|
| 219 | failed login attempts. The <filename>/var/log/btmp</filename> file records
|
---|
| 220 | the bad login attempts.</para>
|
---|
| 221 |
|
---|
[6e11fe2] | 222 | <!-- systemd no longer creates this -->
|
---|
| 223 | <note revision='sysv'><para>The <filename>/run/utmp</filename> file
|
---|
| 224 | records the users that are currently logged in. This file is created
|
---|
| 225 | dynamically in the boot scripts.</para></note>
|
---|
| 226 |
|
---|
| 227 | <!-- AFAIK they are not vital for system function, users requiring such
|
---|
| 228 | info should rely on systemd-logind or elogind or some custom PAM
|
---|
| 229 | module. Maybe we can stop to create them at all. -->
|
---|
| 230 | <note>
|
---|
| 231 | <para>
|
---|
| 232 | The <phrase revision='sysv'><filename>utmp</filename>,
|
---|
| 233 | </phrase><filename>wtmp</filename>, <filename>btmp</filename>, and
|
---|
[25b3c0f] | 234 | <filename>lastlog</filename> files use 32-bit integers for timestamps
|
---|
[6e11fe2] | 235 | and they'll be fundamentally broken after year 2038. Many packages
|
---|
| 236 | have stopped using them and other packages are going to stop using
|
---|
[0d8322d] | 237 | them. It is probably best to consider them deprecated.
|
---|
[6e11fe2] | 238 | </para>
|
---|
| 239 | </note>
|
---|
[fcc02767] | 240 |
|
---|
| 241 | </sect1>
|
---|