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