chroot.xml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <sect1 id="ch06-chroot">
  2. <title>Entering the chroot environment</title>
  3. <?dbhtml filename="chroot.html" dir="chapter06"?>
  4. <para>It is time to enter the chroot environment in order to begin installing
  5. the packages we need. Before you can chroot, however, you need to become
  6. <emphasis>root</emphasis>, since only <emphasis>root</emphasis>
  7. can execute the <userinput>chroot</userinput> command.</para>
  8. <para>Become <emphasis>root</emphasis> and run the following command
  9. to enter the chroot environment:</para>
  10. <para><screen><userinput>chroot $LFS /tools/bin/env -i \
  11. &nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
  12. &nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
  13. &nbsp;&nbsp;&nbsp;&nbsp;/tools/bin/bash --login</userinput></screen>
  14. </para>
  15. <para><screen><userinput>set +h</userinput></screen></para>
  16. <para>The <userinput>-i</userinput> option given to the
  17. <userinput>env</userinput> command will clear all variables of the chroot
  18. environment. After that, only the HOME, TERM, PS1 and PATH variables are
  19. set again. The TERM=$TERM construct will set the TERM variable inside chroot
  20. to the same value as outside chroot; this variable is needed for programs
  21. like vim and less to operate properly. If you need other variables present,
  22. such as CFLAGS or CXXFLAGS, this is a good place to set them again.</para>
  23. <para>Also note the use of the set +h directive. This tells bash to not use
  24. it's internal path hashing. Without this directive, bash will remember paths
  25. to binaries. Since as we go thru chapter 6, we want to use our newly compiled
  26. binaries as soon as they are installed, we turn off this function.</para>
  27. <para>From this point on there's no need to use the LFS variable anymore,
  28. because everything you do will be restricted to the LFS file system -- since
  29. what the shell thinks is <filename class="directory">/</filename> is actually
  30. the value of <filename class="directory">$LFS</filename>, which was passed to
  31. the chroot command.</para>
  32. <para>You have to make sure all the commands in the rest of this chapter and
  33. in the following chapters are run from within the chroot environment.
  34. If you ever leave this environment for any reason (rebooting for example),
  35. you must remember to again enter chroot and mount proc (discussed later)
  36. before continuing with the installations.</para>
  37. <para>Note that the bash prompt will say "I have no name!" This is
  38. normal, as the <filename>/etc/passwd</filename> file has not been
  39. created yet.</para>
  40. </sect1>