Creating the passwd, group and log files

In order for root to be able to login and for the name “root” to be recognized, there need to be relevant entries in the /etc/passwd and /etc/group files.

Create the /etc/passwd file by running the following command:

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

The actual password for root (the “x” here is just a placeholder) will be set later.

Create the /etc/group file by running the following command:

cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
EOF

The created groups aren't part of any standard -- they are some of the groups that the make_devices script in the next section uses. The LSB (Linux Standard Base) recommends only that, beside the group “root” with a GID of 0, a group “bin” with a GID of 1 be present. All other group names and GIDs can be chosen freely by the system administrator, since well-written packages don't depend on GID numbers but use the group's name.

To get rid of the “I have no name!” prompt, we will start a new shell. Since we installed a full Glibc in Chapter 5, and have just created the /etc/passwd and /etc/group files, user name and group name resolution will now work.

exec /tools/bin/bash --login +h

Note the use of the +h directive. This tells bash not to use its internal path hashing. Without this directive, bash would remember the paths to binaries it has executed. Since we want to use our newly compiled binaries as soon as they are installed, we turn off this function for the duration of this chapter.

The login, agetty and init programs (and some others) use a number of log files to record information such as who was logged into the system and when. These programs, however, won't write to the log files if they don't already exist. Initialize the log files and give them their proper permissions:

touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chmod 644 /var/run/utmp /var/log/{btmp,lastlog,wtmp}

The /var/run/utmp file records the users that are currently logged in. The /var/log/wtmp file records all logins and logouts. The /var/log/lastlog file records for each user when he or she last logged in. The /var/log/btmp file records the bad login attempts.