stripping.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-tools-stripping">
  8. <?dbhtml filename="stripping.html"?>
  9. <title>Cleaning up and Saving the Temporary System</title>
  10. <para>The libtool .la files are only useful when linking with static
  11. libraries. They are unneeded, and potentially harmful, when using dynamic
  12. shared libraries, specially when using non-autotools build systems.
  13. While still in chroot, remove those files now:</para>
  14. <screen><userinput>find /usr/{lib,libexec} -name \*.la -delete</userinput></screen>
  15. <note><para>
  16. All the remaining steps in this section are optional. Nevertheless,
  17. as soon as you begin installing packages in <xref
  18. linkend="chapter-building-system"/>, the temporary tools will be
  19. overwritten. So it may be a good idea to do a backup of the temporary
  20. tools as described below. The other steps are only needed if you are
  21. really short on disk space.
  22. </para></note>
  23. <para>
  24. The following steps are performed from outside the chroot
  25. environment. That means, you have to leave the chroot environment
  26. first before continuing. The reason for that is to:
  27. <itemizedlist>
  28. <listitem>
  29. <para>
  30. make sure that objects are not in use while they are
  31. manipulated.
  32. </para>
  33. </listitem>
  34. <listitem>
  35. <para>
  36. get access to file system locations outside of the chroot
  37. environment to store/read the backup archive which should
  38. not be placed within the
  39. <filename class="directory">$LFS</filename> hierarchy for
  40. safety reasons.
  41. </para>
  42. </listitem>
  43. </itemizedlist>
  44. </para>
  45. <para>
  46. Leave the chroot environment and unmount the kernel virtual file
  47. systems:
  48. </para>
  49. <note>
  50. <para>All of the following instructions are executed by
  51. <systemitem class="username">root</systemitem>. Take extra
  52. care about the commands you're going to run as mistakes
  53. here can modify your host system. Be aware that the
  54. environment variable <envar>LFS</envar> is set for user
  55. <systemitem class="username">lfs</systemitem> by default
  56. but it might <emphasis>not</emphasis> be set for
  57. <systemitem class="username">root</systemitem>. Whenever
  58. commands are to be executed by <systemitem class="username">root</systemitem>,
  59. make sure you have set <envar>LFS</envar> accordingly.
  60. This has been discussed in <xref linkend='ch-partitioning-aboutlfs'/>.
  61. </para>
  62. </note>
  63. <screen role="nodump"><userinput>exit
  64. umount $LFS/dev{/pts,}
  65. umount $LFS/{sys,proc,run}</userinput></screen>
  66. <sect2>
  67. <title>Stripping</title>
  68. <para>If the LFS partition is rather small, it is good to
  69. know that unnecessary items can be removed. The executables and
  70. libraries built so far contain a little over 90 MB of unneeded debugging
  71. symbols.</para>
  72. <para>Strip off debugging symbols from binaries:</para>
  73. <screen role="nodump"><userinput>strip --strip-debug $LFS/usr/lib/*
  74. strip --strip-unneeded $LFS/usr/{,s}bin/*
  75. strip --strip-unneeded $LFS/tools/bin/*</userinput></screen>
  76. <para>These commands will skip a number of files reporting that it does not
  77. recognize their file format. Most of these are scripts instead of binaries.
  78. <!--Note that we use the <command>strip</command> program built in
  79. <quote>Binutils pass 2</quote>, since it is the one that knows how to strip
  80. our cross-compiled programs.--></para>
  81. <para>Take care <emphasis>NOT</emphasis> to use
  82. <parameter>--strip-unneeded</parameter> on the libraries. The static
  83. ones would be destroyed and the toolchain packages would need to be
  84. built all over again.</para>
  85. <para>To save more space (slightly more than 35 MB), remove the documentation:</para>
  86. <screen role="nodump"><userinput>rm -rf $LFS/usr/share/{info,man,doc}</userinput></screen>
  87. <para>At this point, you should have at least 5 GB of free space on the
  88. chroot partition that can be used to build and install Glibc and GCC in
  89. the next phase. If you can build and install Glibc, you can build and install
  90. the rest too. You can check the free disk space with the command
  91. <command>df -h $LFS</command>.</para>
  92. </sect2>
  93. <sect2>
  94. <title>Backup</title>
  95. <para>
  96. Now that the essential tools have been created, its time to think about
  97. a backup. When every check has passed successfully in the previously
  98. built packages, your temporary tools are in a good state and might be
  99. backed up for later reuse. In case of fatal failures in the subsequent
  100. chapters, it often turns out that removing everything and starting over
  101. (more carefully) is the best option to recover. Unfortunately, all the
  102. temporary tools will be removed, too. To avoid spending extra time to
  103. redo something which has been built successfully, prepare a backup.
  104. </para>
  105. <para>
  106. Make sure you have at least 600 MB free disk space (the source tarballs
  107. will be included in the backup archive) in the home directory of user
  108. <systemitem class="username">root</systemitem>.
  109. </para>
  110. <para>
  111. Create the backup archive by running the following command:
  112. </para>
  113. <screen role="nodump" revision="sysv"><userinput>cd $LFS &amp;&amp;
  114. tar -cJpf $HOME/lfs-temp-tools-&version;.tar.xz .</userinput></screen>
  115. <screen role="nodump" revision="systemd"><userinput>cd $LFS &amp;&amp;
  116. tar -cJpf $HOME/lfs-temp-tools-&versiond;.tar.xz .</userinput></screen>
  117. <para>
  118. Replace <envar>$HOME</envar> by a directory of your choice if you
  119. do not want to have the backup stored in <systemitem
  120. class="username">root</systemitem>'s home directory.
  121. </para>
  122. </sect2>
  123. <sect2>
  124. <title>Restore</title>
  125. <para>
  126. In case some mistakes have been made and you need to start over, you can
  127. use this backup to restore the temporary tools and save some recovery time.
  128. Since the sources are located under
  129. <filename class="directory">$LFS</filename>, they are included in the
  130. backup archive as well, so they do not need to be downloaded again. After
  131. checking that <envar>$LFS</envar> is set properly,
  132. restore the backup by executing the following commands:
  133. </para>
  134. <!-- Make the following look different so users don't blindly run the
  135. restore when they don't need to. -->
  136. <screen role="nodump" revision="sysv"><computeroutput>cd $LFS &amp;&amp;
  137. rm -rf ./* &amp;&amp;
  138. tar -xpf $HOME/lfs-temp-tools-&version;.tar.xz</computeroutput></screen>
  139. <screen role="nodump" revision="systemd"><computeroutput>cd $LFS &amp;&amp;
  140. rm -rf ./* &amp;&amp;
  141. tar -xpf $HOME/lfs-temp-tools-&versiond;.tar.xz</computeroutput></screen>
  142. <para>
  143. Again, double check that the environment has been setup properly
  144. and continue building the rest of the system.
  145. </para>
  146. <important>
  147. <para>
  148. If you left the chroot environment either to strip off debug
  149. symbols, create a backup, or restart building using a restore,
  150. remember to mount the kernel virtual filesystems now again as
  151. described in <xref linkend='ch-tools-kernfs'/> and re-enter
  152. the chroot environment (see <xref linkend='ch-tools-chroot'/>)
  153. again before continuing.
  154. </para>
  155. </important>
  156. </sect2>
  157. </sect1>