Linux From Scratch: Version 5.1-pre1
Prev | Chapter 5. Constructing a temporary system | Next

# Setting up the environment

We're going to set up a good working environment by creating two new startup files for the bash shell. While logged in as user lfs, issue the following command to create a new `.bash_profile`:

    cat > ~/.bash_profile << "EOF"
    exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
    EOF

Normally, when you log on as user lfs, the initial shell is a login shell which reads the `/etc/profile` of your host (probably containing some settings of environment variables) and then `.bash_profile`. The exec env -i ... /bin/bash command in the latter file replaces the running shell with a new one with a completely empty environment, except for the HOME, TERM and PS1 variables. This ensures that no unwanted and potentially hazardous environment variables from the host system leak into our build environment. The technique used here is a little strange, but it achieves the goal of enforcing a clean environment.

The new instance of the shell is a non-login shell, which doesn't read the `/etc/profile` or `.bash_profile` files, but reads the `.bashrc` file instead. Create this latter file now:

    cat > ~/.bashrc << "EOF"
    set +h
    umask 022
    LFS=/mnt/lfs
    LC_ALL=POSIX
    PATH=/tools/bin:/bin:/usr/bin
    export LFS LC_ALL PATH
    EOF

The set +h command turns off bash's hash function. Normally hashing is a useful feature: bash uses a hash table to remember the full pathnames of executable files to avoid searching the PATH time and time again to find the same executable. However, we'd like the new tools to be used as soon as they are installed. By switching off the hash function, our "interactive" commands (make, patch, sed, cp and so forth) will always use the newest available version during the build process.

Setting the user file-creation mask to 022 ensures that newly created files and directories are only writable for their owner, but readable and executable for anyone.

The LFS variable should of course be set to the mount point you chose.

The LC_ALL variable controls the localization of certain programs, making their messages follow the conventions of a specified country. If your host system uses a version of Glibc older than 2.2.4, having LC_ALL set to something other than "POSIX" or "C" during this chapter may cause trouble if you exit the chroot environment and wish to return later. By setting LC_ALL to "POSIX" (or "C", the two are equivalent) we ensure that everything will work as expected in the chroot environment.

We prepend `/tools/bin` to the standard PATH so that, as we move along through this chapter, the tools we build will get used during the rest of the building process.

Finally, to have our environment fully prepared for building the temporary tools, source the just-created profile:

    source ~/.bash_profile

Prev | Home | Next
Adding the user lfs | Up | Installing Binutils-2.14 - Pass 1