chroot.xml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 /stage1/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:/stage1/bin \
  13. &nbsp;&nbsp;&nbsp;&nbsp;/stage1/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>From this point on there's no need to use the LFS variable anymore,
  24. because everything you do will be restricted to the LFS file system -- since
  25. what the shell thinks is <filename class="directory">/</filename> is actually
  26. the value of <filename class="directory">$LFS</filename>, which was passed to
  27. the chroot command.</para>
  28. <para>You have to make sure all the commands in the rest of this chapter and
  29. in the following chapters are run from within the chroot environment.
  30. If you ever leave this environment for any reason (rebooting for example),
  31. you must remember to again enter chroot and mount proc (discussed later)
  32. before continuing with the installations.</para>
  33. <para>Note that the bash prompt will say "I have no name!" This is
  34. normal, as the Glibc package hasn't been installed yet.</para>
  35. </sect1>