source: chapter04/settingenviron.xml@ a9fde34e

Last change on this file since a9fde34e was 6a0e6f3, checked in by Matthew Burgess <matthew@…>, 20 years ago
  • Remove the spurious <info> tags that I thought were necessary but evidently aren't

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/LFS-RNG/BOOK@4387 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 3.7 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE section [
3 <!ENTITY % general-entities SYSTEM "../general.ent">
4 %general-entities;
5]>
6<section xmlns="http://docbook.org/docbook-ng"
7 xml:id="ch-tools-settingenviron">
8<title>Setting up the environment</title>
9<?dbhtml filename="settingenvironment.html"?>
10
11<para>We're going to set up a good working environment by creating two new
12startup files for the <command>bash</command> shell. While logged in as
13user <emphasis>lfs</emphasis>, issue the following command to create a new
14<filename>.bash_profile</filename>:</para>
15
16<screen><userinput>cat &gt; ~/.bash_profile &lt;&lt; "EOF"
17exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
18EOF</userinput></screen>
19
20<para>Normally, when you log on as user <emphasis>lfs</emphasis>,
21the initial shell is a <emphasis>login</emphasis> shell which reads the
22<filename>/etc/profile</filename> of your host (probably containing some
23settings of environment variables) and then <filename>.bash_profile</filename>.
24The <command>exec env -i ... /bin/bash</command> command in the latter file
25replaces the running shell with a new one with a completely empty environment,
26except for the HOME, TERM and PS1 variables. This ensures that no unwanted and
27potentially hazardous environment variables from the host system leak into our
28build environment. The technique used here is a little strange, but it achieves
29the goal of enforcing a clean environment.</para>
30
31<para>The new instance of the shell is a <emphasis>non-login</emphasis> shell,
32which doesn't read the <filename>/etc/profile</filename> or
33<filename>.bash_profile</filename> files, but reads the
34<filename>.bashrc</filename> file instead. Create this latter file now:</para>
35
36<screen><userinput>cat &gt; ~/.bashrc &lt;&lt; "EOF"
37set +h
38umask 022
39LFS=/mnt/lfs
40LC_ALL=POSIX
41PATH=/tools/bin:/bin:/usr/bin
42export LFS LC_ALL PATH
43EOF</userinput></screen>
44
45<para>The <command>set +h</command> command turns off
46<command>bash</command>'s hash function. Normally hashing is a useful
47feature: <command>bash</command> uses a hash table to remember the
48full pathnames of executable files to avoid searching the PATH time and time
49again to find the same executable. However, we'd like the new tools to be
50used as soon as they are installed. By switching off the hash function, our
51<quote>interactive</quote> commands (<command>make</command>,
52<command>patch</command>, <command>sed</command>,
53<command>cp</command> and so forth) will always use
54the newest available version during the build process.</para>
55
56<para>Setting the user file-creation mask to 022 ensures that newly created
57files and directories are only writable for their owner, but readable and
58executable for anyone.</para>
59
60<para>The LFS variable should of course be set to the mount point you
61chose.</para>
62
63<para>The LC_ALL variable controls the localization of certain programs,
64making their messages follow the conventions of a specified country. If your
65host system uses a version of Glibc older than 2.2.4,
66having LC_ALL set to something other than <quote>POSIX</quote> or
67<quote>C</quote> during this chapter may cause trouble if you exit the chroot
68environment and wish to return later. By setting LC_ALL to <quote>POSIX</quote>
69(or <quote>C</quote>, the two are equivalent) we ensure that
70everything will work as expected in the chroot environment.</para>
71
72<para>We prepend <filename class="directory">/tools/bin</filename> to the standard PATH so
73that, as we move along through this chapter, the tools we build will get used
74during the rest of the building process.</para>
75
76<para>Finally, to have our environment fully prepared for building the
77temporary tools, source the just-created profile:</para>
78
79<screen><userinput>source ~/.bash_profile</userinput></screen>
80
81</section>
Note: See TracBrowser for help on using the repository browser.