source: chapter06/chapter06.xml@ 02974d8

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 02974d8 was 02974d8, checked in by Alex Gronenwoud <alex@…>, 20 years ago

Re-adding HOME to the chroot command, and a few textual shuffles.

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

  • Property mode set to 100644
File size: 27.7 KB
Line 
1<chapter id="chapter-building-system" 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<para>If you wish to keep track of which package installs what files, you may
62want to use a package manager. For a general overview of package managers have
63a look at <ulink url="&blfs-root;view/cvs/introduction/pkgmgt.html"/>. And for
64a package management method specifically geared towards LFS see
65<ulink url="&hints-root;more_control_and_pkg_man.txt"/>.</para>
66
67</sect1>
68
69
70<sect1 id="ch-system-proc">
71<title>Mounting the proc and devpts file systems</title>
72<?dbhtml filename="proc.html" dir="chapter06"?>
73
74<para>In order for certain programs to function properly, the
75<emphasis>proc</emphasis> and <emphasis>devpts</emphasis> file systems must be
76available within the chroot environment. The proc file system is the process
77information pseudo file system through which the kernel provides information
78about the status of the system. And the devpts file system is nowadays the most
79common way pseudo terminals (PTYs) are implemented. Since kernel version 2.4, a
80file system can be mounted as many times and in as many places as you like,
81thus it's not a problem that these file systems are already mounted on your
82host system, especially so because they are virtual file systems.</para>
83
84<para>First become <emphasis>root</emphasis>, as only <emphasis>root</emphasis>
85can mount file systems in unusual places. Then check again that the LFS
86environment variable is set correctly by running <userinput>echo
87$LFS</userinput> and making sure it shows the path to your LFS partition's
88mount point, which is <filename class="directory">/mnt/lfs</filename> if you
89followed our example.</para>
90
91<para>Now make the mount points for these filesystems:</para>
92
93<screen><userinput>mkdir -p $LFS/{proc,dev/pts}</userinput></screen>
94
95<para>Mount the <emphasis>proc</emphasis> file system with:</para>
96
97<screen><userinput>mount proc $LFS/proc -t proc</userinput></screen>
98
99<para>And mount the <emphasis>devpts</emphasis> file system with:</para>
100
101<screen><userinput>mount devpts $LFS/dev/pts -t devpts</userinput></screen>
102
103<para>This last command might fail with an error like:</para>
104
105<blockquote><screen>filesystem devpts not supported by kernel</screen></blockquote>
106
107<para>The most likely cause for this is that your host system's kernel was
108compiled without support for the devpts file system (you can check which file
109systems your kernel supports with <command>cat /proc/filesystems</command>,
110for example). A few PTYs are needed to be able to run the suites for Binutils
111and GCC later on. If your kernel does not support devpts, do not worry, there
112is another way to get them working inside the chroot environment. We'll cover
113this shortly in the <xref linkend="ch-system-MAKEDEV"/> section.</para>
114
115<para>Remember that if for any reason you stop working on your LFS, and start
116again later, it's important to check that these file systems are mounted again
117before entering the chroot environment, otherwise problems could occur.</para>
118
119</sect1>
120
121
122<sect1 id="ch-system-chroot">
123<title>Entering the chroot environment</title>
124<?dbhtml filename="chroot.html" dir="chapter06"?>
125
126<para>It is time to enter the chroot environment in order to begin building
127and installing your final LFS system. Still as <emphasis>root</emphasis> run
128the following command to enter the small world that is, at the moment,
129populated with only the temporary tools:</para>
130
131<screen><userinput>chroot $LFS /tools/bin/env -i \
132&nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
133&nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
134&nbsp;&nbsp;&nbsp;&nbsp;/tools/bin/bash +h</userinput></screen>
135
136<para>The <emphasis>-i</emphasis> option passed to the <command>env</command>
137command will clear all variables of the chroot environment. After that, only
138the HOME, TERM, PS1 and PATH variables are set again. The HOME variable is set
139mainly to prevent several small warnings during the configure runs of
140Diffutils, Grep and Grub. The TERM variable is set to make programs such as
141<command>less</command> and <command>vim</command>, that make use of the
142Ncurses package, operate properly -- the TERM=$TERM construct sets the TERM
143variable inside chroot to the same value as outside chroot. The main prompt
144(PS1) is set to "username:working-dir# " (since the "\$" becomes "#" for root).
145If you need other variables present, such as CFLAGS, CXXFLAGS or LDFLAGS, this
146is a good place to set them.</para>
147
148<para>From this point on there's no need to use the LFS variable anymore,
149because everything you do will be restricted to the LFS file system -- since
150what the shell thinks is <filename class="directory">/</filename> is actually
151the value of <filename class="directory">$LFS</filename>, which was passed to
152the chroot command.</para>
153
154<para>Notice that <filename class="directory">/tools/bin</filename> comes
155last in the PATH. This means that a temporary tool will not be used any more
156as soon as its final version is installed. Well, at least when the shell
157doesn't remember the locations of executed binaries -- for this reason hashing
158is switched off by passing the <emphasis>+h</emphasis> option to
159<command>bash</command>.</para>
160
161<para>You have to make sure all the commands in the rest of this chapter and
162in the following chapters are run from within the chroot environment.
163If you ever leave this environment for any reason (rebooting for example),
164you must remember to first mount the proc and devpts file systems (discussed
165in the previous section) <emphasis>and</emphasis> enter chroot again before
166continuing with the installations.</para>
167
168<para>Note that the bash prompt will say "I have no name!" This is normal, as
169the <filename>/etc/passwd</filename> file has not been created yet.</para>
170
171</sect1>
172
173
174<sect1 id="ch-system-changingowner">
175<title>Changing ownership</title>
176<?dbhtml filename="changingowner.html" dir="chapter06"?>
177
178<para>Right now the <filename class="directory">/tools</filename> directory
179is owned by the user <emphasis>lfs</emphasis>, a user that exists only on your
180host system. Although you will probably want to delete the
181<filename class="directory">/tools</filename> directory once you have
182finished your LFS system, you may want to keep it around, for example to
183build more LFS systems. But if you keep the
184<filename class="directory">/tools</filename> directory as it is, you end up
185with files owned by a user ID without a corresponding account. This is
186dangerous because a user account created later on could get this same user ID
187and would suddenly own the <filename class="directory">/tools</filename>
188directory and all the files therein, thus exposing these files to possible
189malicious manipulation.</para>
190
191<para>To avoid this issue, you could add the <emphasis>lfs</emphasis> user to
192your new LFS system later on when creating the <filename>/etc/passwd</filename>
193file, taking care to assign it the same user and group IDs as on your host
194system. Alternatively, you can (and the book assumes you do) assign the
195contents of the <filename class="directory">/tools</filename> directory to
196user <emphasis>root</emphasis> by running the following command:</para>
197
198<screen><userinput>chown -R 0:0 /tools</userinput></screen>
199
200<para>The command uses "0:0" instead of "root:root", because
201<userinput>chown</userinput> is unable to resolve the name "root" until the
202password file has been created.</para>
203
204</sect1>
205
206
207<sect1 id="ch-system-creatingdirs">
208<title>Creating directories</title>
209<?dbhtml filename="creatingdirs.html" dir="chapter06"?>
210
211<para>Let's now create some structure in our LFS file system. Let's create
212a directory tree. Issuing the following commands will create a more or less
213standard tree:</para>
214
215<screen><userinput>mkdir -p /{bin,boot,dev/{pts,shm},etc/opt,home,lib,mnt,proc}
216mkdir -p /{root,sbin,tmp,usr/local,var,opt}
217mkdir /usr/{bin,include,lib,sbin,share,src}
218ln -s share/{man,doc,info} /usr
219mkdir /usr/share/{doc,info,locale,man}
220mkdir /usr/share/{misc,terminfo,zoneinfo}
221mkdir /usr/share/man/man{1,2,3,4,5,6,7,8}
222mkdir /usr/local/{bin,etc,include,lib,sbin,share,src}
223ln -s share/{man,doc,info} /usr/local
224mkdir /usr/local/share/{doc,info,locale,man}
225mkdir /usr/local/share/{misc,terminfo,zoneinfo}
226mkdir /usr/local/share/man/man{1,2,3,4,5,6,7,8}
227mkdir /var/{lock,log,mail,run,spool}
228mkdir -p /var/{tmp,opt,cache,lib/misc,local}
229mkdir /opt/{bin,doc,include,info}
230mkdir -p /opt/{lib,man/man{1,2,3,4,5,6,7,8}}</userinput></screen>
231
232<para>Directories are, by default, created with permission mode 755, but this
233isn't desirable for all directories. We will make two changes: one to the home
234directory of <emphasis>root</emphasis>, and another to the directories for
235temporary files.</para>
236
237<screen><userinput>chmod 0750 /root
238chmod 1777 /tmp /var/tmp</userinput></screen>
239
240<para>The first mode change ensures that not just anybody can enter the
241<filename class="directory">/root</filename> directory -- the same
242as a normal user would do with his or her home directory.
243The second mode change makes sure that any user can write to the
244<filename class="directory">/tmp</filename> and
245<filename class="directory">/var/tmp</filename> directories, but
246cannot remove other users' files from them. The latter is prohibited
247by the so-called "sticky bit" -- the highest bit in the 1777 bit mask.</para>
248
249<sect2>
250<title>FHS compliance note</title>
251
252<para>We have based our directory tree on the FHS standard (available at
253<ulink url="http://www.pathname.com/fhs/"/>). Besides the above created
254tree this standard stipulates the existence of
255<filename class="directory">/usr/local/games</filename> and
256<filename class="directory">/usr/share/games</filename>, but we don't
257much like these for a base system. However, feel free to make your system
258FHS-compliant. As to the structure of the
259<filename class="directory">/usr/local/share</filename> subdirectory, the FHS
260isn't precise, so we created here the directories that we think are needed.</para>
261
262</sect2>
263
264</sect1>
265
266
267<sect1 id="ch-system-createfiles">
268<title>Creating essential symlinks</title>
269<?dbhtml filename="createfiles.html" dir="chapter06"?>
270
271<para>Some programs hard-wire paths to programs which don't exist yet. In
272order to satisfy these programs, we create a number of symbolic links which
273will be replaced by real files throughout the course of this chapter when
274we're installing all the software.</para>
275
276<screen><userinput>ln -s /tools/bin/{bash,cat,pwd,stty} /bin
277ln -s /tools/bin/perl /usr/bin
278ln -s /tools/lib/libgcc_s.so.1 /usr/lib
279ln -s bash /bin/sh</userinput></screen>
280
281</sect1>
282
283
284<sect1 id="ch-system-pwdgroup">
285<title>Creating the passwd, group and log files</title>
286<?dbhtml filename="pwdgroup.html" dir="chapter06"?>
287
288<para>In order for <emphasis>root</emphasis> to be able to login and for the
289name "root" to be recognized, there need to be relevant entries in the
290<filename>/etc/passwd</filename> and <filename>/etc/group</filename> files.</para>
291
292<para>Create the <filename>/etc/passwd</filename> file by running the following
293command:</para>
294
295<screen><userinput>cat &gt; /etc/passwd &lt;&lt; "EOF"</userinput>
296root:x:0:0:root:/root:/bin/bash
297<userinput>EOF</userinput></screen>
298
299<para>The actual password for <emphasis>root</emphasis> (the "x" here is just a
300placeholder) will be set later.</para>
301
302<para>Create the <filename>/etc/group</filename> file by running the following
303command:</para>
304
305<screen><userinput>cat &gt; /etc/group &lt;&lt; "EOF"</userinput>
306root:x:0:
307bin:x:1:
308sys:x:2:
309kmem:x:3:
310tty:x:4:
311tape:x:5:
312daemon:x:6:
313floppy:x:7:
314disk:x:8:
315lp:x:9:
316dialout:x:10:
317audio:x:11:
318<userinput>EOF</userinput></screen>
319
320<para>The created groups aren't part of any standard -- they are some of the
321groups that the <command>make_devices</command> script in the next section
322uses. The LSB (<ulink url="http://www.linuxbase.org/">Linux Standard
323Base</ulink>) recommends only that, beside the group "root" with a GID of 0, a
324group "bin" with a GID of 1 be present. All other group names and GIDs can
325be chosen freely by the system administrator, since well-written packages don't
326depend on GID numbers but use the group's name.</para>
327
328<para>To get rid of the "I have no name!" prompt, we will start a new shell.
329Since we installed a full Glibc in <xref linkend="chapter-temporary-tools"/>,
330and have just created the <filename>/etc/passwd</filename> and
331<filename>/etc/group</filename> files, user name and group name resolution
332will now work.</para>
333
334<screen><userinput>exec /tools/bin/bash +h</userinput></screen>
335
336<para>Note the use of the <emphasis>+h</emphasis> directive. This tells
337<command>bash</command> not to use its internal path hashing. Without this
338directive, <command>bash</command> would remember the paths to binaries it
339has executed. Since we want to use our newly compiled binaries as soon as
340they are installed, we turn off this function for the duration of this
341chapter.</para>
342
343<para>The <command>login</command>, <command>agetty</command> and
344<command>init</command> programs (and some others) use a number of log
345files to record information such as who was logged into the system and when.
346These programs, however, won't write to the log files if they don't already
347exist. Initialize the log files and give them their proper permissions:</para>
348
349<screen><userinput>touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
350chmod 644 /var/run/utmp /var/log/{btmp,lastlog,wtmp}</userinput></screen>
351
352<para>The <filename>/var/run/utmp</filename> file records the users that are
353currently logged in. The <filename>/var/log/wtmp</filename> file records all
354logins and logouts. The <filename>/var/log/lastlog</filename> file records for
355each user when he or she last logged in. The <filename>/var/log/btmp</filename>
356file records the bad login attempts.</para>
357
358</sect1>
359
360
361&c6-makedev;
362&c6-kernel-headers;
363&c6-manpages;
364&c6-glibc;
365
366
367<sect1 id="ch-system-readjusting">
368<title>Re-adjusting the toolchain</title>
369<?dbhtml filename="readjusting.html" dir="chapter06"?>
370
371<para>Now that the new and final C libraries have been installed, it's time to
372adjust our toolchain again. We'll adjust it so that it will link any newly
373compiled program against these new libraries. This is in fact the same thing we
374did in the "Adjusting" phase in the beginning of the previous chapter, even
375though it looks like the reverse: then we guided the chain from the host's
376<filename class="directory">/{,usr/}lib</filename> to the new
377<filename class="directory">/tools/lib</filename>, now we guide it from that
378same <filename class="directory">/tools/lib</filename>
379to the LFS's <filename class="directory">/{,usr/}lib</filename>.</para>
380
381<para>First we adjust the linker. For this we retained the
382source and build directories from the second pass over Binutils. Install the
383adjusted linker by running the following from within the
384<filename class="directory">binutils-build</filename> directory:</para>
385
386<screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
387
388<note><para>If you somehow missed the earlier warning to retain the Binutils
389source and build directories from the second pass in
390<xref linkend="chapter-temporary-tools"/>, or otherwise accidentally deleted them or just
391don't have access to them, don't worry, all is not lost. Just ignore the above
392command. The result will be that the next package, Binutils, will link against
393the C libraries in <filename class="directory">/tools</filename> rather
394than in <filename class="directory">/{,usr/}lib</filename>. This is not ideal,
395however, our testing has shown that the resulting Binutils program binaries
396should be identical.</para></note>
397
398<para>From now on every compiled program will link <emphasis>only</emphasis>
399against the libraries in <filename>/usr/lib</filename> and
400<filename>/lib</filename>. The extra
401<emphasis>INSTALL=/tools/bin/install</emphasis> is needed because the Makefile
402created during the second pass still contains the reference to
403<filename>/usr/bin/install</filename>, which we obviously haven't installed yet.
404Some host distributions contain a <filename class="symlink">ginstall</filename>
405symbolic link which takes precedence in the Makefile and thus can cause a
406problem here. The above command takes care of this also.</para>
407
408<para>You must now remove the Binutils source and build directories. (This is
409important, as you should start the next section with a fresh untarring of the
410package.)</para>
411
412<para>The next thing to do is to amend our GCC specs file so that it points
413to the new dynamic linker. Just like earlier on, we use a sed to accomplish
414this:</para>
415
416<!-- Ampersands are needed to allow cut and paste -->
417
418<screen><userinput>SPECFILE=/tools/lib/gcc-lib/*/*/specs &amp;&amp;
419sed -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g' \
420&nbsp;&nbsp;&nbsp;&nbsp;$SPECFILE &gt; newspecfile &amp;&amp;
421mv -f newspecfile $SPECFILE &amp;&amp;
422unset SPECFILE</userinput></screen>
423
424<para>Again, cutting and pasting the above is recommended. And just like
425before, it is a good idea to visually inspect the specs file to verify the
426intended change was actually made.</para>
427
428<important><para>If you are working on a platform where the name of the dynamic
429linker is something other than <filename>ld-linux.so.2</filename>, you
430<emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
431name of your platform's dynamic linker in the above commands. Refer back to
432<xref linkend="tools-technicalnotes"/> if necessary.</para></important>
433
434<!-- HACK - Force some whitespace to appease tidy -->
435<literallayout></literallayout>
436
437<caution><para>It is imperative at this point to stop and ensure that the
438basic functions (compiling and linking) of the adjusted toolchain are working
439as expected. For this we are going to perform a simple sanity check:</para>
440
441<screen><userinput>echo 'main(){}' &gt; dummy.c
442cc dummy.c
443readelf -l a.out | grep ': /lib'</userinput></screen>
444
445<para>If everything is working correctly, there should be no errors, and the
446output of the last command will be (allowing for platform specific differences
447in dynamic linker name):</para>
448
449<blockquote><screen>[Requesting program interpreter: /lib/ld-linux.so.2]</screen></blockquote>
450
451<para>Note especially that <filename class="directory">/lib</filename> is now
452the prefix of our dynamic linker.</para>
453
454<para> If you did not receive the output
455as shown above, or received no output at all, then something is seriously wrong.
456You will need to investigate and retrace your steps to find out where the
457problem is and correct it. There is no point in continuing until this is done.
458Most likely something went wrong with the specs file amendment above.</para>
459
460<para>Once you are satisfied that all is well, clean up the test files:</para>
461
462<screen><userinput>rm dummy.c a.out</userinput></screen>
463</caution>
464
465<!-- HACK - Force some whitespace to appease tidy -->
466<literallayout></literallayout>
467
468</sect1>
469
470
471&c6-binutils;
472&c6-gcc;
473
474&c6-coreutils;
475&c6-zlib;
476&c6-lfs-utils;
477&c6-findutils;
478&c6-gawk;
479&c6-ncurses;
480&c6-vim;
481&c6-m4;
482&c6-bison;
483&c6-less;
484&c6-groff;
485&c6-sed;
486&c6-flex;
487&c6-gettext;
488&c6-nettools;
489&c6-inetutils;
490&c6-perl;
491&c6-texinfo;
492&c6-autoconf;
493&c6-automake;
494&c6-bash;
495&c6-file;
496&c6-libtool;
497&c6-bzip2;
498&c6-diffutils;
499&c6-ed;
500&c6-kbd;
501&c6-e2fsprogs;
502&c6-grep;
503&c6-grub;
504&c6-gzip;
505&c6-man;
506&c6-make;
507&c6-modutils;
508&c6-patch;
509&c6-procinfo;
510&c6-procps;
511&c6-psmisc;
512&c6-shadow;
513&c6-sysklogd;
514&c6-sysvinit;
515&c6-tar;
516&c6-utillinux;
517&c6-gcc-2953;
518
519
520<sect1 id="ch-system-aboutdebug">
521<title>About debugging symbols</title>
522<?dbhtml filename="aboutdebug.html" dir="chapter06"?>
523
524<para>Most programs and libraries are, by default, compiled with debugging
525symbols included (with <command>gcc</command>'s <emphasis>-g</emphasis>
526option). This means that, when debugging a program or library that was compiled
527with debugging information included, the debugger can give you not only memory
528addresses but also the names of the routines and variables.</para>
529
530<para>The inclusion of these debugging symbols, however, enlarges a program or
531library significantly. To get an idea of the amount of space these symbols
532occupy, have a look at the following:</para>
533
534<itemizedlist>
535
536<listitem><para>a bash binary
537with debugging symbols: 1200 KB</para></listitem>
538
539<listitem><para>a bash binary
540without debugging symbols: 480 KB</para></listitem>
541
542<listitem><para>Glibc and GCC files (/lib and /usr/lib)
543with debugging symbols: 87 MB</para></listitem>
544
545<listitem><para>Glibc and GCC files
546without debugging symbols: 16 MB</para></listitem>
547
548</itemizedlist>
549
550<para>Sizes may vary somewhat, depending on which compiler was used and which C
551library, but when comparing programs with and without debugging symbols the
552difference will generally be a factor between 2 and 5.</para>
553
554<para>As most people will probably never use a debugger on their system
555software, a lot of disk space can be regained by removing these symbols. For
556your convenience, the next section shows how to strip all debugging symbols
557from all programs and libraries. Information on other ways of optimizing your
558system can be found in the hint at <ulink
559url="&hints-root;optimization.txt"/>.</para>
560
561</sect1>
562
563
564<sect1 id="ch-system-strippingagain">
565<title>Stripping again</title>
566<?dbhtml filename="strippingagain.html" dir="chapter06"?>
567
568<para>If you are not a programmer and don't plan to do any debugging on your
569system software, you can shrink your system by about 200 MB by removing the
570debugging symbols from binaries and libraries. This causes no inconvenience
571other than not being able to debug the software fully any more.</para>
572
573<para>Most people who use the command mentioned below don't experience any
574problems. But it is easy to make a typo and render your new system unusable, so
575before running the strip command it is probably a good idea to make a backup of
576the current situation.</para>
577
578<para>If you are going to perform the stripping, special care is needed to
579ensure you're not running any of the binaries that are about to be stripped.
580If you're not sure whether you entered chroot with the command given in
581<xref linkend="ch-system-chroot"/>, then first exit from chroot:</para>
582
583<screen><userinput>logout</userinput></screen>
584
585<para>Then reenter it with:</para>
586
587<screen><userinput>chroot $LFS /tools/bin/env -i \
588&nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
589&nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin \
590&nbsp;&nbsp;&nbsp;&nbsp;/tools/bin/bash</userinput></screen>
591
592<para>Now you can safely strip the binaries and libraries:</para>
593
594<screen><userinput>/tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
595&nbsp;&nbsp;&nbsp;-exec /tools/bin/strip --strip-debug '{}' ';'</userinput></screen>
596
597<para>A large number of files will be reported as having their file format not
598recognized. These warnings can be safely ignored, they just mean that those
599files are scripts instead of binaries, no harm is done.</para>
600
601<para>If you are really tight on disk space, you may want to use
602<emphasis>--strip-all</emphasis> on the binaries in
603<filename>/{,usr/}{bin,sbin}</filename> to gain several more megabytes. But do
604<emphasis>not</emphasis> use this option on libraries: they would be
605destroyed.</para>
606
607</sect1>
608
609
610<sect1 id="ch-system-revisedchroot">
611<title>Cleaning up</title>
612<?dbhtml filename="revisedchroot.html" dir="chapter06"?>
613
614<para>From now on, when you exit the chroot environment and wish to reenter
615it, you should use the following modified chroot command:</para>
616
617<screen><userinput>chroot $LFS /usr/bin/env -i \
618&nbsp;&nbsp;&nbsp;&nbsp;HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
619&nbsp;&nbsp;&nbsp;&nbsp;PATH=/bin:/usr/bin:/sbin:/usr/sbin \
620&nbsp;&nbsp;&nbsp;&nbsp;/bin/bash</userinput></screen>
621
622<para>The reason for this is that, since the programs in <filename
623class="directory">/tools</filename> are no longer needed, you may want to
624delete the whole directory and regain the space. Before actually deleting the
625directory, exit from chroot and reenter it with the above command. Also, before
626removing <filename class="directory">/tools</filename>, you may want to tar it
627up and store it in a safe place, in case you want to build another LFS system
628soon.</para>
629
630<note><para>Removing <filename class="directory">/tools</filename> will also
631remove the temporary copies of Tcl, Expect and DejaGnu, which were used for
632running the toolchain tests. If you want to use these programs later on, you
633will need to recompile and re-install them. The installation instructions are
634the same as in <xref linkend="chapter-temporary-tools"/>, apart from changing
635the prefix from <emphasis>/tools</emphasis> to <emphasis>/usr</emphasis>. The
636BLFS book discusses a slightly different approach to installing Tcl, see <ulink
637url="&blfs-root;"/>.</para></note>
638
639<para>You may also want to move the packages and patches stored in <filename
640class="directory">/sources</filename> to a more usual location, such as
641<filename class="directory">/usr/src/packages</filename>, and remove the
642directory -- or simply delete the whole directory if you've burned its contents
643on a CD).</para>
644
645</sect1>
646
647</chapter>
648
Note: See TracBrowser for help on using the repository browser.