pkgmgt.xml 12 KB

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