1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
3 <!ENTITY % general-entities SYSTEM "../general.ent">
6 <sect1 id="ch-system-chroot">
7 <title>Entering the chroot environment</title>
8 <?dbhtml filename="chroot.html"?>
10 <para>It is time to enter the chroot environment in order to begin building
11 and installing your final LFS system. Still as <emphasis>root</emphasis> run
12 the following command to enter the small world that is, at the moment,
13 populated with only the temporary tools:</para>
15 <screen><userinput>chroot "$LFS" /tools/bin/env -i \
16 HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
17 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
18 /tools/bin/bash --login +h</userinput></screen>
20 <para>The <emphasis>-i</emphasis> option given to the
21 <command>env</command> 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 <command>vim</command> and <command>less</command> to operate
26 properly. If you need other variables present, such as CFLAGS or CXXFLAGS,
27 this is a good place to set them again.</para>
29 <para>From this point on there's no need to use the LFS variable anymore,
30 because everything you do will be restricted to the LFS file system -- since
31 what the shell thinks is <filename class="directory">/</filename> is actually
32 the value of <filename class="directory">$LFS</filename>, which was passed to
33 the chroot command.</para>
35 <para>Notice that <filename class="directory">/tools/bin</filename> comes
36 last in the PATH. This means that a temporary tool will not be used any more
37 as soon as its final version is installed. Well, at least when the shell
38 doesn't remember the locations of executed binaries -- for this reason hashing
39 is switched off by passing the <emphasis>+h</emphasis> option to
40 <command>bash</command>.</para>
42 <para>You have to make sure all the commands in the rest of this chapter and
43 in the following chapters are run from within the chroot environment.
44 If you ever leave this environment for any reason (rebooting for example),
45 you must remember to first mount the proc and devpts file systems (discussed
46 in the previous section) <emphasis>and</emphasis> enter chroot again before
47 continuing with the installations.</para>
49 <para>Note that the bash prompt will say <quote>I have no name!</quote> This is
50 normal, as the <filename>/etc/passwd</filename> file has not been created yet.