Important Information

Package Management

Package Management is an often requested addition to the LFS Book. A Package Manager allows tracking the installation of files making it easy to remove and upgrade packages. And before you begin to wonder, NO - this section does not talk about any particular package manager, nor does it recommend one. What it provides is a roundup of the more popular techniques and how they work. The perfect package manager for you may be among these techniques or may be a combination of two or more of these techniques. This section briefly mentions issues that may arise when upgrading packages.

Some reasons why no package manager is mentioned in LFS or BLFS:

  • Dealing with package management takes the focus away from the goals of these books - Teaching how a Linux System is built.

  • There are multiple solutions for package management, each having its strengths and drawbacks. Including one that satifies all audiences is difficult.

There are some hints written on the topic of package management. Visit the Hints subproject to find if one of them fits your need.

Upgrade Issues

A Package Manager makes it easy to upgrade to newer versions as and when they are released. Generally the instructions in the LFS and BLFS Book can be used to upgrade to the newer versions. Following are some points that you should be aware of when upgrading packages, especially on a running system.

  • It is recommended that if one of the toolchain package (glibc, gcc, binutils) needs to be upgraded to a newer minor vesion, it is safer to rebuild LFS. Though you may be able to get by rebuilding all the packages in their dependency order. We do not recommend the latter. For example, if glibc-2.2.x needs to be updated to glibc-2.3.x, it is safer to rebuild. For micro version updates, a simple reinstallation usually works, but is not guaranteed. For example, upgrading from glibc-2.3.1 to glibc-2.3.2 will not usually cause any problems.

  • If a package containing a shared library is updated, and if the soname of the library changes, then all the packages dynamically linked to the library need to be recompiled to link against the newer library. (Note that there is no corelation between the package version and the soname of the library.) For example, consider a package foo-1.2.3 that installs a shared library with soname libfoo.so.1. Say you upgrade the package to a newer version foo-1.2.4 that installs a shared library with soname libfoo.so.2. In this case, all packages that are dynamically linked to libfoo.so.1 need to be recompiled to link against libfoo.so.2. Note that you should not remove the previous libraries till the dependent packages are recompiled.

  • If you are upgrading a running system, be on the lookout for packages that use cp instead of install to install files. The latter command is usually safer if the executable or library is already loaded in memory.

Package Management Techniques

The following are some common package management techniques. Before making a decision on a package manager, do a research on the various techniques, particularly the drawbacks of the particular scheme.

It is all in my head!

Yes, this is a package management technique. Some folks do not find the need for a package manager because they know the packages intimately and know what files are installed by each package. Some users also do not need any package management because they plan on rebuilding the entire LFS when a package is changed.

Install in separate directories

This is a simplistic package management that does not need any extra package to manage the installations. Each package is installed in a separate directory. For example, package foo-1.1 is installed in /usr/pkg/foo-1.1 and a symlink is made from /usr/pkg/foo to /usr/pkg/foo-1.1. When installing a new version foo-1.2, it is installed in /usr/pkg/foo-1.2 and the previous symlink is replaced by a symlink to the new vesion.

The environment variables such as those mentioned in the section called “Going Beyond BLFS” need to be expanded to include /usr/pkg/foo. For more than a few packages, this scheme becomes unmanageable.

Symlink style package management

This is a variation of the previous package management technique. Each package is installed similar to the previous scheme. But instead of making the symlink, each file is symlinked into /usr hierarchy. This removes the need to expand the environment variables. Though the symlinks can be created by the user, to automate the creation, many package managers have been written on this approach. A few of the popular ones are Stow, Epkg, Graft, and Depot.

The installation needs to be faked, so that the package thinks that it is installed in /usr though in reality it is installed in /usr/pkg hierarchy. Installing in this manner is not usually a trivial task. For example, consider that you are installing a package libfoo-1.1. The following instructions may not install the package properly:

./configure --prefix=/usr/pkg/libfoo/1.1 &&
make &&
make install

The installation will work, but the dependent packages may not link to libfoo as you would expect. If you compile a package that links against libfoo, you may notice that it is linked to /usr/pkg/libfoo/1.1/lib/libfoo.so.1 instead of /usr/lib/libfoo.so.1 as you would expect. The correct approach is to use DESTDIR strategy to fake installation of the package. This approach works as follows:

./configure --prefix=/usr &&
make &&
make DESTDIR=/usr/pkg/libfoo/1.1 install

Most of the packages do support this approach, but there are some which do not. For the non-compliant packages, you may either need to manually install the package, or you may find that it is easier to install some problematic packages into /opt.

Timestamp based

In this technique, a file is timestamped before the installation of the package. After the installation, a simple use of the find command with the appropriate options can generate a log of all the files installed after the timestamp file was created. A package manager written with this approach is install-log.

Though this scheme has the advantage of being simple, it has two drawbacks. If during installation, the files are installed with any timestamp other than the current time, those files will not be tracked by the package manager. Also, this scheme can only be used when one package is installed at a time. The logs are not reliable if two packages are being installed on two different consoles.

LD_PRELOAD based

In this approach, a library is preloaded before installation. During installation, this library tracks the packages that are being installed by attaching itself to various executables such as cp, install, mv and tracking the system calls that modify the filesystem. For this approach to work, all the executables need to be dymanically linked without the suid or sgid bit. Preloading the library may cause some unwanted side-effects during installation; hence do perform some tests to ensure that the package manager does not break anything and logs all the appropriate files.

Creating Package Archives

In this scheme, the package installation is faked into a separate tree as described in the Symlink style package management. After the installation, a package archive is created using the installed files. This archive is then used to install the package either on the local machine or can even be used to install the package on other machines.

This approach is used by most of the package managers found in the commercial distributions. Examples of package Managers that follow this approach are RPM, pkg-utils, Debian's apt, Gentoo's Portage system.

User Based Management

This scheme, that is unique to LFS, was devised by Matthias Benkmann, and is available from the Hints Project. In this scheme, each package is installed as a separate user into the standard locations. Files belonging to a package are easily identified by checking the user id. The features and shortcomings of this approach are too complex to describe in this section. For the details please see the hint at http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt.