1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?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-chroot">
<?dbhtml filename="env.html"?>
<title>Setting up the Environment</title>
<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>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) \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>
If you don't want to use all available logical cores, replace
<replaceable>$(nproc)</replaceable> with the number of logical cores you
want to use for building packages in this chapter and the following
chapters. The test suites of some packages (notably Autoconf, Libtool,
and Tar) in &ch-final; are not affected by <envar>MAKEFLAGS</envar>, they
use a <envar>TESTSUITEFLAGS</envar> environment variable instead. We
set that here as well for running these test suites with multiple cores.
</para>
<para>The <parameter>-i</parameter> option given to the <command>env</command>
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 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>Notice that <filename class="directory">/tools/bin</filename> is not
in the <envar>PATH</envar>. This means that the cross toolchain will no longer be
used.</para>
<para>Also note that the <command>bash</command> prompt will say
<computeroutput>I have no name!</computeroutput> This is normal because the
<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 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-kernfsmount"/> and
<xref linkend="ch-tools-devadjust"/> and set up the environment again before
continuing with the installation.</para>
</note>
</sect1>
|