stripping.xml 8.3 KB

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