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="pkgmgt">
|
---|
9 | <?dbhtml filename="pkgmgt.html"?>
|
---|
10 |
|
---|
11 |
|
---|
12 | <title>Package Management</title>
|
---|
13 |
|
---|
14 | <para>Package Management is an often requested addition
|
---|
15 | to the LFS Book. A Package Manager allows tracking
|
---|
16 | the installation of files making it easy to remove and upgrade packages.
|
---|
17 | And before you begin to wonder, NO—this section does not talk about any
|
---|
18 | particular package manager, nor does it recommend one. What it provides is
|
---|
19 | a roundup of the more popular techniques and how they work. The perfect
|
---|
20 | package manager for you may be among these techniques or may be a combination
|
---|
21 | of two or more of these techniques. This section briefly mentions
|
---|
22 | issues that may arise when upgrading packages.</para>
|
---|
23 |
|
---|
24 | <para>Some reasons why no package manager is mentioned in LFS
|
---|
25 | or BLFS:</para>
|
---|
26 |
|
---|
27 | <itemizedlist>
|
---|
28 | <listitem>
|
---|
29 | <para>Dealing with package management takes the focus away from
|
---|
30 | the goals of these books—teaching how a Linux system is built.</para>
|
---|
31 | </listitem>
|
---|
32 | <listitem>
|
---|
33 | <para>There are multiple solutions for package management, each having
|
---|
34 | its strengths and drawbacks. Including one that satisfies all audiences is
|
---|
35 | difficult.</para>
|
---|
36 | </listitem>
|
---|
37 | </itemizedlist>
|
---|
38 |
|
---|
39 | <para>There are some hints written on the topic of package management. Visit
|
---|
40 | the <ulink url="&hints-root;">Hints subproject</ulink>
|
---|
41 | and see if one of them fits your need.</para>
|
---|
42 |
|
---|
43 | <sect2>
|
---|
44 | <title>Upgrade Issues</title>
|
---|
45 |
|
---|
46 | <para>A Package Manager makes it easy to upgrade to newer versions when
|
---|
47 | they are released. Generally the instructions in the LFS and BLFS Book can be
|
---|
48 | used to upgrade to the newer versions. Here are some points that you should
|
---|
49 | be aware of when upgrading packages, especially on a running system.</para>
|
---|
50 |
|
---|
51 | <itemizedlist>
|
---|
52 | <listitem>
|
---|
53 | <para>If one of the toolchain packages
|
---|
54 | (<application>Glibc</application>, <application>GCC</application> or
|
---|
55 | <application>Binutils</application>) needs to be upgraded to a newer
|
---|
56 | minor version, it is safer to rebuild LFS. Though you
|
---|
57 | <emphasis>may</emphasis> be able to get by rebuilding all the packages
|
---|
58 | in their dependency order, we do not recommend it. For example, if
|
---|
59 | glibc-2.2.x needs to be updated to glibc-2.3.x, it is safer to rebuild.
|
---|
60 | For micro version updates, a simple reinstallation usually works, but
|
---|
61 | is not guaranteed. For example, upgrading from glibc-2.3.4 to
|
---|
62 | glibc-2.3.5 will not usually cause any problems.</para>
|
---|
63 | </listitem>
|
---|
64 | <listitem>
|
---|
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>
|
---|
80 | </listitem>
|
---|
81 | <listitem>
|
---|
82 | <para>If you are upgrading a running system, be on the lookout for packages
|
---|
83 | that use <command>cp</command> instead of <command>install</command>
|
---|
84 | to install files. The latter command is usually safer if the executable
|
---|
85 | or library is already loaded in memory.</para>
|
---|
86 | </listitem>
|
---|
87 | </itemizedlist>
|
---|
88 |
|
---|
89 | </sect2>
|
---|
90 |
|
---|
91 | <sect2>
|
---|
92 | <title>Package Management Techniques</title>
|
---|
93 |
|
---|
94 | <para>The following are some common package management techniques. Before
|
---|
95 | making a decision on a package manager, do some research on the various
|
---|
96 | techniques, particularly the drawbacks of the particular scheme.</para>
|
---|
97 |
|
---|
98 | <sect3>
|
---|
99 | <title>It is All in My Head!</title>
|
---|
100 |
|
---|
101 | <para>Yes, this is a package management technique. Some folks do not find the
|
---|
102 | need for a package manager because they know the packages intimately and know
|
---|
103 | what files are installed by each package. Some users also do not need any
|
---|
104 | package management because they plan on rebuilding the entire system
|
---|
105 | when a package is changed.</para>
|
---|
106 |
|
---|
107 | </sect3>
|
---|
108 |
|
---|
109 | <sect3>
|
---|
110 | <title>Install in Separate Directories</title>
|
---|
111 |
|
---|
112 | <para>This is a simplistic package management that does not need any
|
---|
113 | extra package to manage the installations. Each package is installed in a
|
---|
114 | separate directory. For example, package foo-1.1 is installed in
|
---|
115 | <filename class='directory'>/usr/pkg/foo-1.1</filename>
|
---|
116 | and a symlink is made from <filename>/usr/pkg/foo</filename> to
|
---|
117 | <filename class='directory'>/usr/pkg/foo-1.1</filename>. When installing
|
---|
118 | a new version foo-1.2, it is installed in
|
---|
119 | <filename class='directory'>/usr/pkg/foo-1.2</filename> and the previous
|
---|
120 | symlink is replaced by a symlink to the new version.</para>
|
---|
121 |
|
---|
122 | <para>The environment variables such as those mentioned in
|
---|
123 | <quote><xref linkend="beyond"/></quote> need to be expanded to
|
---|
124 | include <filename>/usr/pkg/foo</filename>. For more than a few packages,
|
---|
125 | this scheme becomes unmanageable.</para>
|
---|
126 |
|
---|
127 | </sect3>
|
---|
128 |
|
---|
129 | <sect3>
|
---|
130 | <title>Symlink Style Package Management</title>
|
---|
131 |
|
---|
132 | <para>This is a variation of the previous package management technique.
|
---|
133 | Each package is installed similar to the previous scheme. But instead of
|
---|
134 | making the symlink, each file is symlinked into the
|
---|
135 | <filename class='directory'>/usr</filename> hierarchy. This removes the
|
---|
136 | need to expand the environment variables. Though the symlinks can be
|
---|
137 | created by the user to automate the creation, many package managers have
|
---|
138 | been written using this approach. A few of the popular ones are Stow,
|
---|
139 | Epkg, Graft, and Depot.</para>
|
---|
140 |
|
---|
141 | <para>The installation needs to be faked, so that the package thinks that it is
|
---|
142 | installed in <filename class="directory">/usr</filename> though in reality it is
|
---|
143 | installed in the <filename class="directory">/usr/pkg</filename> hierarchy.
|
---|
144 | Installing in this manner is not usually a trivial task. For example, consider
|
---|
145 | that you are installing a package libfoo-1.1. The following instructions may
|
---|
146 | not install the package properly:</para>
|
---|
147 |
|
---|
148 | <screen><userinput>./configure --prefix=/usr/pkg/libfoo/1.1
|
---|
149 | make
|
---|
150 | make install</userinput></screen>
|
---|
151 |
|
---|
152 | <para>The installation will work, but the dependent packages may not link
|
---|
153 | to libfoo as you would expect. If you compile a package that links against
|
---|
154 | libfoo, you may notice that it is linked to
|
---|
155 | <filename class='libraryfile'>/usr/pkg/libfoo/1.1/lib/libfoo.so.1</filename>
|
---|
156 | instead of <filename class='libraryfile'>/usr/lib/libfoo.so.1</filename>
|
---|
157 | as you would expect. The correct approach is to use <envar>DESTDIR</envar>
|
---|
158 | strategy to fake installation of the package. This approach works as
|
---|
159 | follows:</para>
|
---|
160 |
|
---|
161 | <screen><userinput>./configure --prefix=/usr
|
---|
162 | make
|
---|
163 | make DESTDIR=/usr/pkg/libfoo/1.1 install</userinput></screen>
|
---|
164 |
|
---|
165 | <para>Most of the packages do support this approach, but there are some
|
---|
166 | which do not. For the non-compliant packages, you may either need to
|
---|
167 | manually install the package, or you may find that it is easier to install
|
---|
168 | some problematic packages into
|
---|
169 | <filename class='directory'>/opt</filename>.</para>
|
---|
170 |
|
---|
171 | </sect3>
|
---|
172 |
|
---|
173 | <sect3>
|
---|
174 | <title>Timestamp Based</title>
|
---|
175 |
|
---|
176 | <para>In this technique, a file is timestamped before the installation of
|
---|
177 | the package. After the installation, a simple use of the
|
---|
178 | <command>find</command> command with the appropriate options can generate
|
---|
179 | a log of all the files installed after the timestamp file was created. A
|
---|
180 | package manager written with this approach is install-log.</para>
|
---|
181 |
|
---|
182 | <para>Though this scheme has the advantage of being simple, it has two drawbacks.
|
---|
183 | If during installation, the files are installed with any timestamp other than the
|
---|
184 | current time, those files will not be tracked by the package manager. Also, this
|
---|
185 | scheme can only be used when one package is installed at a time. The logs are not
|
---|
186 | reliable if two packages are being installed on two different consoles.</para>
|
---|
187 |
|
---|
188 | </sect3>
|
---|
189 |
|
---|
190 | <sect3>
|
---|
191 | <title>LD_PRELOAD Based</title>
|
---|
192 |
|
---|
193 | <para>In this approach, a library is 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 executables
|
---|
198 | need to be dynamically linked without the suid or sgid bit. Preloading the
|
---|
199 | library may cause some unwanted side-effects during installation. Therefore,
|
---|
200 | do perform some tests to ensure that the package manager does not break
|
---|
201 | anything and logs all the appropriate files.</para>
|
---|
202 |
|
---|
203 | </sect3>
|
---|
204 |
|
---|
205 | <sect3>
|
---|
206 | <title>Creating Package Archives</title>
|
---|
207 |
|
---|
208 | <para>In this scheme, the package installation is faked into a separate
|
---|
209 | tree as described in the Symlink style package management. After the
|
---|
210 | installation, a package archive is created using the installed files.
|
---|
211 | This archive is then used to install the package either on the local
|
---|
212 | machine or can even be used to install the package on other machines.</para>
|
---|
213 |
|
---|
214 | <para>This approach is used by most of the package managers found in the
|
---|
215 | commercial distributions. Examples of package managers that follow this
|
---|
216 | approach are RPM, pkg-utils, Debian's apt, and Gentoo's Portage system.</para>
|
---|
217 |
|
---|
218 | </sect3>
|
---|
219 |
|
---|
220 | <sect3>
|
---|
221 | <title>User Based Management</title>
|
---|
222 |
|
---|
223 | <para>This scheme, unique to LFS, was devised by Matthias Benkmann,
|
---|
224 | and is available from the <ulink url="&hints-root;">Hints
|
---|
225 | Project</ulink>. In this scheme, each package is installed as a separate user
|
---|
226 | into the standard locations. Files belonging to a package are easily identified
|
---|
227 | by checking the user ID. The features and shortcomings of this approach are
|
---|
228 | too complex to describe in this section. For the details please see the hint at <ulink
|
---|
229 | url="&hints-root;/downloads/files/more_control_and_pkg_man.txt"/>.</para>
|
---|
230 |
|
---|
231 | </sect3>
|
---|
232 |
|
---|
233 | </sect2>
|
---|
234 |
|
---|
235 | </sect1>
|
---|