Under normal circumstances, after the kernel's done loading and initializing various system components, it attempts to load a program called init
which will finalize the system boot process. The program found on most Linux systems is called Sysvinit and that's the program we're going to install on our LFS system.
Makefile
fileAfter applying the $(ROOT) parts to the last four lines, they should look like this:
@if [! -p $(ROOT)/dev/initctl ]; then \ echo "Creating $(ROOT)/dev/initctl" \ rm -f $(ROOT)/dev/initctl; \ mknod -m 600 $(ROOT)/dev/initctl p; fi
make LDFLAGS=-static
make install
In order for Sysvinit to work, we need to create it's configuration file. Create the $LFS/etc/inittab
file containing the following:
# Begin /etc/inittab id:2:initdefault: si::sysinit:/etc/init.d/rcS ~~:S:wait:/sbin/sulogin l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 z6:6:wait:/sbin/sulogin ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now 1:2345:respawn:/sbin/sulogin # End /etc/inittab
As you can see from the inittab file, when we boot the system, init will start the sulogin program and sulogin will ask you for root's password. This means we need to have at least a passwd file present on the LFS system. We'll use the passwd and group files from the current running Linux system. Since the passwords are encoded it's just easier to copy the already present file and use that, instead of retyping the encoded password. Mistakes are easily made and this way we can avoid extra hassle afterwards.
/etc/passwd
and /etc/group
files to $LFS/etc/
$LFS/etc/passwd
file and remove every line, exceptthe line for the user root$LFS/etc/group
file and remove every line, except the line for the group rootWhen sulogin asks you for the root password and you've entered the password, a shell needs to be started. Usually this is the bash shell. Since there are no libraries installed yet, we need to link bash statically, just like we did with sysvinit.
configure --enable-static-link
make
bash
to $LFS/bin
$LFS/bin/sh
to $LFS/bin/bash
After you've completed this section, we can test the system and see if we can logon to it. Please note that you will get errors regarding the init program not being able to start the rcS and rc scripts. We will install these scripts in a later stage.
Also note that you won't be able to shutdown the system with a program like shutdown. Although the program is present, it will give you the following error: "You don't exist. Go away." The meaning of this error is that the system isn't able to locate the password file. Although the shutdown program is statically linked against the libraries it needs, it still depends on the nss library (Name Server Switch) which is part of the GNU C Library, which also will be installed in a later stage. This NSS library passes on information where (in this case) the passwd file can be found.
For now you can reboot the system using the reboot -f
command. This will bypass shutting down the system using the shutdown program and reboot immediately. Since the file system is mounted read-only this will not harm our system in any way (though you might get a warning next time you try to mount the system that it wasn't unmounted cleanly the last time and that you should run e2fsck to make sure the file system is ok).