- Timestamp:
- 02/26/2022 03:43:11 PM (2 years ago)
- 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)
- Location:
- chapter07
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
chapter07/chapter07.xml
rfa7acfc rfebac51 10 10 <?dbhtml filename="chapter07.html"?> 11 11 12 <title> Entering Chrootand Building Additional Temporary Tools</title>12 <title>Booting the Target System and Building Additional Temporary Tools</title> 13 13 14 14 <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"/--> 16 16 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="kernfs.xml"/> 17 17 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="chroot.xml"/> -
chapter07/chroot.xml
rfa7acfc rfebac51 7 7 8 8 <sect1 id="ch-tools-chroot"> 9 <?dbhtml filename=" chroot.html"?>9 <?dbhtml filename="env.html"?> 10 10 11 <title> Entering the ChrootEnvironment</title>11 <title>Setting up the Environment</title> 12 12 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> 20 18 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 31 bash: 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 \ 22 38 HOME=/root \ 23 39 TERM="$TERM" \ 24 PS1='(lfs chroot) \u:\w\$ '\40 PS1='(lfs) \u:\w\$ ' \ 25 41 PATH=/usr/bin:/usr/sbin \ 26 42 /bin/bash --login</userinput></screen> 27 43 44 <para>The command replace the current shell process with a new shell 45 process, with controlling terminal set up.</para> 46 28 47 <para>The <parameter>-i</parameter> option given to the <command>env</command> 29 command will clear all variables of the chrootenvironment. After that, only48 command will clear all variables of the environment. After that, only 30 49 the <envar>HOME</envar>, <envar>TERM</envar>, <envar>PS1</envar>, and 31 50 <envar>PATH</envar> variables are set again. The 32 51 <parameter>TERM=$TERM</parameter> construct will set the <envar>TERM</envar> 33 variable inside chroot to the same value as outside chroot. This variable is52 variable to the default value specified by <command>agetty</command>. This variable is 34 53 needed for programs like <command>vim</command> and <command>less</command> 35 54 to operate properly. If other variables are desired, such as … … 37 56 them again.</para> 38 57 39 <para>From this point on, there is no need to use the40 <envar>LFS</envar> variable anymore because all work will be restricted41 to the LFS file system. This is because the Bash shell is told that42 <filename class="directory">$LFS</filename> is now the root43 (<filename class="directory">/</filename>) directory.</para>44 45 58 <para>Notice that <filename class="directory">/tools/bin</filename> is not 46 59 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> 48 61 49 62 <para>Note that the <command>bash</command> prompt will say … … 53 66 <note> 54 67 <para>It is important that all the commands throughout the remainder of this 55 chapter and the following chapters are run from within the chroot56 environment. If you leave this environment for any reason (rebooting for68 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 57 70 example), ensure that the virtual kernel filesystems are mounted as 58 explained in <xref linkend="ch-tools- bindmount"/> and <xref59 linkend="ch-tools-kernfsmount"/> and enter chroot again before continuing60 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> 61 74 </note> 62 75 -
chapter07/introduction.xml
rfa7acfc rfebac51 13 13 <para>This chapter shows how to build the last missing bits of the temporary 14 14 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> 18 19 19 <para>For proper operation of the isolated environment, some communication20 <para>For proper operation of the temporary system, some communication 20 21 with the running kernel must be established. This is done through the 21 22 so-called <emphasis>Virtual Kernel File Systems</emphasis>, which must be 22 mounted when entering the chroot environment. You may want to check23 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> 24 25 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> 31 31 32 32 </sect1> -
chapter07/kernfs.xml
rfa7acfc rfebac51 23 23 mounted:</para> 24 24 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> 66 26 67 27 <sect2 id="ch-tools-kernfsmount"> 68 28 <title>Mounting Virtual Kernel File Systems</title> 69 29 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> 71 33 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} 35 mount -vt devpts /dev/pts /dev/pts -o gid=5,mode=620 36 mount -vt proc proc /proc 37 mount -vt sysfs sysfs /sys 38 mount -vt tmpfs tmpfs /run 39 mount -vt tmpfs tmpfs /dev/shm</userinput></screen> 40 77 41 <variablelist> 78 42 <title>The meaning of the mount options for devpts:</title> … … 102 66 103 67 </variablelist> 104 -->105 <para>In some host systems, <filename>/dev/shm</filename> is a106 symbolic link to <filename class="directory">/run/shm</filename>.107 The /run tmpfs was mounted above so in this case only a108 directory needs to be created.</para>109 68 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 83 ln -sfv /proc/self/fd/1 /dev/stdout 84 ln -sfv /proc/self/fd/2 /dev/stderr</userinput></screen> 113 85 114 86 </sect2>
Note:
See TracChangeset
for help on using the changeset viewer.