Index: chapter07/chapter07.xml
===================================================================
--- chapter07/chapter07.xml	(revision 01247ac90a16aa37dc31dec1d743d77d09194234)
+++ chapter07/chapter07.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -10,8 +10,8 @@
   <?dbhtml filename="chapter07.html"?>
 
-  <title>Entering Chroot and Building Additional Temporary Tools</title>
+  <title>Booting the Target System and Building Additional Temporary Tools</title>
 
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="introduction.xml"/>
-  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="changingowner.xml"/>
+  <!--xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="changingowner.xml"/-->
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="kernfs.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="chroot.xml"/>
@@ -24,4 +24,5 @@
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="texinfo.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="util-linux.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="iproute2.xml"/>
 
 <!--
Index: chapter07/chroot.xml
===================================================================
--- chapter07/chroot.xml	(revision 01247ac90a16aa37dc31dec1d743d77d09194234)
+++ chapter07/chroot.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -7,24 +7,50 @@
 
 <sect1 id="ch-tools-chroot">
-  <?dbhtml filename="chroot.html"?>
+  <?dbhtml filename="env.html"?>
 
-  <title>Entering the Chroot Environment</title>
+  <title>Setting up the Environment</title>
 
-  <para>Now that all the packages which are required to build the rest of the
-  needed tools are on the system, it is time to enter the chroot environment and
-  finish installing the temporary tools. This environment will also be
-  used to install the final system. As user <systemitem
-  class="username">root</systemitem>, run the following command to enter the
-  environment that is, at the moment, populated with nothing but temporary
-  tools:</para>
+    <para>The current shell is also the <command>init</command> process,
+    so exiting from it will cause kernel panic.  Prevent exiting from the
+    shell accidentally:</para>
 
-<screen role="nodump"><userinput>chroot "$LFS" /usr/bin/env -i   \
+<screen role="nodump"><userinput>enable -n exit
+readonly IGNOREEOF=1000</userinput></screen>
+
+    <para>The standard I/O streams of the initial shell process is connected
+    with <filename>/dev/console</filename>.  However, the testsuite of some
+    packages may expect the standard I/O streams to be connected with a
+    <quote>real</quote> TTY device node.  Spawn a new shell process on the
+    TTY device with <command>agetty</command>:</para>
+
+<screen role="nodump"><userinput>agetty -n -l /bin/bash <replaceable>tty0</replaceable></userinput></screen>
+
+    <para>If you are working via a serial console, replace
+    <replaceable>tty0</replaceable> with the name of the serial console
+    device node, for example <literal>ttyS0</literal>.</para>
+
+    <para>The command above spawns a new shell process on the TTY device
+    specified in the command, and the initial shell process will run in
+    background as an init process with very limited functions. The new shell
+    process will output:</para>
+
+<screen role="nodump"><computeroutput>bash: cannot set terminal process group (-1): Inappropriate ioctl for device
+bash: no job control in this shell</computeroutput></screen>
+
+    <para>This is normal because the shell is not assigned with a
+    controlling terminal yet.  Now set up controlling terminal and
+    environment variables:</para>
+
+<screen><userinput>exec setsid -c /usr/bin/env -i  \
     HOME=/root                  \
     TERM="$TERM"                \
-    PS1='(lfs chroot) \u:\w\$ ' \
+    PS1='(lfs) \u:\w\$ '        \
     PATH=/usr/bin:/usr/sbin     \
     MAKEFLAGS="-j<replaceable>$(nproc)</replaceable>"      \
     TESTSUITEFLAGS="-j<replaceable>$(nproc)</replaceable>" \
     /bin/bash --login</userinput></screen>
+
+    <para>The command replace the current shell process with a new shell
+    process, with controlling terminal set up.</para>
 
   <para>
@@ -39,20 +65,13 @@
 
   <para>The <parameter>-i</parameter> option given to the <command>env</command>
-  command will clear all the variables in the chroot environment. After that, only
+  command will clear all the variables in the environment. After that, only
   the <envar>HOME</envar>, <envar>TERM</envar>, <envar>PS1</envar>, and
   <envar>PATH</envar> variables are set again. The
-  <parameter>TERM=$TERM</parameter> construct sets the <envar>TERM</envar>
-  variable inside chroot to the same value as outside chroot. This variable is
+  <parameter>TERM=$TERM</parameter> construct will set the <envar>TERM</envar>
+  variable to the default value specified by <command>agetty</command>. This variable is
   needed so programs like <command>vim</command> and <command>less</command>
   can operate properly.  If other variables are desired, such as
   <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar>, this is a good place to set
   them.</para>
