chroot.xml 2.8 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. <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>
  19. <para>The <userinput>-i</userinput> option given to the
  20. <userinput>env</userinput> command will clear all variables of the chroot
  21. environment. After that, only the HOME, TERM, PS1 and PATH variables are
  22. set again. The TERM=$TERM construct will set the TERM variable inside chroot
  23. to the same value as outside chroot; this variable is needed for programs
  24. like <userinput>vim</userinput> and <userinput>less</userinput> to operate
  25. properly. If you need other variables present, such as CFLAGS or CXXFLAGS,
  26. this is a good place to set them again.</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>Notice that <filename class="directory">/tools /bin</filename> comes
  33. last in the PATH. This means that a temporary tool will not be used any more
  34. as soon as its final version is installed. Well, at least when the shell
  35. doesn't remember the locations of executed binaries -- for this reason hashing
  36. is switched off a bit further on.</para>
  37. <para>You have to make sure all the commands in the rest of this chapter and
  38. in the following chapters are run from within the chroot environment.
  39. If you ever leave this environment for any reason (rebooting for example),
  40. you must remember to again enter chroot and mount the proc and devpts
  41. filesystems (discussed later) before continuing with the installations.</para>
  42. <para>Note that the bash prompt will say "I have no name!" This is
  43. normal, as the <filename>/etc/passwd</filename> file has not been
  44. created yet.</para>
  45. </sect1>