7.4. Entering the Chroot Environment

Now that all the packages which are required to build the rest of the needed tools are on the system, it is time to enter the chroot environment to finish installing the remaining temporary tools. This environment will be in use also for installing the final system. As user root, run the following command to enter the environment that is, at the moment, populated with only the temporary tools:

chroot "$LFS" /usr/bin/env -i   \
    HOME=/root                  \
    TERM="$TERM"                \
    PS1='(lfs chroot) \u:\w\$ ' \
    PATH=/usr/bin:/usr/sbin     \
    /bin/bash --login

The -i option given to the env command will clear all variables of the chroot environment. After that, only the HOME, TERM, PS1, and PATH variables are set again. The TERM=$TERM construct will set the TERM variable inside chroot to the same value as outside chroot. This variable is needed for programs like vim and less to operate properly. If other variables are desired, such as CFLAGS or CXXFLAGS, this is a good place to set them again.

From this point on, there is no need to use the LFS variable anymore because all work will be restricted to the LFS file system. This is because the Bash shell is told that $LFS is now the root (/) directory.

Notice that /tools/bin is not in the PATH. This means that the cross toolchain will no longer be used in the chroot environment.

Note that the bash prompt will say I have no name! This is normal because the /etc/passwd file has not been created yet.



It is important that all the commands throughout the remainder of this chapter and the following chapters are run from within the chroot environment. If you leave this environment for any reason (rebooting for example), ensure that the virtual kernel filesystems are mounted as explained in Section 7.3.2, “Mounting and Populating /dev” and Section 7.3.3, “Mounting Virtual Kernel File Systems” and enter chroot again before continuing with the installation.