Binary package guide/ko

일상의 ebuild 지원 요소 말고도, 포티지에서는 바이너리 꾸러미 빌드 및 설치를 지원합니다. 이 안내서에서는 바이너리 꾸러미를 만들고, 설치하는 방법, 그리고 바이너리 꾸러미 서버를 설정하는 방법을 설명합니다.

도입부
There are many reasons why some administrators like using binary package installations in Gentoo.


 * 1) First of all, it allows administrators to keep similar systems updated. Having to compile everything from source can become time consuming at times. Maintaining several similar systems, possibly some of them rather slow, can be much easier if only one system has to compile everything from source and the other systems reuse the binary packages.
 * 2) A second reason is to do safe updates. For mission critical systems it is important to stay usable as much as possible. This can be done by a staging server that performs all updates first and once the staging server is in a good state updates can be applied to the critical system. A variant of this approach is to do the updates in a chroot on the same system and use the binaries created there on the real system.
 * 3) A third reason is as a backup. Sometimes binary package are the only way of recovering a broken system (i.e. broken compiler). Having them around either on a binary package server or locally can be of great help.
 * 4) Finally, it also supports updating very old systems. The task of updating very old systems can be greatly eased using binary packages. It is usually easier to install binary packages as those don't require the build time dependencies to be installed / updated and the failures in the build process for them can be avoided.

In this guide, we focus on
 * how to create binary packages,
 * how to distribute these to the clients,
 * how to use binary packages, and
 * how to maintain the binary packages

We end with a few more advanced topics on dealing with binary packages.

Creating binary packages
There are three main methods for creating binary packages:
 * 1) After a regular installation, using
 * 2) Explicitly during an emerge operation by using the   option
 * 3) Automatically through the use of the   portage feature

All three methods will create a binary package in the directory pointed to by the  variable (which defaults to ).

Using quickpkg
The  application takes one or more dependency atoms (or package sets) and creates binary packages for all installed packages that match the atom.

For instance, to create binary packages of all installed GCC versions:

To create binary packages of all installed packages, use the  glob:

There is a caveat with this method though: it relies on the installed files, which can be a problem in case of configuration files. Administrators often change configuration files after installing software. Because this could leak out important or perhaps even confidential data into the packages,  by default does not include configuration files that are protected through the CONFIG_PROTECT method. To include those as well, use the  or   options.

Using the --buildpkg emerge option
When installing software using, portage can be asked to create binary packages as well by using  :

It is also possible to ask portage to only create a binary package but not to install the software on the live system. For this, the  option can be used:

The latter approach however requires that all build time dependencies are already installed.

Automatically using buildpkg feature
The most common way is to automatically create binary packages whenever a package is installed by. This is done through the buildpkg feature, which can be set in like so:

Every time portage installs software, it will create a binary package as well.

Excluding creation of some packages
It is possible to tell portage not to create binary packages for a select few packages or categories. This is done through the  option to emerge:

This could be used for packages that have little to no benefit in having a binary package available. Examples would be the Linux kernel source packages or upstream binary packages (those ending with -bin like ).

Setting up a binary package host
Portage supports a number of protocols for downloading binary packages: FTP, FTPS, HTTP, HTTPS and SSH. This leaves room for many possible binary package host implementations.

There is, however, no out-of-the-box method provided by portage for distributing binary packages. Depending on the requested setup, additional software will need to be installed.

Web based binary package host
A common approach for distributing binary packages is to create a web based binary package host.

Use a web server (such as ) and configure it to provide read access to the  location.

Then, on the clients, configure the  variable accordingly:

SSH binary package host
To provide a more authenticated approach for binary packages, one can consider using SSH.

When using SSH, it is possible to use the portage Linux user's SSH key (without passphraze as the installations need to happen in the background) to connect to a remote binary package host.

To accomplish this, make sure that the portage user's SSH key is allowed on the server:

The  could then look like so:

NFS exported
When using binary packages on an internal network, it might be easier to just export the packages through NFS and mount it on the clients.

The file could look like so:

On the clients, the location can then be mounted. An example entry would look like so:

Using binary packages
For binary packages to be usable on other systems they must fulfill some requirements.
 * The client and server architecture and CHOST must match.
 * The  and   that were used to build the binary packages must be compatible with all clients.
 * USE flags for processor specific features (like MMX, SSE,...) have to be carefully selected; all clients need to support them.

Next to these, portage will check if the binary package is built using the same USE flags as expected on the client. If a package is built with a different USE flag combination, portage will either ignore the binary package (and use source-based build) or fail, depending on the options passed on to  (see Installing binary packages).

