stripping.xml 7.4 KB

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