Changeset febac51


Ignore:
Timestamp:
02/26/2022 03:43:11 PM (7 months ago)
Author:
Xi Ruoyao <xry111@…>
Branches:
xry111/clfs-ng
Children:
ae636e7
Parents:
fa7acfc
git-author:
Xi Ruoyao <xry111@…> (08/25/2021 05:30:13 AM)
git-committer:
Xi Ruoyao <xry111@…> (02/26/2022 03:43:11 PM)
Message:

cross-ng: chapter 7: adjust introduction for cross build

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • chapter02/stages.xml

    rfa7acfc rfebac51  
    6565    <itemizedlist>
    6666      <listitem>
    67          <para>The /mnt/lfs partition must be mounted.</para>
     67        <para>You must boot the temporary system on the target machine.</para>
    6868      </listitem>
    6969
    7070      <listitem>
    71         <para>A few operations, from <quote>Changing Ownership</quote> to
    72         <quote>Entering the Chroot Environment</quote> must be done as the
    73         <systemitem class="username">root</systemitem> user, with the LFS
    74         environment variable set for the
    75         <systemitem class="username">root</systemitem>user.</para>
     71        <para>A few operations, from
     72        <quote>Preparing Virtual Kernel File Systems</quote> to
     73        <quote>Setting up Environment</quote> must be done as the
     74        <systemitem class="username">root</systemitem> user.</para>
    7675      </listitem>
    7776
    78       <listitem>
    79          <para> When entering chroot, the LFS environment variable must be set
    80          for <systemitem class="username">root</systemitem>. The LFS
    81          variable is not used afterwards.</para>
    82       </listitem>
    83 
    84       <listitem>
    85          <para> The virtual file systems must be mounted.  This can be done
    86          before or after entering chroot by changing to a host virtual terminal
    87          and, as <systemitem class="username">root</systemitem>, running the
    88          commands in
    89          <xref linkend='ch-tools-bindmount'/> and
    90          <xref linkend='ch-tools-kernfsmount'/>.</para>
    91       </listitem>
    9277    </itemizedlist>
    9378  </sect2>
  • chapter07/chapter07.xml

    rfa7acfc rfebac51  
    1010  <?dbhtml filename="chapter07.html"?>
    1111
    12   <title>Entering Chroot and Building Additional Temporary Tools</title>
     12  <title>Booting the Target System and Building Additional Temporary Tools</title>
    1313
    1414  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="introduction.xml"/>
    15   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="changingowner.xml"/>
     15  <!--xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="changingowner.xml"/-->
    1616  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="kernfs.xml"/>
    1717  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="chroot.xml"/>
  • chapter07/chroot.xml

    rfa7acfc rfebac51  
    77
    88<sect1 id="ch-tools-chroot">
    9   <?dbhtml filename="chroot.html"?>
     9  <?dbhtml filename="env.html"?>
    1010
    11   <title>Entering the Chroot Environment</title>
     11  <title>Setting up the Environment</title>
    1212
    13   <para>Now that all the packages which are required to build the rest of the
    14   needed tools are on the system, it is time to enter the chroot environment to
    15   finish installing the remaining temporary tools. This environment will be in
    16   use also for installing the final system. As user <systemitem
    17   class="username">root</systemitem>, run the following command to enter the
    18   environment that is, at the moment, populated with only the temporary
    19   tools:</para>
     13    <para>The standard I/O streams of the initial shell process is connected
     14    with <filename>/dev/console</filename>.  However, the testsuite of some
     15    packages may expect the standard I/O streams to be connected with a
     16    <quote>real</quote> TTY device node.  Spawn a new shell process on the
     17    TTY device with <command>agetty</command>:</para>
    2018
    21 <screen role="nodump"><userinput>chroot "$LFS" /usr/bin/env -i   \
     19<screen role="nodump"><userinput>agetty -n -l /bin/bash <replaceable>tty0</replaceable></userinput></screen>
     20
     21    <para>If you are working via a serial console, replace
     22    <replaceable>tty0</replaceable> with the name of the serial console
     23    device node, for example <literal>ttyS0</literal>.</para>
     24
     25    <para>The command above spawns a new shell process on the TTY device
     26    specified in the command, and the initial shell process will run in
     27    background as an init process with very limited functions. The new shell
     28    process will output:</para>
     29
     30<screen role="nodump"><computeroutput>bash: cannot set terminal process group (-1): Inappropriate ioctl for device
     31bash: no job control in this shell</computeroutput></screen>
     32
     33    <para>This is normal because the shell is not assigned with a
     34    controlling terminal yet.  Now set up controlling terminal and
     35    environment variables:</para>
     36
     37<screen><userinput>exec setsid -c /usr/bin/env -i  \
    2238    HOME=/root                  \
    2339    TERM="$TERM"                \
    24     PS1='(lfs chroot) \u:\w\$ ' \
     40    PS1='(lfs) \u:\w\$ '        \
    2541    PATH=/usr/bin:/usr/sbin     \
    2642    /bin/bash --login</userinput></screen>
    2743
     44    <para>The command replace the current shell process with a new shell
     45    process, with controlling terminal set up.</para>
     46
    2847  <para>The <parameter>-i</parameter> option given to the <command>env</command>
    29   command will clear all variables of the chroot environment. After that, only
     48  command will clear all variables of the environment. After that, only
    3049  the <envar>HOME</envar>, <envar>TERM</envar>, <envar>PS1</envar>, and
    3150  <envar>PATH</envar> variables are set again. The
    3251  <parameter>TERM=$TERM</parameter> construct will set the <envar>TERM</envar>
    33   variable inside chroot to the same value as outside chroot. This variable is
     52  variable to the default value specified by <command>agetty</command>. This variable is
    3453  needed for programs like <command>vim</command> and <command>less</command>
    3554  to operate properly.  If other variables are desired, such as
     
    3756  them again.</para>
    3857
    39   <para>From this point on, there is no need to use the
    40   <envar>LFS</envar> variable anymore because all work will be restricted
    41   to the LFS file system.  This is because the Bash shell is told that
    42   <filename class="directory">$LFS</filename> is now the root
    43   (<filename class="directory">/</filename>) directory.</para>
    44 
    4558  <para>Notice that <filename class="directory">/tools/bin</filename> is not
    4659  in the <envar>PATH</envar>. This means that the cross toolchain will no longer be
    47   used in the chroot environment.</para>
     60  used on the target machine.</para>
    4861
    4962  <para>Note that the <command>bash</command> prompt will say
     
    5366  <note>
    5467    <para>It is important that all the commands throughout the remainder of this
    55     chapter and the following chapters are run from within the chroot
    56     environment. If you leave this environment for any reason (rebooting for
     68    chapter and the following chapters are run from within the environment
     69    we've set. If you leave this environment for any reason (rebooting for
    5770    example), ensure that the virtual kernel filesystems are mounted as
    58     explained in <xref linkend="ch-tools-bindmount"/> and <xref
    59     linkend="ch-tools-kernfsmount"/> and enter chroot again before continuing
    60     with the installation.</para>
     71    explained in <xref linkend="ch-tools-kernfsmount"/> and
     72    <xref linkend="ch-tools-devadjust"/> and set up the environment again before
     73    continuing with the installation.</para>
    6174  </note>
    6275
  • chapter07/introduction.xml

    rfa7acfc rfebac51  
    1313  <para>This chapter shows how to build the last missing bits of the temporary
    1414  system: the tools needed by the build machinery of various packages.  Now
    15   that all circular dependencies have been resolved, a <quote>chroot</quote>
    16   environment, completely isolated from the host operating system (except for
    17   the running kernel), can be used for the build.</para>
     15  that all circular dependencies have been resolved and the temporary system
     16  is already bootable, we can boot it on the target machine and it would be
     17  completely isolated from the host operating system.  Then we can continue
     18  to build on the target machine.</para>
    1819
    19   <para>For proper operation of the isolated environment, some communication
     20  <para>For proper operation of the temporary system, some communication
    2021  with the running kernel must be established. This is done through the
    2122  so-called <emphasis>Virtual Kernel File Systems</emphasis>, which must be
    22   mounted when entering the chroot environment. You may want to check
    23   that they are mounted by issuing <command>findmnt</command>.</para>
     23  mounted as soon as possible after boot. You may want to check
     24  that they are mounted by issuing <command>mount</command>.</para>
    2425
    25   <para>Until <xref linkend="ch-tools-chroot"/>, the commands must be
    26   run as <systemitem class="username">root</systemitem>, with the
    27   <envar>LFS</envar> variable set. After entering chroot, all commands
    28   are run as root, fortunately without access to the OS of the computer
    29   you built LFS on. Be careful anyway, as it is easy to destroy the whole
    30   LFS system with badly formed commands.</para>
     26  <para>All commands in this and following chapters are run as root on the
     27  target system, fortunately without access to the host system.
     28  Be careful anyway, as if the storage devices of your target system already
     29  contain some important data, it's possible to destroy them with badly
     30  formed commands.</para>
    3131
    3232</sect1>
  • chapter07/kernfs.xml

    rfa7acfc rfebac51  
    2323    mounted:</para>
    2424
    25 <screen><userinput>mkdir -pv $LFS/{dev,proc,sys,run}</userinput></screen>
    26 
    27   <sect2>
    28     <title>Creating Initial Device Nodes</title>
    29 
    30     <para>When the kernel boots the system, it requires the presence of a few
    31     device nodes, in particular the <filename
    32     class="devicefile">console</filename> and <filename
    33     class="devicefile">null</filename> devices. The device nodes must be
    34     created on the hard disk so that they are available before the kernel
    35     populates <systemitem class="filesystem">/dev</systemitem>), and
    36     additionally when Linux is started with
    37     <parameter>init=/bin/bash</parameter>. Create the devices by running the
    38     following commands:</para>
    39 
    40 <screen><userinput>mknod -m 600 $LFS/dev/console c 5 1
    41 mknod -m 666 $LFS/dev/null c 1 3</userinput></screen>
    42 
    43   </sect2>
    44 
    45   <sect2 id="ch-tools-bindmount">
    46     <title>Mounting and Populating /dev</title>
    47 
    48       <para>The recommended method of populating the <filename
    49       class="directory">/dev</filename> directory with devices is to mount a
    50       virtual filesystem (such as <systemitem
    51       class="filesystem">tmpfs</systemitem>) on the <filename
    52       class="directory">/dev</filename> directory, and allow the devices to be
    53       created dynamically on that virtual filesystem as they are detected or
    54       accessed. Device creation is generally done during the boot process
    55       by Udev. Since this new system does not yet have Udev and has not yet
    56       been booted, it is necessary to mount and populate <filename
    57       class="directory">/dev</filename> manually. This is accomplished by bind
    58       mounting the host system's <filename class="directory">/dev</filename>
    59       directory. A bind mount is a special type of mount that allows you to
    60       create a mirror of a directory or mount point to some other location. Use
    61       the following command to achieve this:</para>
    62 
    63 <screen><userinput>mount -v --bind /dev $LFS/dev</userinput></screen>
    64 
    65   </sect2>
     25<screen><userinput>mkdir -pv /{proc,sys,run}</userinput></screen>
    6626
    6727  <sect2 id="ch-tools-kernfsmount">
    6828    <title>Mounting Virtual Kernel File Systems</title>
    6929
    70       <para>Now mount the remaining virtual kernel filesystems:</para>
     30    <para>The kernel has already mounted
     31    <systemitem class="filesystem">devtmpfs</systemitem>.
     32    Mount the remaining virtual kernel filesystems:</para>
    7133
    72 <screen><userinput>mount -v --bind /dev/pts $LFS/dev/pts
    73 mount -vt proc proc $LFS/proc
    74 mount -vt sysfs sysfs $LFS/sys
    75 mount -vt tmpfs tmpfs $LFS/run</userinput></screen>
    76 <!--
     34<screen><userinput>mkdir -pv /dev/{pts,shm}
     35mount -vt devpts /dev/pts /dev/pts -o gid=5,mode=620
     36mount -vt proc  proc  /proc
     37mount -vt sysfs sysfs /sys
     38mount -vt tmpfs tmpfs /run
     39mount -vt tmpfs tmpfs /dev/shm</userinput></screen>
     40
    7741    <variablelist>
    7842      <title>The meaning of the mount options for devpts:</title>
     
    10266
    10367    </variablelist>
    104 -->
    105       <para>In some host systems, <filename>/dev/shm</filename> is a
    106       symbolic link to <filename class="directory">/run/shm</filename>.
    107       The /run tmpfs was mounted above so in this case only a
    108       directory needs to be created.</para>
    10968
    110 <screen><userinput>if [ -h $LFS/dev/shm ]; then
    111   mkdir -pv $LFS/$(readlink $LFS/dev/shm)
    112 fi</userinput></screen>
     69  </sect2>
     70
     71  <sect2 id="ch-tools-devadjust">
     72    <title>Adjusting devtmpfs</title>
     73
     74    <para>Now <systemitem class='filesystem'>proc</systemitem> filesystem
     75    is mounted, we can replace the device nodes for standard I/O streams
     76    with symlinks to pseudo files in
     77    <filename class="directory">/proc/self/fd</filename> (which are symlinks
     78    to the files connected to the standard I/O streams for the current
     79    process).  This is necessary for I/O redirection in the building system
     80    of some packages to function properly:</para>
     81
     82<screen><userinput>ln -sfv /proc/self/fd/0 /dev/stdin
     83ln -sfv /proc/self/fd/1 /dev/stdout
     84ln -sfv /proc/self/fd/2 /dev/stderr</userinput></screen>
    11385
    11486  </sect2>
Note: See TracChangeset for help on using the changeset viewer.