chroot.xml 2.7 KB

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