source: chapter06/chapter06.xml@ 90e3cb3

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 6.0 6.1 6.1.1 6.3 6.4 6.5 6.6 6.7 6.8 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk v5_1 v5_1_1 xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 90e3cb3 was 90e3cb3, checked in by Alex Gronenwoud <alex@…>, 20 years ago

Replacing several <userinput> tags by <command>.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@3203 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 19.7 KB
Line 
1<chapter id="chapter06" xreflabel="Chapter 6">
2<title>Installing basic system software</title>
3<?dbhtml filename="chapter06.html" dir="chapter06"?>
4
5
6<sect1 id="ch-system-introduction">
7<title>Introduction</title>
8<?dbhtml filename="introduction.html" dir="chapter06"?>
9
10<para>In this chapter we enter the building site, and start
11constructing our LFS system in earnest. That is, we chroot into
12our temporary mini Linux system, create some auxiliary things,
13and then start installing all the packages, one by one.</para>
14
15<para>The installation of all this software is pretty straightforward,
16and you will probably think it would be much shorter to give here
17the generic installation instructions and explain in full only the
18installation of those packages that require an alternate method.
19Although we agree with that, we nevertheless choose to give the
20full instructions for each and every package, simply to minimize
21the possibilities for mistakes.</para>
22
23<para>The key to learning what makes a Linux system work is to know
24what each package is used for and why the user (or the system) needs it.
25For this purpose for every installed package a summary of its content is
26given followed by concise descriptions of each program and library it
27installed.</para>
28
29<para>If you plan to use compiler optimizations in this chapter, take a look at
30the optimization hint at <ulink url="&hints-root;optimization.txt"/>. Compiler
31optimizations can make a program run slightly faster, but they may also cause
32compilation difficulties and even problems when running the program. If a
33package refuses to compile when using optimization, try to compile it without
34optimization and see if the problem goes away. Even if the package does compile
35when using optimization, there is the risk it may have been compiled incorrectly
36due to complex interactions between the code and build tools. In short, the
37small potential gains achieved in using compiler optimization are generally
38outweighed by the risk. First time builders of LFS are encouraged to build
39without custom optimizations. Your system will still be very fast and very
40stable at the same time.</para>
41
42<para>The order in which packages are installed in this chapter has
43to be strictly followed, to ensure that no program gets a path referring
44to <filename class="directory">/tools</filename> hard-wired into it.
45For the same reason, <emphasis>do not </emphasis> compile packages
46in parallel. Compiling in parallel may save you some time (especially on
47dual-CPU machines), but it could result in a program containing a
48hard-wired path to <filename class="directory">/tools</filename>,
49which will cause the program to stop working when that directory
50is removed.</para>
51
52<para>Before the installation instructions each installation page gives some
53information about the package: a concise description of what it contains, how
54long it will approximately take to build it, how much disk space it needs
55during this building process, the official download location of the package
56(in case you just want to update a few of them), and which other packages it
57needs in order to be built successfully. After the installation instructions
58follows a list of programs and libraries that the package installs, together
59with a series of short descriptions of these.</para>
60
61</sect1>
62
63
64<sect1 id="ch-system-chroot">
65<title>Entering the chroot environment</title>
66<?dbhtml filename="chroot.html" dir="chapter06"?>
67
68<para>It is time to enter the chroot environment in order to begin installing
69the packages we need. Before you can chroot, however, you need to become
70<emphasis>root</emphasis>, since only <emphasis>root</emphasis>
71can execute the <command>chroot</command> command.</para>
72
73<para>Just like earlier, ensure the LFS environment variable is set up properly
74by running <userinput>echo $LFS</userinput> and ensuring it shows the path to
75your LFS partition's mount point, which is
76<filename class="directory">/mnt/lfs</filename> if you followed our example.</para>
77
78<para>Become <emphasis>root</emphasis> and run the following command
79to enter the chroot environment:</para>
80
81<screen><userinput>chroot $LFS /tools/bin/env -i \
82&nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
83&nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
84&nbsp;&nbsp;&nbsp;&nbsp;/tools/bin/bash --login +h</userinput></screen>
85
86<para>The <emphasis>-i</emphasis> option given to the
87<command>env</command> command will clear all variables of the chroot
88environment. After that, only the HOME, TERM, PS1 and PATH variables are
89set again. The TERM=$TERM construct will set the TERM variable inside chroot
90to the same value as outside chroot; this variable is needed for programs
91like <command>vim</command> and <command>less</command> to operate
92properly. If you need other variables present, such as CFLAGS or CXXFLAGS,
93this is a good place to set them again.</para>
94
95<para>From this point on there's no need to use the LFS variable anymore,
96because everything you do will be restricted to the LFS file system -- since
97what the shell thinks is <filename class="directory">/</filename> is actually
98the value of <filename class="directory">$LFS</filename>, which was passed to
99the chroot command.</para>
100
101<para>Notice that <filename class="directory">/tools/bin</filename> comes
102last in the PATH. This means that a temporary tool will not be used any more
103as soon as its final version is installed. Well, at least when the shell
104doesn't remember the locations of executed binaries -- for this reason hashing
105is switched off by passing the <emphasis>+h</emphasis> option to
106<command>bash</command>.</para>
107
108<para>You have to make sure all the commands in the rest of this chapter and
109in the following chapters are run from within the chroot environment.
110If you ever leave this environment for any reason (rebooting for example),
111you must remember to again enter chroot and mount the proc and devpts
112file systems (discussed later) before continuing with the installations.</para>
113
114<para>Note that the bash prompt will say "I have no name!" This is
115normal, as the <filename>/etc/passwd</filename> file has not been
116created yet.</para>
117
118</sect1>
119
120
121<sect1 id="ch-system-changingowner">
122<title>Changing ownership</title>
123<?dbhtml filename="changingowner.html" dir="chapter06"?>
124
125<para>Right now the <filename class="directory">/tools</filename> directory
126is owned by the user <emphasis>lfs</emphasis>, a user that exists only on your
127host system. Although you will probably want to delete the
128<filename class="directory">/tools</filename> directory once you have
129finished your LFS system, you may want to keep it around, for example to
130build more LFS systems. But if you keep the
131<filename class="directory">/tools</filename> directory as it is, you end up
132with files owned by a user ID without a corresponding account. This is
133dangerous because a user account created later on could get this same user ID
134and would suddenly own the <filename class="directory">/tools</filename>
135directory and all the files therein, thus exposing these files to possible
136malicious manipulation.</para>
137
138<para>To avoid this issue, you could add the <emphasis>lfs</emphasis> user to
139your new LFS system later on when creating the <filename>/etc/passwd</filename>
140file, taking care to assign it the same user and group IDs as on your host
141system. Alternatively, you can (and the book assumes you do) assign the
142contents of the <filename class="directory">/tools</filename> directory to
143user <emphasis>root</emphasis> by running the following command:</para>
144
145<screen><userinput>chown -R 0:0 /tools</userinput></screen>
146
147<para>The command uses "0:0" instead of "root:root", because
148<userinput>chown</userinput> is unable to resolve the name "root" until the
149password file has been created.</para>
150
151</sect1>
152
153
154<sect1 id="ch-system-creatingdirs">
155<title>Creating directories</title>
156<?dbhtml filename="creatingdirs.html" dir="chapter06"?>
157
158<para>Let's now create some structure in our LFS file system. Let's create
159a directory tree. Issuing the following commands will create a more or less
160standard tree:</para>
161
162<screen><userinput>mkdir -p /{bin,boot,dev/{pts,shm},etc/opt,home,lib,mnt,proc}
163mkdir -p /{root,sbin,tmp,usr/local,var,opt}
164for dirname in /usr /usr/local
165&nbsp;&nbsp;&nbsp;&nbsp;do
166&nbsp;&nbsp;&nbsp;&nbsp;mkdir $dirname/{bin,etc,include,lib,sbin,share,src}
167&nbsp;&nbsp;&nbsp;&nbsp;ln -s share/{man,doc,info} $dirname
168&nbsp;&nbsp;&nbsp;&nbsp;mkdir $dirname/share/{doc,info,locale,man}
169&nbsp;&nbsp;&nbsp;&nbsp;mkdir $dirname/share/{misc,terminfo,zoneinfo}
170&nbsp;&nbsp;&nbsp;&nbsp;mkdir $dirname/share/man/man{1,2,3,4,5,6,7,8}
171done
172mkdir /var/{lock,log,mail,run,spool}
173mkdir -p /var/{tmp,opt,cache,lib/misc,local}
174mkdir /opt/{bin,doc,include,info}
175mkdir -p /opt/{lib,man/man{1,2,3,4,5,6,7,8}}</userinput></screen>
176
177<para>Directories are, by default, created with permission mode 755, but this
178isn't desirable for all directories. We will make two changes: one to the home
179directory of <emphasis>root</emphasis>, and another to the directories for
180temporary files.</para>
181
182<screen><userinput>chmod 0750 /root
183chmod 1777 /tmp /var/tmp</userinput></screen>
184
185<para>The first mode change ensures that not just anybody can enter the
186<filename class="directory">/root</filename> directory -- the same
187as a normal user would do with his or her home directory.
188The second mode change makes sure that any user can write to the
189<filename class="directory">/tmp</filename> and
190<filename class="directory">/var/tmp</filename> directories, but
191cannot remove other users' files from them. The latter is prohibited
192by the so-called "sticky bit" -- the highest bit in the 1777 bit mask.</para>
193
194<sect2>
195<title>FHS compliance note</title>
196
197<para>We have based our directory tree on the FHS standard (available at
198<ulink url="http://www.pathname.com/fhs/"/>). Besides the above created
199tree this standard stipulates the existence of
200<filename class="directory">/usr/local/games</filename> and
201<filename class="directory">/usr/share/games</filename>, but we don't
202much like these for a base system. However, feel free to make your system
203FHS-compliant. As to the structure of the
204<filename class="directory">/usr/local/share</filename> subdirectory, the FHS
205isn't precise, so we created here the directories that we think are needed.</para>
206
207</sect2>
208
209</sect1>
210
211
212&c6-mountproc;
213
214
215<sect1 id="ch-system-createfiles">
216<title>Creating essential symlinks</title>
217<?dbhtml filename="createfiles.html" dir="chapter06"?>
218
219<para>Some programs hard-wire paths to programs which don't exist yet. In
220order to satisfy these programs, we create a number of symbolic links which
221will be replaced by real files throughout the course of this chapter when
222we're installing all the software.</para>
223
224<screen><userinput>ln -s /tools/bin/{bash,cat,pwd,stty} /bin
225ln -s /tools/bin/perl /usr/bin
226ln -s /tools/lib/libgcc_s.so.1 /usr/lib
227ln -s bash /bin/sh</userinput></screen>
228
229</sect1>
230
231
232<sect1 id="ch-system-pwdgroup">
233<title>Creating the passwd, group and log files</title>
234<?dbhtml filename="pwdgroup.html" dir="chapter06"?>
235
236<para>In order for <emphasis>root</emphasis> to be able to login and for the
237name "root" to be recognized, there need to be relevant entries in the
238<filename>/etc/passwd</filename> and <filename>/etc/group</filename> files.</para>
239
240<para>Create the <filename>/etc/passwd</filename> file by running the following
241command:</para>
242
243<screen><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"</userinput>
244root:x:0:0:root:/root:/bin/bash
245<userinput>EOF</userinput></screen>
246
247<para>The actual password for <emphasis>root</emphasis> (the "x" here is just a
248placeholder) will be set later.</para>
249
250<para>Create the <filename>/etc/group</filename> file by running the following
251command:</para>
252
253<screen><userinput>cat &gt; /etc/group &lt;&lt; "EOF"</userinput>
254root:x:0:
255bin:x:1:
256sys:x:2:
257kmem:x:3:
258tty:x:4:
259tape:x:5:
260daemon:x:6:
261floppy:x:7:
262disk:x:8:
263lp:x:9:
264dialout:x:10:
265audio:x:11:
266<userinput>EOF</userinput></screen>
267
268<para>The created groups aren't part of any standard -- they are the groups
269that the MAKEDEV script in the next section uses. Besides the group "root", the
270LSB (<ulink url="http://www.linuxbase.org"/>) recommends only a group "bin",
271with a GID of 1, be present. All other group names and GIDs can be chosen
272freely by the user, as well-written packages don't depend on GID numbers but
273use the group's name.</para>
274
275<para>To get rid of the "I have no name!" prompt, we will start a new shell.
276Since we installed a full Glibc in <xref linkend="chapter05"/>, and have just
277created the <filename>/etc/passwd</filename> and
278<filename>/etc/group</filename> files, user name and group name resolution
279will now work.</para>
280
281<screen><userinput>exec /tools/bin/bash --login +h</userinput></screen>
282
283<para>Note the use of the <emphasis>+h</emphasis> directive. This tells
284<command>bash</command> not to use its internal path hashing. Without this
285directive, <command>bash</command> would remember the paths to binaries it
286has executed. Since we want to use our newly compiled binaries as soon as
287they are installed, we turn off this function for the duration of this
288chapter.</para>
289
290<para>The <command>login</command>, <command>agetty</command> and
291<command>init</command> programs (and some others) use a number of log
292files to record information such as who was logged into the system and when.
293These programs, however, won't write to the log files if they don't already
294exist. Initialize the log files and give them their proper permissions:</para>
295
296<screen><userinput>touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
297chmod 644 /var/run/utmp /var/log/{btmp,lastlog,wtmp}</userinput></screen>
298
299<para>The <filename>/var/run/utmp</filename> file records the users that are
300currently logged in. The <filename>/var/log/wtmp</filename> file records all
301logins and logouts. The <filename>/var/log/lastlog</filename> file records for
302each user when he or she last logged in. The <filename>/var/log/btmp</filename>
303file records the bad login attempts.</para>
304
305</sect1>
306
307
308&c6-makedev;
309&c6-kernel;
310&c6-manpages;
311&c6-glibc;
312
313
314<sect1 id="ch-system-adjustingtoolchain">
315<title>Re-adjusting the toolchain</title>
316<?dbhtml filename="adjustingtoolchain.html" dir="chapter06"?>
317
318<para>Now that the new C libraries have been installed, it's time to re-adjust
319our toolchain. We'll adjust it so that it will link any newly compiled program
320against the new C libraries. Basically, this is the reverse of what we did
321in the "locking in" stage in the beginning of the previous chapter.</para>
322
323<para>The first thing to do is to adjust the linker. For this we retained the
324source and build directories from the second pass over Binutils. Install the
325adjusted linker by running the following from within the
326<filename class="directory">binutils-build</filename> directory:</para>
327
328<screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
329
330<note><para>If you somehow missed the earlier warning to retain the Binutils
331source and build directories from the second pass in
332<xref linkend="chapter05"/>, or otherwise accidentally deleted them or just
333don't have access to them, don't worry, all is not lost. Just ignore the above
334command. The result will be that the next package, Binutils, will link against
335the Glibc libraries in <filename class="directory">/tools</filename> rather
336than <filename class="directory">/usr</filename>. This is not ideal, however,
337our testing has shown that the resulting Binutils program binaries should be
338identical.</para></note>
339
340<para>From now on every compiled program will link <emphasis>only</emphasis>
341against the libraries in <filename>/usr/lib</filename> and
342<filename>/lib</filename>. The extra
343<emphasis>INSTALL=/tools/bin/install</emphasis> is needed because the Makefile
344created during the second pass still contains the reference to
345<filename>/usr/bin/install</filename>, which we obviously haven't installed yet.
346Some host distributions contain a <filename class="symlink">ginstall</filename>
347symbolic link which takes precedence in the Makefile and thus can cause a
348problem here. The above command takes care of this also.</para>
349
350<para>You can now remove the Binutils source and build directories.</para>
351
352<para>The next thing to do is to amend our GCC specs file so that it points
353to the new dynamic linker. Just like earlier on, we use a sed to accomplish
354this:</para>
355
356<!-- Ampersands are needed to allow cut and paste -->
357
358<screen><userinput>SPECFILE=/tools/lib/gcc-lib/*/*/specs &amp;&amp;
359sed -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g' \
360&nbsp;&nbsp;&nbsp;&nbsp;$SPECFILE &gt; newspecfile &amp;&amp;
361mv -f newspecfile $SPECFILE &amp;&amp;
362unset SPECFILE</userinput></screen>
363
364<para>Again, cutting and pasting the above is recommended. And just like
365before, it is a good idea to visually inspect the specs file to verify the
366intended change was actually made.</para>
367
368<important><para>If you are working on a platform where the name of the dynamic
369linker is something other than <filename>ld-linux.so.2</filename>, you
370<emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
371name of your platform's dynamic linker in the above commands. Refer back to
372<xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
373
374<!-- HACK - Force some whitespace to appease tidy -->
375<literallayout></literallayout>
376
377<caution><para>It is imperative at this point to stop and ensure that the
378basic functions (compiling and linking) of the adjusted toolchain are working
379as expected. For this we are going to perform a simple sanity check:</para>
380
381<screen><userinput>echo 'main(){}' &gt; dummy.c
382cc dummy.c
383readelf -l a.out | grep ': /lib'</userinput></screen>
384
385<para>If everything is working correctly, there should be no errors, and the
386output of the last command will be:</para>
387
388<blockquote><screen>[Requesting program interpreter: /lib/ld-linux.so.2]</screen></blockquote>
389
390<para>(Of course allowing for platform specific differences in dynamic linker
391name). Note especially that <filename class="directory">/lib</filename> now
392appears as the prefix of our dynamic linker. If you did not receive the output
393as shown above, or received no output at all, then something is seriously wrong.
394You will need to investigate and retrace your steps to find out where the
395problem is and correct it. There is no point in continuing until this is done.
396Most likely something went wrong with the specs file amendment above.</para>
397
398<para>Once you are satisfied that all is well, clean up the test files:</para>
399
400<screen><userinput>rm dummy.c a.out</userinput></screen>
401</caution>
402
403<!-- HACK - Force some whitespace to appease tidy -->
404<literallayout></literallayout>
405
406</sect1>
407
408
409&c6-binutils;
410&c6-gcc;
411
412&c6-coreutils;
413&c6-zlib;
414&c6-lfs-utils;
415&c6-findutils;
416&c6-gawk;
417&c6-ncurses;
418&c6-vim;
419&c6-m4;
420&c6-bison;
421&c6-less;
422&c6-groff;
423&c6-sed;
424&c6-flex;
425&c6-gettext;
426&c6-nettools;
427&c6-inetutils;
428&c6-perl;
429&c6-texinfo;
430&c6-autoconf;
431&c6-automake;
432&c6-bash;
433&c6-file;
434&c6-libtool;
435&c6-bzip2;
436&c6-diffutils;
437&c6-ed;
438&c6-kbd;
439&c6-e2fsprogs;
440&c6-grep;
441&c6-grub;
442&c6-gzip;
443&c6-man;
444&c6-make;
445&c6-modutils;
446&c6-patch;
447&c6-procinfo;
448&c6-procps;
449&c6-psmisc;
450&c6-shadowpwd;
451&c6-sysklogd;
452&c6-sysvinit;
453&c6-tar;
454&c6-utillinux;
455&c6-gcc-2953;
456
457
458<sect1 id="ch-system-revisedchroot">
459<title>Revised chroot command</title>
460<?dbhtml filename="revisedchroot.html" dir="chapter06"?>
461
462<para>From now on when you exit the chroot environment and wish to re-enter
463it, you should run the following modified chroot command:</para>
464
465<screen><userinput>chroot $LFS /usr/bin/env -i \
466&nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
467&nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin \
468&nbsp;&nbsp;&nbsp;&nbsp;/bin/bash --login</userinput></screen>
469
470<para>The reason being there is no longer any need to use programs from the
471<filename class="directory">/tools</filename> directory. However, we don't
472want to remove the <filename class="directory">/tools</filename> directory
473just yet. There is still some use for it towards the end of the book.</para>
474
475</sect1>
476
477
478&c6-bootscripts;
479&c6-aboutdebug;
480
481</chapter>
482
Note: See TracBrowser for help on using the repository browser.