-
-  <para>From this point on, there is no need to use the
-  <envar>LFS</envar> variable any more because all work will be restricted
-  to the LFS file system; the <command>chroot</command> command runs the
-  Bash shell with the root
-  (<filename class="directory">/</filename>) directory set to
-  <filename class='directory'>$LFS</filename>.</para>
 
   <para>Notice that <filename class="directory">/tools/bin</filename> is not
@@ -64,12 +83,17 @@
   <filename>/etc/passwd</filename> file has not been created yet.</para>
 
+  <para>Now set up a temporary hostname, which is required by test suite of
+  some packages:</para>
+
+<screen><userinput>hostname lfs</userinput></screen>
+
   <note>
     <para>It is important that all the commands throughout the remainder of this
-    chapter and the following chapters are run from within the chroot
-    environment. If you leave this environment for any reason (rebooting for
+    chapter and the following chapters are run from within the environment
+    we've set. If you leave this environment for any reason (rebooting for
     example), ensure that the virtual kernel filesystems are mounted as
-    explained in <xref linkend="ch-tools-bindmount"/> and <xref
-    linkend="ch-tools-kernfsmount"/> and enter chroot again before continuing
-    with the installation.</para>
+    explained in <xref linkend="ch-tools-kernfsmount"/> and
+    <xref linkend="ch-tools-devadjust"/> and set up the environment again before
+    continuing with the installation.</para>
   </note>
 
Index: chapter07/cleanup.xml
===================================================================
--- chapter07/cleanup.xml	(revision 01247ac90a16aa37dc31dec1d743d77d09194234)
+++ chapter07/cleanup.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -58,49 +58,13 @@
 
     <para>
-      The following steps are performed from outside the chroot
-      environment. That means you have to leave the chroot environment
-      first before continuing. The reason for that is to
-      get access to file system locations outside of the chroot
-      environment to store/read the backup archive, which ought
-      not be placed within the
-      <filename class="directory">$LFS</filename> hierarchy.
+       If you are making a backup, mount the partition for backup:
     </para>
 
-    <para>
-       If you have decided to make a backup, leave the chroot environment:
-    </para>
-
-<screen role="nodump"><userinput>exit</userinput></screen>
-
-    <important>
-      <para>
-        All of the following instructions are executed by
-        <systemitem class="username">root</systemitem> on your host system.
-        Take extra care about the commands you're going to run as mistakes
-        made here can modify your host system. Be aware that the
-        environment variable <envar>LFS</envar>
-        is set for user <systemitem class="username">lfs</systemitem> by default
-        but may <emphasis>not</emphasis> be set for
-        <systemitem class="username">root</systemitem>.
-     </para>
-     <para>
-        Whenever commands are to be executed by <systemitem class="username">root</systemitem>,
-        make sure you have set <envar>LFS</envar>.
-     </para>
-     <para>
-        This has been discussed in <xref linkend='ch-partitioning-aboutlfs'/>.
-      </para>
-    </important>
-
-    <para>Before making a backup, unmount the virtual file systems:</para>
-
-<screen role="nodump"><userinput>mountpoint -q $LFS/dev/shm &amp;&amp; umount $LFS/dev/shm
-umount $LFS/dev/pts
-umount $LFS/{sys,proc,run,dev}</userinput></screen>
+<screen role="nodump"><userinput>mount -v /dev/sda<replaceable>4</replaceable> /mnt</userinput></screen>
 
     <para>
       Make sure you have at least 1 GB free disk space (the source tarballs
-      will be included in the backup archive) on the file system containing
-      the directory where you create the backup archive.
+      will be included in the backup archive) in the partition prepared for
+      backup.
     </para>
 
@@ -125,13 +89,13 @@
     </note>
 
-<screen role="nodump"><userinput>cd $LFS
-tar -cJpf $HOME/lfs-temp-tools-&version;.tar.xz .</userinput></screen>
+<screen role="nodump"><userinput>cd /
+tar -cJpf /mnt/lfs-temp-tools-&version;.tar.xz . \
+    --exclude="dev/*" --exclude="proc/*"
+    --exclude="sys/*" --exclude="run/*"
+    --exclude="mnt/*"</userinput></screen>
 
-    <note>
-      <para>
-        If continuing to chapter 8, don't forget to reenter the chroot
-        environment as explained in the <quote>Important</quote> box below.
-      </para>
-    </note>
+    <para>Unmount the partition containing the backup:</para>
+
+<screen role="nodump"><userinput>umount /mnt</userinput></screen>
 
   </sect2>
@@ -143,36 +107,52 @@
       In case some mistakes have been made and you need to start over, you can
       use this backup to restore the system and save some recovery time.
