| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <sect1 id="ch06-chroot"><title>Entering the chroot environment</title><?dbhtml filename="chroot.html" dir="chapter06"?><para>It is time to enter the chroot environment in order to begin installingthe packages we need. Before you can chroot, however, you need to become<emphasis>root</emphasis>, since only <emphasis>root</emphasis>can execute the <userinput>chroot</userinput> command.</para><para>Just like earlier, ensure the LFS environment variable is set up properly(if you decided to make use of it) by running <userinput>echo $LFS</userinput>and ensuring it shows the path to your LFS partition's mount point, which is<filename class="directory">/mnt/lfs</filename> if you followed ourexample.</para><para>Become <emphasis>root</emphasis> and run the following commandto enter the chroot environment:</para><para><screen><userinput>chroot $LFS /tools/bin/env -i \    HOME=/root TERM=$TERM PS1='\u:\w\$ ' \    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \    /tools/bin/bash --login</userinput></screen></para><para><screen><userinput>set +h</userinput></screen></para><para>The <userinput>-i</userinput> option given to the<userinput>env</userinput> command will clear all variables of the chrootenvironment. After that, only the HOME, TERM, PS1 and PATH variables areset again. The TERM=$TERM construct will set the TERM variable inside chrootto the same value as outside chroot; this variable is needed for programslike vim and less to operate properly. If you need other variables present,such as CFLAGS or CXXFLAGS, this is a good place to set them again.</para><para>Also note the use of the set +h directive.  This tells bash to not useits internal path hashing. Without this directive, bash will remember pathsto binaries.  Since as we go thru chapter 6, we want to use our newly compiledbinaries as soon as they are installed, we turn off this function.</para><para>From this point on there's no need to use the LFS variable anymore,because everything you do will be restricted to the LFS file system -- sincewhat the shell thinks is <filename class="directory">/</filename> is actuallythe value of <filename class="directory">$LFS</filename>, which was passed tothe chroot command.</para><para>You have to make sure all the commands in the rest of this chapter andin the following chapters are run from within the chroot environment.If you ever leave this environment for any reason (rebooting for example),you must remember to again enter chroot and mount the proc and devptsfilesystems (discussed later) before continuing with the installations.</para><para>Note that the bash prompt will say "I have no name!" This isnormal, as the <filename>/etc/passwd</filename> file has not beencreated yet.</para></sect1>
 |