On clients, a few configuration changes are needed in order for the binary packages to be used.

Installing binary packages
There are a few options that can be passed on to the  command that inform portage about using binary packages.


 * Try to use the binary package(s) in the locally available packages directory. Useful when using NFS-mounted binary package hosts. If the binary package is not found, a regular (source-based) installation will be done.
 * Try to use the binary package(s) in the locally available packages directory. Useful when using NFS-mounted binary package hosts. If the binary package is not found, a regular (source-based) installation will be done.


 * Similar to  but fail if the binary package cannot be found.
 * Similar to  but fail if the binary package cannot be found.


 * Download the binary package from a remote binary package host. If the binary package is not found, a regular (source-based) installation will be done.
 * Download the binary package from a remote binary package host. If the binary package is not found, a regular (source-based) installation will be done.


 * Similar to  but fail if the binary package cannot be downloaded.
 * Similar to  but fail if the binary package cannot be downloaded.

In order to automatically use binary package installations, the appropriate option can be added to the  variable:

There is a portage feature that automatically implements the equivalent of  without the need for updating the   variable: getbinpkg.

Pulling packages from a binary package host
When using a binary package host, clients need to have the  variable set. Otherwise the client will not know where the binary packages are stored (and how to retrieve them).

The  variable uses a space-separated list of URIs. This allows administrators to use several binary package servers simultaneously. The URI must always point to the directory in which the file resides.

Reinstalling modified binary packages
The  option to   will reinstall every binary that has been rebuild since the package was installed. This is useful in case rebuilding tools like  or   are run on the binary package server.

A related option is. It causes emerge not to consider binary packages for a re-install if those binary packages have been built before the given time stamp. This is useful to avoid re-installing all packages, if the binary package server had to be rebuild from scratch but  is used otherwise.

Additional client settings
Next to the getbinpkg feature, portage also listens to the binpkg-logs feature. This one controls if log files for successful binary package installations should be kept. It is only relevant if  is set and is enabled by default.

Similar to excluding binary packages for a certain set of packages or categories, clients can be configured to exclude binary package installations for a certain set of packages or categories.

To accomplish this, use the  option:

Maintaining binary packages
Exporting and distributing the binary packages will lead to useless storage consumption if the binary package list is not actively maintained.

Removing outdated binary packages
In the package an application called   is provided. It allows for maintaining portage-related variable files, such as downloaded source code files, but also binary packages.

The following command will remove all binary packages that have no corresponding ebuild:

For more details please read the Eclean article.

Another tool that can be used is the  tool from the. However, this tool is a bit less configurable.

To clean up unused binary packages (in the sense of used by the server on which the binary packages are stored):

Maintaining the Packages file
Inside the packages directory, a file called exists. This file acts as a cache for the metadata of all binary packages in the packages directory. The file is updated whenever portage adds a binary package to the directory. Similarly,  updates it when it removes binary packages.

If for some reason binary packages are simply deleted or copied into the packages directory, or the file gets corrupted or deleted, then it needs to be recreated. This is done using :

Creating snapshots of the packages directory
When deploying binary packages for a large number of client systems it might become worthwhile to create snapshots of the packages directory. The client systems then don't use the packages directory directly but use binary packages from the snapshot.

Snapshots can be created using the tool. It takes four arguments,
 * 1) a source directory (the path to the packages directory),
 * 2) a target directory (that must not exist),
 * 3) a URI, and
 * 4) a binary package server directory.

The files from the package directory are copied to the target directory. A file is then created inside the binary package server directory (fourth argument) with the provided URI.

Client systems need to use an URI that points to the binary package server directory. From there they will be redirected to the URI that was given to. This URI has to refer to the target directory.

Understanding the binary package format
Binary packages created by portage have the file name ending tbz2. These files consist of two parts:
 * 1) an .tar.bz2 archive containing the files that will be installed on the system, and
 * 2) an xpak archive containing the metadata, the ebuild and the environment file.

See  for a description of the format.

In some tools exists that are able to split or create tbz2 and xpak files.

The following command will split the tbz2 into a and an  file:

The xpak file can be examined using.

To list the contents:

The next command will extract a file called which contains the enabled use flags for this package:

The PKGDIR layout
The currently used format version 2 has the following layout:

Packages directory layout (version 2)

The is the major improvement (and also the trigger for portage to know that the binary package directory uses version 2) over the first binary package directory layout (version 1). In version 1, all binary packages were also hosted inside a single directory (called ) and the category directories only had symbolic links to the binary packages inside the directory.

Unpacking with quickunpkg
Zoobab wrote a simple shell tool named quickunpkg to quickly unpack tbz2 files.