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">
8 <sect1 id="ch-system-pkgmgt">
9 <?dbhtml filename="pkgmgt.html"?>
11 <title>Package Management</title>
13 <para>Package Management is an often requested addition to the LFS Book. A
14 Package Manager allows tracking the installation of files making it easy to
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—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
20 be among these techniques or may be a combination of two or more of these
21 techniques. This section briefly mentions issues that may arise when upgrading
24 <para>Some reasons why no package manager is mentioned in LFS or BLFS
29 <para>Dealing with package management takes the focus away from the goals
30 of these books—teaching how a Linux system is built.</para>
34 <para>There are multiple solutions for package management, each having
35 its strengths and drawbacks. Including one that satisfies all audiences
40 <para>There are some hints written on the topic of package management. Visit
41 the <ulink url="&hints-index;">Hints Project</ulink> and see if one of them
42 fits your need.</para>
45 <title>Upgrade Issues</title>
47 <para>A Package Manager makes it easy to upgrade to newer versions when they
48 are released. Generally the instructions in the LFS and BLFS Book can be
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>
54 <para>If one of the toolchain packages (Glibc, GCC or Binutils) needs
55 to be upgraded to a newer minor version, it is safer to rebuild LFS.
56 Though you <emphasis>may</emphasis> be able to get by rebuilding all
57 the packages in their dependency order, we do not recommend it. For
58 example, if glibc-2.2.x needs to be updated to glibc-2.3.x, it is safer
59 to rebuild. For micro version updates, a simple reinstallation usually
60 works, but is not guaranteed. For example, upgrading from glibc-2.3.4
61 to glibc-2.3.5 will not usually cause any problems.</para>
65 <para>If a package containing a shared library is updated, and if the
66 name of the library changes, then all the packages dynamically linked
67 to the library need to be recompiled to link against the newer library.
68 (Note that there is no correlation between the package version and the
69 name of the library.) For example, consider a package foo-1.2.3 that
70 installs a shared library with name
71 <filename class='libraryfile'>libfoo.so.1</filename>. Say you upgrade
72 the package to a newer version foo-1.2.4 that installs a shared library
73 with name <filename class='libraryfile'>libfoo.so.2</filename>. In this
74 case, all packages that are dynamically linked to
75 <filename class='libraryfile'>libfoo.so.1</filename> need to be
76 recompiled to link against
77 <filename class='libraryfile'>libfoo.so.2</filename>. Note that you
78 should not remove the previous libraries until the dependent packages
79 are recompiled.</para>
86 <title>Package Management Techniques</title>
88 <para>The following are some common package management techniques. Before
89 making a decision on a package manager, do some research on the various
90 techniques, particularly the drawbacks of the particular scheme.</para>
93 <title>It is All in My Head!</title>
95 <para>Yes, this is a package management technique. Some folks do not find
96 the need for a package manager because they know the packages intimately
97 and know what files are installed by each package. Some users also do not
98 need any package management because they plan on rebuilding the entire
99 system when a package is changed.</para>
104 <title>Install in Separate Directories</title>
106 <para>This is a simplistic package management that does not need any extra
107 package to manage the installations. Each package is installed in a
108 separate directory. For example, package foo-1.1 is installed in
109 <filename class='directory'>/usr/pkg/foo-1.1</filename>
110 and a symlink is made from <filename>/usr/pkg/foo</filename> to
111 <filename class='directory'>/usr/pkg/foo-1.1</filename>. When installing
112 a new version foo-1.2, it is installed in
113 <filename class='directory'>/usr/pkg/foo-1.2</filename> and the previous
114 symlink is replaced by a symlink to the new version.</para>
116 <para>Environment variables such as <envar>PATH</envar>,
117 <envar>LD_LIBRARY_PATH</envar>, <envar>MANPATH</envar>,
118 <envar>INFOPATH</envar> and <envar>CPPFLAGS</envar> need to be expanded to
119 include <filename>/usr/pkg/foo</filename>. For more than a few packages,
120 this scheme becomes unmanageable.</para>
125 <title>Symlink Style Package Management</title>
127 <para>This is a variation of the previous package management technique.
128 Each package is installed similar to the previous scheme. But instead of
129 making the symlink, each file is symlinked into the
130 <filename class='directory'>/usr</filename> hierarchy. This removes the
131 need to expand the environment variables. Though the symlinks can be
132 created by the user to automate the creation, many package managers have
133 been written using this approach. A few of the popular ones include Stow,
134 Epkg, Graft, and Depot.</para>
136 <para>The installation needs to be faked, so that the package thinks that
137 it is installed in <filename class="directory">/usr</filename> though in
138 reality it is installed in the
139 <filename class="directory">/usr/pkg</filename> hierarchy. Installing in
140 this manner is not usually a trivial task. For example, consider that you
141 are installing a package libfoo-1.1. The following instructions may
142 not install the package properly:</para>
144 <screen role="nodump"><userinput>./configure --prefix=/usr/pkg/libfoo/1.1
146 make install</userinput></screen>
148 <para>The installation will work, but the dependent packages may not link
149 to libfoo as you would expect. If you compile a package that links against
150 libfoo, you may notice that it is linked to
151 <filename class='libraryfile'>/usr/pkg/libfoo/1.1/lib/libfoo.so.1</filename>
152 instead of <filename class='libraryfile'>/usr/lib/libfoo.so.1</filename>
153 as you would expect. The correct approach is to use the
154 <envar>DESTDIR</envar> strategy to fake installation of the package. This
155 approach works as follows:</para>
157 <screen role="nodump"><userinput>./configure --prefix=/usr
159 make DESTDIR=/usr/pkg/libfoo/1.1 install</userinput></screen>
161 <para>Most packages support this approach, but there are some which do not.
162 For the non-compliant packages, you may either need to manually install the
163 package, or you may find that it is easier to install some problematic
164 packages into <filename class='directory'>/opt</filename>.</para>
169 <title>Timestamp Based</title>
171 <para>In this technique, a file is timestamped before the installation of
172 the package. After the installation, a simple use of the
173 <command>find</command> command with the appropriate options can generate
174 a log of all the files installed after the timestamp file was created. A
175 package manager written with this approach is install-log.</para>
177 <para>Though this scheme has the advantage of being simple, it has two
178 drawbacks. If, during installation, the files are installed with any
179 timestamp other than the current time, those files will not be tracked by
180 the package manager. Also, this scheme can only be used when one package
181 is installed at a time. The logs are not reliable if two packages are
182 being installed on two different consoles.</para>
187 <title>Tracing Installation Scripts</title>
189 <para>In this approach, the commands that the installation scripts perform
190 are recorded. There are two techniques that one can use:</para>
192 <para>The <envar>LD_PRELOAD</envar> environment variable can be set to
193 point to a library to be preloaded before installation. During
194 installation, this library tracks the packages that are being installed by
195 attaching itself to various executables such as <command>cp</command>,
196 <command>install</command>, <command>mv</command> and tracking the system
197 calls that modify the filesystem. For this approach to work, all the
198 executables need to be dynamically linked without the suid or sgid bit.
199 Preloading the library may cause some unwanted side-effects during
200 installation. Therefore, it is advised that one performs some tests to
201 ensure that the package manager does not break anything and logs all the
202 appropriate files.</para>
204 <para>The second technique is to use <command>strace</command>, which
205 logs all system calls made during the execution of the installation
210 <title>Creating Package Archives</title>
212 <para>In this scheme, the package installation is faked into a separate
213 tree as described in the Symlink style package management. After the
214 installation, a package archive is created using the installed files.
215 This archive is then used to install the package either on the local
216 machine or can even be used to install the package on other machines.</para>
218 <para>This approach is used by most of the package managers found in the
219 commercial distributions. Examples of package managers that follow this
220 approach are RPM (which, incidentally, is required by the <ulink
221 url="http://www.linux-foundation.org/en/Specifications">Linux
222 Standard Base Specification</ulink>), pkg-utils, Debian's apt, and
223 Gentoo's Portage system. A hint describing how to adopt this style of
224 package management for LFS systems is located at <ulink
225 url="&hints-root;fakeroot.txt"/>.</para>
227 <para>Creation of package files that include dependency information is
228 complex and is beyond the scope of LFS.</para>
230 <para>Slackware uses a <command>tar</command> based system for package
231 archives. This system purposely does not handle package dependencies
232 as more complex package managers do. For details of Slackware package
233 management, see <ulink
234 url="http://www.slackbook.org/html/package-management.html"/>.</para>
238 <title>User Based Management</title>
240 <para>This scheme, unique to LFS, was devised by Matthias Benkmann, and is
241 available from the <ulink url="&hints-index;">Hints Project</ulink>. In
242 this scheme, each package is installed as a separate user into the
243 standard locations. Files belonging to a package are easily identified by
244 checking the user ID. The features and shortcomings of this approach are
245 too complex to describe in this section. For the details please see the
246 hint at <ulink url="&hints-root;more_control_and_pkg_man.txt"/>.</para>
253 <title>Deploying LFS on Multiple Systems</title>
255 <para>One of the advantages of an LFS system is that there are no files that
256 depend on the position of files on a disk system. Cloning an LFS build to
257 another computer with an architecture similar to the base system is as
258 simple as using <command>tar</command> on the LFS partition that contains
259 the root directory (about 250MB uncompressed for a base LFS build), copying
260 that file via network transfer or CD-ROM to the new system and expanding
261 it. From that point, a few configuration files will have to be changed.
262 Configuration files that may need to be updated include:
263 <filename>/etc/hosts</filename>,
264 <filename>/etc/fstab</filename>,
265 <filename>/etc/passwd</filename>,
266 <filename>/etc/group</filename>,
267 <filename>/etc/shadow</filename>,
268 <filename>/etc/ld.so.conf</filename>,
269 <filename>/etc/scsi_id.config</filename>,
270 <filename>/etc/sysconfig/network</filename> and
271 <filename>/etc/sysconfig/network-devices/ifconfig.eth0/ipv4</filename>.
274 <para>A custom kernel may need to be built for the new system depending on
275 differences in system hardware and the original kernel
276 configuration.</para>
278 <para>Finally the new system has to be made bootable via <xref
279 linkend="ch-bootable-grub"/>.</para>