settingenviron.xml 3.8 KB

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