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. <note><para>
  11. All the steps in this section are optional. Nevertheless, as soon
  12. as you begin installing packages in <xref
  13. linkend="chapter-building-system"/>, the temporary tools will be
  14. overwritten. So it may be a good idea to do a backup of the temporary
  15. tools as described below. The other steps are only needed if you are
  16. really short on disk space.
  17. </para></note>
  18. <para>
  19. The following steps are performed from outside the chroot
  20. environment. That means, you have to leave the chroot environment
  21. first before continuing. The reason for that is to:
  22. <itemizedlist>
  23. <listitem>
  24. <para>
  25. make sure that objects are not in use while they are
  26. manipulated.
  27. </para>
  28. </listitem>
  29. <listitem>
  30. <para>
  31. get access to file system locations outside of the chroot
  32. environment to store/read the backup archive which should
  33. not be placed within the
  34. <filename class="directory">$LFS</filename> hierarchy for
  35. safety reasons.
  36. </para>
  37. </listitem>
  38. </itemizedlist>
  39. </para>
  40. <para>
  41. Leave the chroot environment and unmount the kernel virtual file
  42. systems:
  43. </para>
  44. <note>
  45. <para>All of the following instructions are executed by
  46. <systemitem class="username">root</systemitem>. Take extra
  47. care about the commands you're going to run as mistakes
  48. here can modify your host system. Be aware that the
  49. environment variable <envar>LFS</envar> is set for user
  50. <systemitem class="username">lfs</systemitem> by default
  51. but it might <emphasis>not</emphasis> be set for
  52. <systemitem class="username">root</systemitem>. Whenever
  53. commands are to be executed by <systemitem class="username">root</systemitem>,
  54. make sure you have set <envar>LFS</envar> accordingly.
  55. This has been discussed in <xref linkend='ch-partitioning-aboutlfs'/>.
  56. </para>
  57. </note>
  58. <screen role="nodump"><userinput>exit
  59. umount $LFS/dev{/pts,}
  60. umount $LFS/{sys,proc,run}</userinput></screen>
  61. <sect2>
  62. <title>Stripping</title>
  63. <para>If the LFS partition is rather small, it is good to
  64. know that unnecessary items can be removed. The executables and
  65. libraries built so far contain a little over 90 MB of unneeded debugging
  66. symbols.</para>
  67. <para>Strip off debugging symbols from binaries:</para>
  68. <screen role="nodump"><userinput>strip --strip-debug $LFS/usr/lib/*
  69. strip --strip-unneeded $LFS/usr/{,s}bin/*
  70. strip --strip-unneeded $LFS/tools/bin/*</userinput></screen>
  71. <para>These commands will skip a number of files reporting that it does not
  72. recognize their file format. Most of these are scripts instead of binaries.
  73. <!--Note that we use the <command>strip</command> program built in
  74. <quote>Binutils pass 2</quote>, since it is the one that knows how to strip
  75. our cross-compiled programs.--></para>
  76. <para>Take care <emphasis>NOT</emphasis> to use
  77. <parameter>--strip-unneeded</parameter> on the libraries. The static
  78. ones would be destroyed and the toolchain packages would need to be
  79. built all over again.</para>
  80. <para>To save more space (slightly more than 35 MB), remove the documentation:</para>
  81. <screen role="nodump"><userinput>rm -rf $LFS/usr/share/{info,man,doc}</userinput></screen>
  82. <para>The libtool .la files are only useful when linking with static
  83. libraries. They are unneeded, and potentially harmful, when using dynamic
  84. shared libraries, specially when using non-autotools build systems.
  85. Remove those files now:</para>
  86. <screen role="nodump"><userinput>find $LFS/usr/{lib,libexec} -name \*.la -delete</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>