-      Since the sources are located under
-      <filename class="directory">$LFS</filename>, they are included in the
-      backup archive as well, so they do not need to be downloaded again. After
-      checking that <envar>$LFS</envar> is set properly, you can
-      restore the backup by executing the following commands:
+      Since the sources are included in the
+      backup archive as well, so they do not need to be downloaded again.
     </para>
+
+    <warning><para>
+      Power off the target system and reconnect the disk containing LFS
+      temporary system to the host for restoring the backup.  It's necessary
+      to avoid overwriting some binaries being used.  Because the package
+      providing <command>shutdown</command> command is not built yet, the
+      system can't be shut down cleanly.  Issue <command>sync</command> to
+      ensure all filesystem writes cached in memory to be really written
+      into the disk, then power off the system physically (for example,
+      unplug the AC cord).
+    </para></warning>
+
+    <para>Mount the LFS partition and the backup partition on
+    <emphasis role="bold">the host system</emphasis>:</para>
 
 <!-- Make the following look different so users don't blindly run the
      restore when they don't need to. -->
 
+<screen role="nodump"><computeroutput>mkdir -pv /mnt/lfs-{target,backup}
+mount -v -t ext4 <replaceable>/dev/sdx</replaceable>3 /mnt/lfs-target
+mount -v -t ext4 <replaceable>/dev/sdx4</replaceable> /mnt/lfs-backup</computeroutput></screen>
+
+
     <warning><para>The following commands are extremely dangerous.  If
     you run <command>rm -rf ./*</command> as the &root; user and you
-    do not change to the $LFS directory or the <envar>LFS</envar>
-    environment variable is not set for the &root; user, it will destroy
-    your entire host system.  YOU ARE WARNED.</para></warning>
+    do not change to the <filename>lfs-target</filename> directory,
+    it will destroy your entire host system.
+    YOU ARE WARNED.</para></warning>
 
-<screen role="nodump"><computeroutput>cd $LFS
+<screen role="nodump"><computeroutput>cd /mnt/lfs-target
 rm -rf ./*
-tar -xpf $HOME/lfs-temp-tools-&version;.tar.xz</computeroutput></screen>
+tar -xpf /mnt/lfs-backup/lfs-temp-tools-&version;.tar.xz</computeroutput></screen>
 
     <para>
-       Again, double check that the environment has been set up properly
-       and continue building the rest of the system.
+       Again, unmount the two partitions, reconnect the device to the target
+       machine, boot it and continue building the rest of system:
     </para>
+
+<screen role="nodump"><computeroutput>umount /mnt/lfs-{target,backup}</computeroutput></screen>
 
     <important>
       <para>
-         If you left the chroot environment to create a backup or restart
-         building using a restore, remember to check that the virtual
-         file systems are still mounted (<command>findmnt | grep
-         $LFS</command>).  If they are not mounted, remount them now as
-         described in <xref linkend='ch-tools-kernfs'/> and re-enter the chroot
+         If you reboot your target machine and restart
+         building using a restore, remount the virtual filesystems now as
+         described in <xref linkend='ch-tools-kernfs'/> and re-enter the build
          environment (see <xref linkend='ch-tools-chroot'/>) before continuing.
        </para>
Index: chapter07/introduction.xml
===================================================================
--- chapter07/introduction.xml	(revision 01247ac90a16aa37dc31dec1d743d77d09194234)
+++ chapter07/introduction.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -11,22 +11,31 @@
   <title>Introduction</title>
 
+  <warning>
+    <para>Please make sure the temporary system is already booted on the
+    target machine.  All commands in this chapter and the following chapters
+    should be executed on the target machine instead of the host distro,
+    unless the book explicitly says a command is for the host.  Running a
+    command for the temporary system on the host can completely destroy the
+    host distro.</para>
+  </warning>
+
   <para>This chapter shows how to build the last missing bits of the temporary
   system: the tools needed to build the various packages.  Now
-  that all circular dependencies have been resolved, a <quote>chroot</quote>
-  environment, completely isolated from the host operating system (except for
-  the running kernel), can be used for the build.</para>
+  that all circular dependencies have been resolved and the temporary system
+  is already bootable, we can boot it on the target machine and it would be
+  completely isolated from the host operating system.  Then we can continue
+  to build on the target machine.</para>
 
-  <para>For proper operation of the isolated environment, some communication
-  with the running kernel must be established. This is done via the
+  <para>For proper operation of the temporary system, some communication
+  with the running kernel must be established. This is done through the
   so-called <emphasis>Virtual Kernel File Systems</emphasis>, which will be
-  mounted before entering the chroot environment. You may want to verify
-  that they are mounted by issuing the <command>findmnt</command> command.</para>
+  mounted as soon as possible after boot. You may want to check
+  that they are mounted by issuing <command>mount</command>.</para>
 
-  <para>Until <xref linkend="ch-tools-chroot"/>, the commands must be
-  run as <systemitem class="username">root</systemitem>, with the
-  <envar>LFS</envar> variable set. After entering chroot, all commands
-  are run as &root;, fortunately without access to the OS of the computer
-  you built LFS on. Be careful anyway, as it is easy to destroy the whole
-  LFS system with bad commands.</para>
+  <para>All commands in this and following chapters are run as &root; on the
+  target system, fortunately without access to the host system.
+  Be careful anyway, as if the storage devices of your target system already
+  contain some important data, it's possible to destroy them with bad
+  commands.</para>
 
 </sect1>
Index: chapter07/iproute2.xml
===================================================================
--- chapter07/iproute2.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
+++ chapter07/iproute2.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+  <!ENTITY % general-entities SYSTEM "../general.ent">
+  %general-entities;
+]>
+
+<sect1 id="ch-tools-lo" role="wrap">
+  <?dbhtml filename="lo-iface.html"?>
+
+  <sect1info condition="script">
+    <productname>iproute2</productname>
+    <productnumber>&iproute2-version;</productnumber>
+    <address>&iproute2-url;</address>
+  </sect1info>
+
+  <title>Setting Up Loopback Network Interface with IPRoute-&iproute2-version;</title>
+
+  <indexterm zone="ch-tools-lo">
+    <primary sortas="a-IPRoute2">IPRoute2</primary>
+    <secondary>tools</secondary>
+  </indexterm>
+
+  <sect2 role="package">
+    <title/>
+
+    <para>The IPRoute2 package contains programs for basic and advanced IPV4-based
+    networking. Now we need <command>ip</command> from it to bring up
+    loopback network interface, which is expected by the testsuites of
+    various packages.</para>
+
+    <segmentedlist>
+      <segtitle>&buildtime;</segtitle>
+      <segtitle>&diskspace;</segtitle>
+
+      <seglistitem>
+        <seg>&iproute2-tmp-sbu;</seg>
+        <seg>&iproute2-tmp-du;</seg>
+      </seglistitem>
+    </segmentedlist>
+
+  </sect2>
+
+  <sect2 role="installation">
+    <title>Use IPRoute2 to Set Up Loopback Network Interface</title>
+
+    <para>IPRoute2 package has several dependencies not installed yet, but
+    we only need <command>ip</command> utility from the package now.
+    Disable the build of other utilities:</para>
+
+<screen><userinput remap="pre">sed '/SUBDIRS/s/=.*/=lib ip/' -i Makefile</userinput></screen>
+
+    <para>Compile the package:</para>
+
+<screen><userinput remap="make">PKG_CONFIG=false make</userinput></screen>
+
+    <variablelist>
+      <title>The meaning of the environment variable:</title>
+
+      <varlistentry>
+        <term><parameter>PKG_CONFIG=false</parameter></term>
+        <listitem>
+          <para>The building system attempts to find dependencies with
+          <command>pkg-config</command>, which is not installed yet.
+          We can override it since <command>ip</command> utility does not
+          need these dependencies.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+
+    <para>It's not needed to install the <command>ip</command> utility now.
+    Just bring up the loopback interface:</para>
+
+<screen><userinput remap="install">ip/ip link set lo up</userinput></screen>
+
+    <para>Verify the result:</para>
+
+<screen><userinput remap="install">ip/ip addr</userinput></screen>
+
+    <para>The command above should show <literal>127.0.0.1/8</literal>
+    as the IPv4 address of <literal>lo</literal>, and
+    <literal>::1/128</literal> as the IPv6 address.</para>
+
+  </sect2>
+
+  <sect2 role="content">
+    <title/>
+
+    <para>Details on this package are located in <xref linkend="contents-iproute2" role="."/></para>
+
+  </sect2>
+
+</sect1>
Index: chapter07/kernfs.xml
===================================================================
--- chapter07/kernfs.xml	(revision 01247ac90a16aa37dc31dec1d743d77d09194234)
+++ chapter07/kernfs.xml	(revision 7546d8b8505ecc175af166dfbec6798a6121dc9f)
@@ -19,54 +19,25 @@
     with the kernel itself. These file systems are virtual: no disk
     space is used for them. The content of these file systems resides in
