source: final-preps/settingenviron.xml@ 0160455

Last change on this file since 0160455 was 6a8ff5c, checked in by Jim Gifford <clfs@…>, 19 years ago

r1017@server (orig r1015): chris | 2006-01-07 10:08:14 -0800
Modification to About Test Suites, and various minor fixes

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[bf8c11f]1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-final-preps-settingenviron">
9 <?dbhtml filename="settingenvironment.html"?>
10
11 <title>Setting Up the Environment</title>
12
[4a9cdca]13 <para os="a">Set up a good working environment by creating two new startup
[bf8c11f]14 files for the <command>bash</command> shell. While logged in as user
15 <systemitem class="username">lfs</systemitem>, issue the following
16 command to create a new <filename>.bash_profile</filename>:</para>
17
[4a9cdca]18<screen os="b"><userinput>cat &gt; ~/.bash_profile &lt;&lt; "EOF"
[bf8c11f]19<literal>exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash</literal>
20EOF</userinput></screen>
21
[4a9cdca]22 <para os="c">When logged on as user <systemitem class="username">lfs</systemitem>,
[bf8c11f]23 the initial shell is usually a <emphasis>login</emphasis> shell which
24 reads the <filename>/etc/profile</filename> of the host (probably
25 containing some settings and environment variables) and then
26 <filename>.bash_profile</filename>. The
27 <command>exec env -i.../bin/bash</command> command in the
28 <filename>.bash_profile</filename> file replaces the running shell with
29 a new one with a completely empty environment, except for the
30 <envar>HOME</envar>, <envar>TERM</envar>, and <envar>PS1</envar> variables.
31 This ensures that no unwanted and potentially hazardous environment
32 variables from the host system leak into the build environment. The
33 technique used here achieves the goal of ensuring a clean environment.</para>
34
[4a9cdca]35 <para os="d">The new instance of the shell is a <emphasis>non-login</emphasis>
[bf8c11f]36 shell, which does not read the <filename>/etc/profile</filename> or
37 <filename>.bash_profile</filename> files, but rather reads the
38 <filename>.bashrc</filename> file instead. Create the
39 <filename>.bashrc</filename> file now:</para>
40
[4a9cdca]41<screen os="e"><userinput>cat &gt; ~/.bashrc &lt;&lt; "EOF"
[bf8c11f]42<literal>set +h
43umask 022
44LFS=/mnt/lfs
45LC_ALL=POSIX
46PATH=/cross-tools/bin:/bin:/usr/bin
47export LFS LC_ALL PATH</literal>
48EOF</userinput></screen>
49
[e0c8829]50 <para os="f">The <command>set +h</command> command turns off
[bf8c11f]51 <command>bash</command>'s hash function. Hashing is ordinarily a useful
52 feature&mdash;<command>bash</command> uses a hash table to remember the
53 full path of executable files to avoid searching the <envar>PATH</envar>
54 time and again to find the same executable. However, the new tools should
55 be used as soon as they are installed. By switching off the hash function,
56 the shell will always search the <envar>PATH</envar> when a program is to
57 be run. As such, the shell will find the newly compiled tools in
[6a8ff5c]58 <filename class="directory">$LFS/cross-tools</filename> as soon as they are
[bf8c11f]59 available without remembering a previous version of the same program in a
60 different location.</para>
61
[4a9cdca]62 <para os="g">Setting the user file-creation mask (umask) to 022 ensures that
[bf8c11f]63 newly created files and directories are only writable by their owner,
64 but are readable and executable by anyone (assuming default modes are
65 used by the open(2) system call, new files will end up with permission
66 mode 644 and directories with mode 755).</para>
67
[e0c8829]68 <para os="h">The <envar>LFS</envar> variable should be set to the
[bf8c11f]69 chosen mount point.</para>
70
[e0c8829]71 <para os="i">TO BE REWRITTEN - The <envar>LC_ALL</envar> variable controls
[bf8c11f]72 the localization of
73 certain programs, making their messages follow the conventions of a
74 specified country. If the host system uses a version of Glibc older
75 than 2.2.4, having <envar>LC_ALL</envar> set to something other than
76 <quote>POSIX</quote> or <quote>C</quote> (during this chapter) may cause
77 issues if you exit the chroot environment and wish to return later.
78 Setting <envar>LC_ALL</envar> to <quote>POSIX</quote> or <quote>C</quote>
79 (the two are equivalent) ensures that everything will work as expected in
80 the chroot environment.</para>
81
[7c91007]82 <para os="j">By putting <filename class="directory">/cross-tools/bin</filename> ahead
[bf8c11f]83 of the standard <envar>PATH</envar>, all the programs installed in
[56d9c50]84 <xref linkend="chapter-cross-tools"/> are picked up by the cross-compiler
[bf8c11f]85 immediately after their installation. This, combined with turning off
86 hashing, limits the risk that old programs are used from the host when
[56d9c50]87 building a sane set of cross-compiler tools.</para>
[bf8c11f]88
[e0c8829]89 <para os="k">Finally, to have the environment fully prepared for building the
[bf8c11f]90 temporary tools, source the just-created user profile:</para>
91
[e0c8829]92<screen os="l"><userinput>source ~/.bash_profile</userinput></screen>
[bf8c11f]93
94</sect1>
Note: See TracBrowser for help on using the repository browser.