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