-    memory. These file systems must be mounted in the $LFS directory tree
-    so the applications can find them in the chroot environment.</para>
+    memory.</para>
 
     <para>Begin by creating the directories on which these virtual file systems will be
     mounted:</para>
 
-<screen><userinput>mkdir -pv $LFS/{dev,proc,sys,run}</userinput></screen>
-
-  <sect2 id="ch-tools-bindmount">
-    <title>Mounting and Populating /dev</title>
-
-      <para>During a normal boot of an LFS system, the kernel automatically
-      mounts the <systemitem class="filesystem">devtmpfs</systemitem>
-      file system on the
-      <filename class="directory">/dev</filename> directory; the kernel
-      creates device nodes on that virtual file system during the boot process,
-      or when a device is first detected or accessed. The udev daemon may
-      change the ownership or permissions of the device nodes created by the
-      kernel, and create new device nodes or symlinks, to ease the work of
-      distro maintainers and system administrators.  (See
-      <xref linkend='ch-config-udev-device-node-creation'/> for details.)
-      If the host kernel supports &devtmpfs;, we can simply mount a
-      &devtmpfs; at <filename class='directory'>$LFS/dev</filename> and rely
-      on the kernel to populate it.</para>
-
-      <para>But some host kernels lack &devtmpfs; support; these
-      host distros use different methods to create the content of
-      <filename class="directory">/dev</filename>.
-      So the only host-agnostic way to populate the
-      <filename class="directory">$LFS/dev</filename> directory is
-      by bind mounting the host system's
-      <filename class="directory">/dev</filename> directory. A bind mount is
-      a special type of mount that makes a directory subtree or a file
-      visible at some other location. Use the following
-      command to do this.</para>
-
-<screen><userinput>mount -v --bind /dev $LFS/dev</userinput></screen>
-
-  </sect2>
+<screen><userinput>mkdir -pv /{proc,sys,run}</userinput></screen>
 
   <sect2 id="ch-tools-kernfsmount">
     <title>Mounting Virtual Kernel File Systems</title>
 
