source: chapter07/stripping.xml@ 07bf061

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 07bf061 was 9d8bf7e, checked in by Xi Ruoyao <xry111@…>, 4 years ago

chap7/stripping: when refering $LFS as an envar, use <envar> instead of <filename>

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@11968 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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