chapter06.xml 28 KB

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