source: chapter08/pkgmgt.xml@ 1e9ad78

12.0 12.1 12.1-rc1 multilib trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/update-glibc
Last change on this file since 1e9ad78 was 5e7593e, checked in by Xi Ruoyao <xry111@…>, 13 months ago

pkgmgmt: Revert some of reword for "dependency hell" from Bruce

Use "library name" (instead of "library version") for SONAME (for now).
And "conflicting locations" may not be a problem if the symbol is at two
locations but they are exactly same (or ABI compatible).

For the details see lfs-dev discussion.

The current word is still not perfect (we've not defined "the name of a
shared library" at all), so I guess we'll need to make a major revision
for the entire "upgrading issue with shared libraries" thing in the
future.

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