-      <para>Now mount the remaining virtual kernel file systems:</para>
+    <para>The kernel has already mounted
+    <systemitem class="filesystem">devtmpfs</systemitem>.
+    Mount the remaining virtual kernel file systems:</para>
 
-<screen><userinput>mount -v --bind /dev/pts $LFS/dev/pts
-mount -vt proc proc $LFS/proc
-mount -vt sysfs sysfs $LFS/sys
-mount -vt tmpfs tmpfs $LFS/run</userinput></screen>
-<!--
+<screen><userinput>mkdir -pv /dev/{pts,shm}
+mount -vt devpts /dev/pts /dev/pts -o gid=5,mode=620
+mount -vt proc  proc  /proc
+mount -vt sysfs sysfs /sys
+mount -vt tmpfs tmpfs /run
+mount -vt tmpfs tmpfs /dev/shm -o nosuid,nodev</userinput></screen>
+
     <variablelist>
       <title>The meaning of the mount options for devpts:</title>
@@ -96,20 +67,23 @@
 
     </variablelist>
--->
-      <para>In some host systems, <filename>/dev/shm</filename> is a
-      symbolic link to <filename class="directory">/run/shm</filename>.
-      The /run tmpfs was mounted above so in this case only a
-      directory needs to be created.</para>
 
-      <para>In other host systems <filename>/dev/shm</filename> is a mount point 
-      for a tmpfs. In that case the mount of /dev above will only create
-      /dev/shm as a directory in the chroot environment. In this situation
-      we must explicitly mount a tmpfs:</para>
+  </sect2>
 
-<screen><userinput>if [ -h $LFS/dev/shm ]; then
-  (cd $LFS/dev; mkdir $(readlink shm))
-else
-  mount -vt tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm
-fi</userinput></screen>
+  <sect2 id="ch-tools-devadjust">
+    <title>Adjusting devtmpfs</title>
+
+    <para>Now <systemitem class='filesystem'>proc</systemitem> filesystem
+    is mounted, we can replace the device nodes for standard I/O streams
+    with symlinks to pseudo files in
+    <filename class="directory">/proc/self/fd</filename> (which are symlinks
+    to the files connected to the standard I/O streams for the current
+    process).  And, create another symlink recommended by the kernel
+    documentation.  These are necessary for I/O redirection in the building
+    system of some packages to function properly:</para>
+
+<screen><userinput>ln -sfv /proc/self/fd/0 /dev/stdin
+ln -sfv /proc/self/fd/1 /dev/stdout
+ln -sfv /proc/self/fd/2 /dev/stderr
+ln -sv  /proc/self/fd   /dev</userinput></screen>
 
   </sect2>
