pkgmgt.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-system-pkgmgt">
  8. <?dbhtml filename="pkgmgt.html"?>
  9. <title>Package Management</title>
  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. As well as the binary and library files, a
  13. package manager will handle the installation of configuration files. Before
  14. you begin to wonder, NO&mdash;this section will not talk about nor recommend
  15. any particular package manager. What it provides is a roundup of the more
  16. popular techniques and how they work. The perfect package manager for you may
  17. be among these techniques or may be a combination of two or more of these
  18. techniques. This section briefly mentions issues that may arise when upgrading
  19. packages.</para>
  20. <para>Some reasons why no package manager is mentioned in LFS or BLFS
  21. include:</para>
  22. <itemizedlist>
  23. <listitem>
  24. <para>Dealing with package management takes the focus away from the goals
  25. of these books&mdash;teaching how a Linux system is built.</para>
  26. </listitem>
  27. <listitem>
  28. <para>There are multiple solutions for package management, each having
  29. its strengths and drawbacks. Including one that satisfies all audiences
  30. is difficult.</para>
  31. </listitem>
  32. </itemizedlist>
  33. <para>There are some hints written on the topic of package management. Visit
  34. the <ulink url="&hints-index;">Hints Project</ulink> and see if one of them
  35. fits your need.</para>
  36. <sect2>
  37. <title>Upgrade Issues</title>
  38. <para>A Package Manager makes it easy to upgrade to newer versions when they
  39. are released. Generally the instructions in the LFS and BLFS Book can be
  40. used to upgrade to the newer versions. Here are some points that you should
  41. be aware of when upgrading packages, especially on a running system.</para>
  42. <itemizedlist>
  43. <listitem>
  44. <para>If Glibc needs to be upgraded to a newer version, (e.g. from
  45. glibc-2.19 to glibc-2.20), it is safer to rebuild LFS. Though you
  46. <emphasis>may</emphasis> be able to rebuild all the packages in their
  47. dependency order, we do not recommend it. </para>
  48. </listitem>
  49. <listitem>
  50. <para>If a package containing a shared library is updated, and if the
  51. name of the library changes, then all the packages dynamically linked
  52. to the library need to be recompiled to link against the newer library.
  53. (Note that there is no correlation between the package version and the
  54. name of the library.) For example, consider a package foo-1.2.3 that
  55. installs a shared library with name
  56. <filename class='libraryfile'>libfoo.so.1</filename>. Say you upgrade
  57. the package to a newer version foo-1.2.4 that installs a shared library
  58. with name <filename class='libraryfile'>libfoo.so.2</filename>. In this
  59. case, all packages that are dynamically linked to
  60. <filename class='libraryfile'>libfoo.so.1</filename> need to be
  61. recompiled to link against
  62. <filename class='libraryfile'>libfoo.so.2</filename>. Note that you
  63. should not remove the previous libraries until the dependent packages
  64. are recompiled.</para>
  65. </listitem>
  66. </itemizedlist>
  67. </sect2>
  68. <sect2>
  69. <title>Package Management Techniques</title>
  70. <para>The following are some common package management techniques. Before
  71. making a decision on a package manager, do some research on the various
  72. techniques, particularly the drawbacks of the particular scheme.</para>
  73. <sect3>
  74. <title>It is All in My Head!</title>
  75. <para>Yes, this is a package management technique. Some folks do not find
  76. the need for a package manager because they know the packages intimately
  77. and know what files are installed by each package. Some users also do not
  78. need any package management because they plan on rebuilding the entire
  79. system when a package is changed.</para>
  80. </sect3>
  81. <sect3>
  82. <title>Install in Separate Directories</title>
  83. <para>This is a simplistic package management that does not need any extra
  84. package to manage the installations. Each package is installed in a
  85. separate directory. For example, package foo-1.1 is installed in
  86. <filename class='directory'>/usr/pkg/foo-1.1</filename>
  87. and a symlink is made from <filename>/usr/pkg/foo</filename> to
  88. <filename class='directory'>/usr/pkg/foo-1.1</filename>. When installing
  89. a new version foo-1.2, it is installed in
  90. <filename class='directory'>/usr/pkg/foo-1.2</filename> and the previous
  91. symlink is replaced by a symlink to the new version.</para>
  92. <para>Environment variables such as <envar>PATH</envar>,
  93. <envar>LD_LIBRARY_PATH</envar>, <envar>MANPATH</envar>,
  94. <envar>INFOPATH</envar> and <envar>CPPFLAGS</envar> need to be expanded to
  95. include <filename>/usr/pkg/foo</filename>. For more than a few packages,
  96. this scheme becomes unmanageable.</para>
  97. </sect3>
  98. <sect3>
  99. <title>Symlink Style Package Management</title>
  100. <para>This is a variation of the previous package management technique.
  101. Each package is installed similar to the previous scheme. But instead of
  102. making the symlink, each file is symlinked into the
  103. <filename class='directory'>/usr</filename> hierarchy. This removes the
  104. need to expand the environment variables. Though the symlinks can be
  105. created by the user to automate the creation, many package managers have
  106. been written using this approach. A few of the popular ones include Stow,
  107. Epkg, Graft, and Depot.</para>
  108. <para>The installation needs to be faked, so that the package thinks that
  109. it is installed in <filename class="directory">/usr</filename> though in
  110. reality it is installed in the
  111. <filename class="directory">/usr/pkg</filename> hierarchy. Installing in
  112. this manner is not usually a trivial task. For example, consider that you
  113. are installing a package libfoo-1.1. The following instructions may
  114. not install the package properly:</para>
  115. <screen role="nodump"><userinput>./configure --prefix=/usr/pkg/libfoo/1.1
  116. make
  117. make install</userinput></screen>
  118. <para>The installation will work, but the dependent packages may not link
  119. to libfoo as you would expect. If you compile a package that links against
  120. libfoo, you may notice that it is linked to
  121. <filename class='libraryfile'>/usr/pkg/libfoo/1.1/lib/libfoo.so.1</filename>
  122. instead of <filename class='libraryfile'>/usr/lib/libfoo.so.1</filename>
  123. as you would expect. The correct approach is to use the
  124. <envar>DESTDIR</envar> strategy to fake installation of the package. This
  125. approach works as follows:</para>
  126. <screen role="nodump"><userinput>./configure --prefix=/usr
  127. make
  128. make DESTDIR=/usr/pkg/libfoo/1.1 install</userinput></screen>
  129. <para>Most packages support this approach, but there are some which do not.
  130. For the non-compliant packages, you may either need to manually install the
  131. package, or you may find that it is easier to install some problematic
  132. packages into <filename class='directory'>/opt</filename>.</para>
  133. </sect3>
  134. <sect3>
  135. <title>Timestamp Based</title>
  136. <para>In this technique, a file is timestamped before the installation of
  137. the package. After the installation, a simple use of the
  138. <command>find</command> command with the appropriate options can generate
  139. a log of all the files installed after the timestamp file was created. A
  140. package manager written with this approach is install-log.</para>
  141. <para>Though this scheme has the advantage of being simple, it has two
  142. drawbacks. If, during installation, the files are installed with any
  143. timestamp other than the current time, those files will not be tracked by
  144. the package manager. Also, this scheme can only be used when one package
  145. is installed at a time. The logs are not reliable if two packages are
  146. being installed on two different consoles.</para>
  147. </sect3>
  148. <sect3>
  149. <title>Tracing Installation Scripts</title>
  150. <para>In this approach, the commands that the installation scripts perform
  151. are recorded. There are two techniques that one can use:</para>
  152. <para>The <envar>LD_PRELOAD</envar> environment variable can be set to
  153. point to a library to be preloaded before installation. During
  154. installation, this library tracks the packages that are being installed by
  155. attaching itself to various executables such as <command>cp</command>,
  156. <command>install</command>, <command>mv</command> and tracking the system
  157. calls that modify the filesystem. For this approach to work, all the
  158. executables need to be dynamically linked without the suid or sgid bit.
  159. Preloading the library may cause some unwanted side-effects during
  160. installation. Therefore, it is advised that one performs some tests to
  161. ensure that the package manager does not break anything and logs all the
  162. appropriate files.</para>
  163. <para>The second technique is to use <command>strace</command>, which
  164. logs all system calls made during the execution of the installation
  165. scripts.</para>
  166. </sect3>
  167. <sect3>
  168. <title>Creating Package Archives</title>
  169. <para>In this scheme, the package installation is faked into a separate
  170. tree as described in the Symlink style package management. After the
  171. installation, a package archive is created using the installed files.
  172. This archive is then used to install the package either on the local
  173. machine or can even be used to install the package on other machines.</para>
  174. <para>This approach is used by most of the package managers found in the
  175. commercial distributions. Examples of package managers that follow this
  176. approach are RPM (which, incidentally, is required by the <ulink
  177. url="http://refspecs.linuxfoundation.org/lsb.shtml">Linux
  178. Standard Base Specification</ulink>), pkg-utils, Debian's apt, and
  179. Gentoo's Portage system. A hint describing how to adopt this style of
  180. package management for LFS systems is located at <ulink
  181. url="&hints-root;fakeroot.txt"/>.</para>
  182. <para>Creation of package files that include dependency information is
  183. complex and is beyond the scope of LFS.</para>
  184. <para>Slackware uses a <command>tar</command> based system for package
  185. archives. This system purposely does not handle package dependencies
  186. as more complex package managers do. For details of Slackware package
  187. management, see <ulink
  188. url="http://www.slackbook.org/html/package-management.html"/>.</para>
  189. </sect3>
  190. <sect3>
  191. <title>User Based Management</title>
  192. <para>This scheme, unique to LFS, was devised by Matthias Benkmann, and is
  193. available from the <ulink url="&hints-index;">Hints Project</ulink>. In
  194. this scheme, each package is installed as a separate user into the
  195. standard locations. Files belonging to a package are easily identified by
  196. checking the user ID. The features and shortcomings of this approach are
  197. too complex to describe in this section. For the details please see the
  198. hint at <ulink url="&hints-root;more_control_and_pkg_man.txt"/>.</para>
  199. </sect3>
  200. </sect2>
  201. <sect2>
  202. <title>Deploying LFS on Multiple Systems</title>
  203. <para>One of the advantages of an LFS system is that there are no files that
  204. depend on the position of files on a disk system. Cloning an LFS build to
  205. another computer with the same architecture as the base system is as
  206. simple as using <command>tar</command> on the LFS partition that contains
  207. the root directory (about 250MB uncompressed for a base LFS build), copying
  208. that file via network transfer or CD-ROM to the new system and expanding
  209. it. From that point, a few configuration files will have to be changed.
  210. Configuration files that may need to be updated include:
  211. <filename>/etc/hosts</filename>,
  212. <filename>/etc/fstab</filename>,
  213. <filename>/etc/passwd</filename>,
  214. <filename>/etc/group</filename>,
  215. <phrase revision="systemd">
  216. <filename>/etc/shadow</filename>, and
  217. <filename>/etc/ld.so.conf</filename>.
  218. </phrase>
  219. <phrase revision="sysv">
  220. <filename>/etc/shadow</filename>,
  221. <filename>/etc/ld.so.conf</filename>,
  222. <filename>/etc/sysconfig/rc.site</filename>,
  223. <filename>/etc/sysconfig/network</filename>, and
  224. <filename>/etc/sysconfig/ifconfig.eth0</filename>.
  225. </phrase>
  226. </para>
  227. <para>A custom kernel may need to be built for the new system depending on
  228. differences in system hardware and the original kernel
  229. configuration.</para>
  230. <note><para>There have been some reports of issues when copying between
  231. similar but not identical architectures. For instance, the instruction set
  232. for an Intel system is not identical with an AMD processor and later
  233. versions of some processors may have instructions that are unavailable in
  234. earlier versions.</para></note>
  235. <para>Finally the new system has to be made bootable via <xref
  236. linkend="ch-bootable-grub"/>.</para>
  237. </sect2>
  238. </sect1>