source: chapter07/chroot.xml@ 2f9498af

11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 bdubbs/gcc13 multilib renodr/libudev-from-systemd trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/update-glibc
Last change on this file since 2f9498af was f714a8f, checked in by Xi Ruoyao <xry111@…>, 18 months ago

chroot: reword how chroot works

Technically chroot command "tells" bash nothing. It basically calls
chroot("$LFS"), then chdir("/"), then
execve(["/usr/bin/env", "-i", ...]). The kernel also does not tell bash
something like "hey, the root is now $LFS" but just executes (almost) all
system calls from bash as-if $LFS is /.

The man page of chroot says:

DESCRIPTION

Run COMMAND with root directory set to NEWROOT.

Just use the same grammar construction here.

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[fcc02767]1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-tools-chroot">
9 <?dbhtml filename="chroot.html"?>
10
11 <title>Entering the Chroot Environment</title>
12
[387a32af]13 <para>Now that all the packages which are required to build the rest of the
[ebecd08]14 needed tools are on the system, it is time to enter the chroot environment and
15 finish installing the temporary tools. This environment will also be
16 used to install the final system. As user <systemitem
[fcc02767]17 class="username">root</systemitem>, run the following command to enter the
[ebecd08]18 environment that is, at the moment, populated with nothing but temporary
[387a32af]19 tools:</para>
[fcc02767]20
[387a32af]21<screen role="nodump"><userinput>chroot "$LFS" /usr/bin/env -i \
[fcc02767]22 HOME=/root \
23 TERM="$TERM" \
24 PS1='(lfs chroot) \u:\w\$ ' \
[d7a9421]25 PATH=/usr/bin:/usr/sbin \
[490dc153]26 /bin/bash --login</userinput></screen>
[fcc02767]27
28 <para>The <parameter>-i</parameter> option given to the <command>env</command>
[ebecd08]29 command will clear all the variables in the chroot environment. After that, only
[fcc02767]30 the <envar>HOME</envar>, <envar>TERM</envar>, <envar>PS1</envar>, and
31 <envar>PATH</envar> variables are set again. The
[ebecd08]32 <parameter>TERM=$TERM</parameter> construct sets the <envar>TERM</envar>
[fcc02767]33 variable inside chroot to the same value as outside chroot. This variable is
[ebecd08]34 needed so programs like <command>vim</command> and <command>less</command>
35 can operate properly. If other variables are desired, such as
[fcc02767]36 <envar>CFLAGS</envar> or <envar>CXXFLAGS</envar>, this is a good place to set
[ebecd08]37 them.</para>
[fcc02767]38
39 <para>From this point on, there is no need to use the
[ebecd08]40 <envar>LFS</envar> variable any more because all work will be restricted
[f714a8f]41 to the LFS file system; the <command>chroot</command> command runs the
42 Bash shell with the root
43 (<filename class="directory">/</filename>) directory set to
44 <filename class='directory'>$LFS</filename>.</para>
[fcc02767]45
46 <para>Notice that <filename class="directory">/tools/bin</filename> is not
[9174a66]47 in the <envar>PATH</envar>. This means that the cross toolchain will no longer be
[ebecd08]48 used.</para>
[fcc02767]49
50 <para>Note that the <command>bash</command> prompt will say
51 <computeroutput>I have no name!</computeroutput> This is normal because the
52 <filename>/etc/passwd</filename> file has not been created yet.</para>
53
54 <note>
55 <para>It is important that all the commands throughout the remainder of this
56 chapter and the following chapters are run from within the chroot
57 environment. If you leave this environment for any reason (rebooting for
58 example), ensure that the virtual kernel filesystems are mounted as
[bfab1b2]59 explained in <xref linkend="ch-tools-bindmount"/> and <xref
60 linkend="ch-tools-kernfsmount"/> and enter chroot again before continuing
[fcc02767]61 with the installation.</para>
62 </note>
63
64</sect1>
Note: See TracBrowser for help on using the repository browser.