stripping.xml 7.2 KB

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