Linux From Scratch: Version 5.0-pre2
Prev | Chapter 6. Installing basic system software | Next

# Entering the chroot environment

It is time to enter the chroot environment in order to begin installing the packages we need. Before you can chroot, however, you need to become root, since only root can execute the `chroot` command.

Become root and run the following command to enter the chroot environment:

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

    set +h

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 you need other variables present, such as CFLAGS or CXXFLAGS, this is a good place to set them again.

Also note the use of the set +h directive. This tells bash to not use its internal path hashing. Without this directive, bash will remember paths to binaries. Since as we go thru chapter 6, we want to use our newly compiled binaries as soon as they are installed, we turn off this function.

From this point on there's no need to use the LFS variable anymore, because everything you do will be restricted to the LFS file system -- since what the shell thinks is `/` is actually the value of `$LFS`, which was passed to the chroot command.

You have to make sure all the commands in the rest of this chapter and in the following chapters are run from within the chroot environment. If you ever leave this environment for any reason (rebooting for example), you must remember to again enter chroot and mount the proc and devpts filesystems (discussed later) before continuing with the installations.

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

Prev | Home | Next
About debugging symbols | Up | Changing ownership