source: chapter08/pkgmgt.xml@ 092b86a

12.1 12.1-rc1 multilib trunk xry111/arm64 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.1 xry111/mips64el
Last change on this file since 092b86a was d3b0a08, checked in by Xi Ruoyao <xry111@…>, 3 months ago

pkgmgt: Upgrading Linux API headers cannot be dangerous

Per a discussion in the team, we only consider an upgradation dangerous
if it may render the system unusable. "Causing something not able to
build" is never considered dangerous. Thus upgrading some headers
cannot be dangerous.

The Glibc portion will need an update too (it can be upgraded safely
with some caution) to ease security updates. But let's do the easy
change first...

  • Property mode set to 100644
File size: 19.5 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
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-system-pkgmgt">
9 <?dbhtml filename="pkgmgt.html"?>
10
11 <title>Package Management</title>
12
13 <para>Package Management is an often requested addition to the LFS Book. A
14 Package Manager tracks the installation of files, making it easier to
15 remove and upgrade packages. A good package manager will also handle the
16 configuration files specially to keep the user configuration when the
17 package is reinstalled or upgraded. Before
18 you begin to wonder, NO&mdash;this section will not talk about nor recommend
19 any particular package manager. What it does provide is a roundup of the more
20 popular techniques and how they work. The perfect package manager for you may
21 be among these techniques, or it may be a combination of two or more of these
22 techniques. This section briefly mentions issues that may arise when upgrading
23 packages.</para>
24
25 <para>Some reasons why no package manager is mentioned in LFS or BLFS
26 include:</para>
27
28 <itemizedlist>
29 <listitem>
30 <para>Dealing with package management takes the focus away from the goals
31 of these books&mdash;teaching how a Linux system is built.</para>
32 </listitem>
33
34 <listitem>
35 <para>There are multiple solutions for package management, each having
36 its strengths and drawbacks. Finding one solution that satisfies all audiences
37 is difficult.</para>
38 </listitem>
39 </itemizedlist>
40
41 <para>There are some hints written on the topic of package management. Visit
42 the <ulink url="&hints-root;">Hints Project</ulink> and see if one of them
43 fits your needs.</para>
44
45 <sect2 id='pkgmgmt-upgrade-issues'>
46 <title>Upgrade Issues</title>
47
48 <para>A Package Manager makes it easy to upgrade to newer versions when they
49 are released. Generally the instructions in the LFS and BLFS books can be
50 used to upgrade to the newer versions. Here are some points that you should
51 be aware of when upgrading packages, especially on a running system.</para>
52
53 <itemizedlist>
54 <listitem>
55 <para>If the Linux kernel needs to be upgraded (for example, from
56 5.10.17 to 5.10.18 or 5.11.1), nothing else needs to be rebuilt.
57 The system will keep working fine thanks to the well-defined interface
58 between the kernel and userspace. Specifically, Linux API headers
59 need not be upgraded
60 along with the kernel. You will merely need to reboot your system to use the
61 upgraded kernel.</para>
62 </listitem>
63
64 <listitem>
65 <para>If Glibc needs to be upgraded to a newer
66 version, (e.g., from Glibc-2.31 to Glibc-2.32), it is safer to
67 rebuild LFS. Though you <emphasis>may</emphasis> be able to rebuild
68 all the packages in their dependency order, we do not recommend
69 it. </para>
70 </listitem>
71
72 <listitem>
73 <para>Reinstalling the same version of Glibc (&glibc-version; for
74 this release of LFS) with patches should be safe when these patches
75 do not change ABI and API. When a security vulnerability is found
76 in Glibc, we often need to apply such a patch to fix the
77 vulnerability and reinstall Glibc. Consult
78 <ulink url='&lfs-root;lfs/advisories/'>LFS security
79 advisories</ulink> if you are alerted for a published Glibc security
80 vulnerability but unsure about the action to take.</para>
81 </listitem>
82
83 <listitem> <para>If a package containing a shared library is updated, and
84 if the name of the library changes, then any packages dynamically
85 linked to the library must be recompiled, to link against the
86 newer library. (Note that there is no correlation between the package
87 version and the name of the library.) For example, consider a package
88 foo-1.2.3 that installs a shared library with the name <filename
89 class='libraryfile'>libfoo.so.1</filename>. Suppose you upgrade the package to
90 a newer version foo-1.2.4 that installs a shared library with the name
91 <filename class='libraryfile'>libfoo.so.2</filename>. In this case, any
92 packages that are dynamically linked to <filename
93 class='libraryfile'>libfoo.so.1</filename> need to be recompiled to link
94 against <filename class='libraryfile'>libfoo.so.2</filename> in order to
95 use the new library version. You should not remove the old
96 libraries until all the dependent packages have been recompiled.</para>
97 </listitem>
98
99 <listitem><para>If a package is (directly or indirectly) linked to both
100 the old and new names of a shared library (for example, the package
101 links to both <filename class='libraryfile'>libfoo.so.2</filename> and
102 <filename class='libraryfile'>libbar.so.1</filename>, while the latter
103 links to <filename class='libraryfile'>libfoo.so.3</filename>), the
104 package may malfunction because the different revisions of the shared
105 library present incompatible definitions for some symbol names. This can be
106 caused by recompiling some, but not all, of the packages linked to the
107 old shared library after the package providing the shared library is
108 upgraded. To avoid the issue, users will need to rebuild every package
109 linked to a shared library with an updated revision (e.g. libfoo.so.2 to
110 libfoo.so.3) as soon as possible.
111 </para></listitem>
112
113 <listitem> <para>If a package containing a shared library is updated,
114 and the name of the library doesn't change, but the version number of the
115 library <emphasis role="bold">file</emphasis> decreases (for example,
116 the library is still named
117 <filename class='libraryfile'>libfoo.so.1</filename>,
118 but the name of the library file is changed from
119 <filename class='libraryfile'>libfoo.so.1.25</filename> to
120 <filename class='libraryfile'>libfoo.so.1.24</filename>),
121 you should remove the library file from the previously installed version
122 (<filename class='libraryfile'>libfoo.so.1.25</filename> in this case).
123 Otherwise, a <command>ldconfig</command> command (invoked by yourself from the command
124 line, or by the installation of some package) will reset the symlink
125 <filename class='libraryfile'>libfoo.so.1</filename> to point to
126 the old library file because it seems to be a <quote>newer</quote>
127 version; its version number is larger. This situation may arise if
128 you have to downgrade a package, or if the authors change the versioning
129 scheme for library files.</para> </listitem>
130
131 <listitem><para>If a package containing a shared library is updated,
132 and the name of the library doesn't change, but a severe issue
133 (especially, a security vulnerability) is fixed, all running programs
134 linked to the shared library should be restarted. The following
135 command, run as <systemitem class="username">root</systemitem> after
136 the update is complete, will list which processes are using the old versions of those libraries
137 (replace <replaceable>libfoo</replaceable> with the name of the
138 library):</para>
139
140<screen role="nodump"><userinput>grep -l '<replaceable>libfoo</replaceable>.*deleted' /proc/*/maps | tr -cd 0-9\\n | xargs -r ps u</userinput></screen>
141
142 <para>
143 If <application>OpenSSH</application> is being used to access
144 the system and it is linked to the updated library, you must
145 restart the <command>sshd</command> service, then logout, login again,
146 and run the preceding command again to confirm that nothing is still using the
147 deleted libraries.
148 </para>
149
150 <para revision='systemd'>
151 If the <command>systemd</command> daemon (running as PID 1) is
152 linked to the updated library, you can restart it without rebooting
153 by running <command>systemctl daemon-reexec</command> as the
154 <systemitem class='username'>root</systemitem> user.
155 </para></listitem>
156
157 <listitem>
158 <para>If an executable program or a shared library is overwritten, the processes
159 using the code or data in that program or library may crash. The
160 correct way to update a program or a shared library without causing
161 the process to crash is to remove it first, then install the new
162 version. The <command>install</command> command
163 provided by <application>coreutils</application> has already
164 implemented this, and most packages use that command to install binary files and
165 libraries. This means that you won't be troubled by this issue most of the time.
166 However, the install process of some packages (notably SpiderMonkey
167 in BLFS) just overwrites the file if it exists; this causes a crash. So
168 it's safer to save your work and close unneeded running processes
169 before updating a package.</para> <!-- binary is an adjective, not a noun. -->
170 </listitem>
171 </itemizedlist>
172
173 </sect2>
174
175 <sect2>
176 <title>Package Management Techniques</title>
177
178 <para>The following are some common package management techniques. Before
179 making a decision on a package manager, do some research on the various
180 techniques, particularly the drawbacks of each particular scheme.</para>
181
182 <sect3>
183 <title>It is All in My Head!</title>
184
185 <para>Yes, this is a package management technique. Some folks do not
186 need a package manager because they know the packages intimately
187 and know which files are installed by each package. Some users also do not
188 need any package management because they plan on rebuilding the entire
189 system whenever a package is changed.</para>
190
191 </sect3>
192
193 <sect3>
194 <title>Install in Separate Directories</title>
195
196 <para>This is a simplistic package management technique that does not need a
197 special program to manage the packages. Each package is installed in a
198 separate directory. For example, package foo-1.1 is installed in
199 <filename class='directory'>/opt/foo-1.1</filename>
200 and a symlink is made from <filename>/opt/foo</filename> to
201 <filename class='directory'>/opt/foo-1.1</filename>. When
202 a new version foo-1.2 comes along, it is installed in
203 <filename class='directory'>/opt/foo-1.2</filename> and the previous
204 symlink is replaced by a symlink to the new version.</para>
205
206 <para>Environment variables such as <envar>PATH</envar>,
207 <envar>MANPATH</envar>, <envar>INFOPATH</envar>,
208 <envar>PKG_CONFIG_PATH</envar>, <envar>CPPFLAGS</envar>,
209 <envar>LDFLAGS</envar>, and the configuration file
210 <filename>/etc/ld.so.conf</filename> may need to be expanded to
211 include the corresponding subdirectories in
212 <filename class='directory'>/opt/foo-x.y</filename>.</para>
213
214 <para>
215 This scheme is used by the BLFS book to install some very large
216 packages to make it easier to upgrade them. If you install more
217 than a few packages, this scheme becomes unmanageable. And some
218 packages (for example Linux API headers and Glibc) may not work well
219 with this scheme.
220 <emphasis role='bold'>Never use this scheme system-wide.</emphasis>
221 </para>
222 </sect3>
223
224 <sect3>
225 <title>Symlink Style Package Management</title>
226
227 <para>This is a variation of the previous package management technique.
228 Each package is installed as in the previous scheme. But instead of
229 making the symlink via a generic package name, each file is symlinked into the
230 <filename class='directory'>/usr</filename> hierarchy. This removes the
231 need to expand the environment variables. Though the symlinks can be
232 created by the user, many package managers use this approach, and
233 automate the creation of the symlinks. A few of the popular ones include Stow,
234 Epkg, Graft, and Depot.</para>
235
236 <para>The installation script needs to be fooled, so the package thinks
237 it is installed in <filename class="directory">/usr</filename> though in
238 reality it is installed in the
239 <filename class="directory">/usr/pkg</filename> hierarchy. Installing in
240 this manner is not usually a trivial task. For example, suppose you
241 are installing a package libfoo-1.1. The following instructions may
242 not install the package properly:</para>
243
244<screen role="nodump"><userinput>./configure --prefix=/usr/pkg/libfoo/1.1
245make
246make install</userinput></screen>
247
248 <para>The installation will work, but the dependent packages may not link
249 to libfoo as you would expect. If you compile a package that links against
250 libfoo, you may notice that it is linked to
251 <filename class='libraryfile'>/usr/pkg/libfoo/1.1/lib/libfoo.so.1</filename>
252 instead of <filename class='libraryfile'>/usr/lib/libfoo.so.1</filename>
253 as you would expect. The correct approach is to use the
254 <envar>DESTDIR</envar> variable to direct the installation. This
255 approach works as follows:</para>
256
257<screen role="nodump"><userinput>./configure --prefix=/usr
258make
259make DESTDIR=/usr/pkg/libfoo/1.1 install</userinput></screen>
260
261 <para>Most packages support this approach, but there are some which do not.
262 For the non-compliant packages, you may either need to install the
263 package manually, or you may find that it is easier to install some problematic
264 packages into <filename class='directory'>/opt</filename>.</para>
265
266 </sect3>
267
268 <sect3>
269 <title>Timestamp Based</title>
270
271 <para>In this technique, a file is timestamped before the installation of
272 the package. After the installation, a simple use of the
273 <command>find</command> command with the appropriate options can generate
274 a log of all the files installed after the timestamp file was created. A
275 package manager that uses this approach is install-log.</para>
276
277 <para>Though this scheme has the advantage of being simple, it has two
278 drawbacks. If, during installation, the files are installed with any
279 timestamp other than the current time, those files will not be tracked by
280 the package manager. Also, this scheme can only be used when packages
281 are installed one at a time. The logs are not reliable if two packages are
282 installed simultaneously from two different consoles.</para>
283
284 </sect3>
285
286 <sect3>
287 <title>Tracing Installation Scripts</title>
288
289 <para>In this approach, the commands that the installation scripts perform
290 are recorded. There are two techniques that one can use:</para>
291
292 <para>The <envar>LD_PRELOAD</envar> environment variable can be set to
293 point to a library to be preloaded before installation. During
294 installation, this library tracks the packages that are being installed by
295 attaching itself to various executables such as <command>cp</command>,
296 <command>install</command>, <command>mv</command> and tracking the system
297 calls that modify the filesystem. For this approach to work, all the
298 executables need to be dynamically linked without the suid or sgid bit.
299 Preloading the library may cause some unwanted side-effects during
300 installation. Therefore, it's a good idea to perform some tests to
301 ensure that the package manager does not break anything, and that it logs all the
302 appropriate files.</para>
303
304 <para>Another technique is to use <command>strace</command>, which
305 logs all the system calls made during the execution of the installation
306 scripts.</para>
307 </sect3>
308
309 <sect3>
310 <title>Creating Package Archives</title>
311
312 <para>In this scheme, the package installation is faked into a separate
313 tree as previously described in the symlink style package management section. After the
314 installation, a package archive is created using the installed files.
315 This archive is then used to install the package on the local
316 machine or even on other machines.</para>
317
318 <para>This approach is used by most of the package managers found in the
319 commercial distributions. Examples of package managers that follow this
320 approach are RPM (which, incidentally, is required by the <ulink
321 url="https://refspecs.linuxfoundation.org/lsb.shtml">Linux
322 Standard Base Specification</ulink>), pkg-utils, Debian's apt, and
323 Gentoo's Portage system. A hint describing how to adopt this style of
324 package management for LFS systems is located at <ulink
325 url="&hints-root;fakeroot.txt"/>.</para>
326
327 <para>The creation of package files that include dependency information is
328 complex, and beyond the scope of LFS.</para>
329
330 <para>Slackware uses a <command>tar</command>-based system for package
331 archives. This system purposely does not handle package dependencies
332 as more complex package managers do. For details of Slackware package
333 management, see <ulink
334 url="https://www.slackbook.org/html/package-management.html"/>.</para>
335 </sect3>
336
337 <sect3>
338 <title>User Based Management</title>
339
340 <para>This scheme, unique to LFS, was devised by Matthias Benkmann, and is
341 available from the <ulink url="&hints-root;">Hints Project</ulink>. In
342 this scheme, each package is installed as a separate user into the
343 standard locations. Files belonging to a package are easily identified by
344 checking the user ID. The features and shortcomings of this approach are
345 too complex to describe in this section. For the details please see the
346 hint at <ulink url="&hints-root;more_control_and_pkg_man.txt"/>.</para>
347
348 </sect3>
349
350 </sect2>
351
352 <sect2>
353 <title>Deploying LFS on Multiple Systems</title>
354
355 <para>One of the advantages of an LFS system is that there are no files that
356 depend on the position of files on a disk system. Cloning an LFS build to
357 another computer with the same architecture as the base system is as
358 simple as using <command>tar</command> on the LFS partition that contains
359 the root directory (about 900MB uncompressed for a basic LFS build), copying
360 <!-- D. Bryant created LFS 11.2 in October 2022; 900MB is (roughly) the size of his rsync archive. -->
361 that file via network transfer or CD-ROM / USB stick to the new system, and expanding
362 it. After that, a few configuration files will have to be changed.
363 Configuration files that may need to be updated include:
364 <filename>/etc/hosts</filename>,
365 <filename>/etc/fstab</filename>,
366 <filename>/etc/passwd</filename>,
367 <filename>/etc/group</filename>,
368 <phrase revision="systemd">
369 <filename>/etc/shadow</filename>, and
370 <filename>/etc/ld.so.conf</filename>.
371 </phrase>
372 <phrase revision="sysv">
373 <filename>/etc/shadow</filename>,
374 <filename>/etc/ld.so.conf</filename>,
375 <filename>/etc/sysconfig/rc.site</filename>,
376 <filename>/etc/sysconfig/network</filename>, and
377 <filename>/etc/sysconfig/ifconfig.eth0</filename>.
378 </phrase>
379 </para>
380
381 <para>A custom kernel may be needed for the new system, depending on
382 differences in system hardware and the original kernel
383 configuration.</para>
384
385 <note><para>There have been some reports of issues when copying between
386 similar but not identical architectures. For instance, the instruction set
387 for an Intel system is not identical with the AMD processor's instructions, and later
388 versions of some processors may provide instructions that are unavailable with
389 earlier versions.</para></note>
390
391 <para>Finally, the new system has to be made bootable via <xref
392 linkend="ch-bootable-grub"/>.</para>
393
394 </sect2>
395
396</sect1>
Note: See TracBrowser for help on using the repository browser.