7.4. Entering the Chroot Environment

#### Linux From Scratch - Version 11.3-rc1

### Chapter 7. Entering Chroot and Building Additional Temporary Tools

- Prev

  Preparing Virtual Kernel File Systems

- Next

  Creating Directories

- Up
- Home

# 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 and finish installing the temporary tools. This environment will also be used to install the final system. As user `root`, run the following command to enter the environment that is, at the moment, populated with nothing but 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 the variables in the chroot environment. After that, only the `HOME`, `TERM`, `PS1`, and `PATH` variables are set again. The `TERM=$TERM` construct sets the `TERM` variable inside chroot to the same value as outside chroot. This variable is needed so programs like vim and less can operate properly. If other variables are desired, such as `CFLAGS` or `CXXFLAGS`, this is a good place to set them.

From this point on, there is no need to use the `LFS` variable any more because all work will be restricted to the LFS file system; the chroot command runs the Bash shell with the root (`/`) directory set to `$LFS`.

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

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

### Note

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.1, “Mounting and Populating /dev” and Section 7.3.2, “Mounting Virtual Kernel File Systems” and enter chroot again before continuing with the installation.

- Prev

  Preparing Virtual Kernel File Systems

- Next

  Creating Directories

- Up
- Home