source: chapter08/pkgmgt.xml@ 5f3a328

multilib xry111/multilib
Last change on this file since 5f3a328 was 6582ddc5, checked in by Xi Ruoyao <xry111@…>, 2 years ago

pkgmgt: fix two typos

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