1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3CR2//EN" "http://www.docbook.org/xml/4.3CR2/docbookx.dtd">
3 <sect1 id="ch05-settingenviron">
4 <title>Setting up the environment</title>
5 <?dbhtml filename="settingenvironment.html"?>
7 <para>We're going to set up a good working environment by creating two new
8 startup files for the Bash shell. While logged in as user
9 <emphasis>lfs</emphasis>, issue the following commands to create a new
10 <filename>.bash_profile</filename>:</para>
12 <screen><userinput>cat > ~/.bash_profile << "EOF"</userinput>
13 exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
14 <userinput>EOF</userinput></screen>
17 <userinput>exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash</userinput>
18 command creates a new instance of Bash with a completely empty environment,
19 except for the HOME, TERM and PS1 variables. This is needed to ensure that no
20 unwanted and potentially hazardous environment variables from the host system
21 leak into our build environment. The technique used here is a little
22 non-standard but it achieves the goal of enforcing a clean environment. By way
23 of explanation, the initial shell is a <emphasis>login</emphasis> shell which
24 reads the <filename>.bash_profile</filename>. The new shell instance is a
25 <emphasis>non-login</emphasis> shell which reads the
26 <filename>.bashrc</filename> (created next).</para>
28 <para>Now create a new <filename>.bashrc</filename>:</para>
30 <screen><userinput>cat > ~/.bashrc << "EOF"</userinput>
35 PATH=/tools/bin:/bin:/usr/bin
36 export LFS LC_ALL PATH
37 <userinput>EOF</userinput></screen>
39 <para>The <userinput>set +h</userinput> command turns off
40 <userinput>bash</userinput>'s hash function. Normally hashing is a useful
41 feature: <userinput>bash</userinput> uses a hash table to remember the
42 full pathnames of executable files to avoid searching the PATH time and time
43 again to find the same executable. However, we'd like the new tools to be
44 used as soon as they are installed. By switching off the hash function, our
45 "interactive" commands (<userinput>make</userinput>,
46 <userinput>patch</userinput>, <userinput>sed</userinput>,
47 <userinput>cp</userinput> and so forth) will always use
48 the newest available version during the build process.</para>
50 <para>Setting the user file-creation mask to 022 ensures that newly created
51 files and directories are only writable for their owner, but readable and
52 executable for anyone.</para>
54 <para>The LFS variable should of course be set to the mount point you
57 <para>The LC_ALL variable controls the localization of certain programs,
58 making their messages follow the conventions of a specified country. If your
59 host system uses a version of Glibc older than 2.2.4,
60 having LC_ALL set to something other than "POSIX" or "C" during this chapter
61 may cause trouble if you exit the chroot environment and wish to return later.
62 By setting LC_ALL to "POSIX" (or "C", the two are equivalent) we ensure that
63 everything will work as expected in the chroot environment.</para>
65 <para>We prepend <filename>/tools/bin</filename> to the standard PATH so
66 that, as we move along through this chapter, the tools we build will get used
67 during the rest of the building process.</para>
69 <para>Finally, source the just-created profile so that we're all set to begin
70 building the temporary tools that will support us in later chapters.</para>
72 <screen><userinput>source ~/.bash_profile</userinput></screen>