Binary package guide/fr

Outre la compilation à partir de fichiers ebuild, Portage permet de créer et d'installer des paquets binaires. Ce guide explique comment les créer, les installer et mettre en place un serveur de paquets binaires.

Il y a de nombreuses raisons qui expliquent que les administrateurs système aiment utiliser des paquets binaires sur Gentoo :


 * 1) Cela permet aux administrateurs de gagner du temps quand il faut mettre à jour des systèmes similaires. Devoir tout compiler à partir des sources peut parfois s'avérer chronophage. Maintenir plusieurs systèmes similaires, éventuellement pour certains d'entre eux composés de matériels plus anciens, peut être plus aisé si un seul système réalise toutes les compilations depuis les sources et les autres systèmes utilisent les paquets ainsi produits.
 * 2) Effectuer des mises à jour sécurisées. Pour les systèmes  dont la disponibilité est un enjeu critique pour la production, il est important de rester utilisable autant que possible. Cet objectif peut être atteint par l'utilisation d'un serveur qui, dans une première étape, opère l'ensemble des mises à jour en local. Une variante de cette approche consiste à opérer les actualisations en   sur le même système et à utiliser les paquets binaires ainsi créés sur le système de fichiers parent du serveur.
 * 3) Comme sauvegarde. Souvent les paquets binaires sont la seule façon de récupérer un système endommagé (par exemple un compilateur). Avoir des paquets binaires pré-compilés à disposition, soit sur un serveur dédié ou en local peut être d'un grand secours en cas de dommage rencontré dans la chaîne logicielle du système d'exploitation.
 * 4) Cela permet de faciliter la mise à jour de systèmes très anciens Ces mises à jour peuvent être grandement facilités par l'utilisation de paquets binaires. Il est souvent utile d'installer des paquets binaires sur des systèmes anciens, en raison de l'absence de dépendances de compilation pour leur installation ou mise à jour. Cela permet aussi d'éviter des échecs dans le processus de compilation puisque les paquets sont pré-compilés.

Ce guide sera centré sur les thèmes suivants :


 * Comment créer des paquets binaires.
 * Les distribuer aux clients.
 * Implémenter cette fonctionnalité.
 * Maintenir les paquets binaires.

Vers la fin de cette page, quelques sujets plus avancés sont abordés.

Binary package formats
Starting with portage version 3.0.31, a new binary package format (GPKG) support has been added. The new format was completely redesigned to solve issues with the old design and to include new features, therefore no backward compatibility is provided. If users need to create binary packages for the system using older versions of Portage, please keep using the current XPAK format.

Motivation for the new GPKG format can be found in GLEP 78: Gentoo binary package container format. See also and.

To use new GPKG format, set the BINPKG_FORMAT value in. The default value is xpak.

This guide applies to both formats. See the section for more information on the binary package formats.

Créer des paquets binaires
Il y a trois méthodes principales pour créer des paquets binaires :


 * 1) Après une installation standard, utiliser l'application.
 * 2) Explicitement, au cours d'une opération  en utilisant l'option
 * 3) Automatiquement, en utilisant la valeur de   pour la variable FEATURES de Portage.

Les trois méthodes créeront un paquet binaire dans le répertoire indiqué par la variable PKGDIR (qui par défaut prend la valeur ).

Utilisation de quickpkg
L'application prend comme argument un ou plusieurs atomes (ou ensembles de paquets) et crée des paquets binaires pour tous les paquets "installés" qui leur correspondent.

Attention, cette méthode doit être utilisée avec prudence, car elle part des fichiers installés, ce qui peut poser problème en cas de fichiers de configurations spécifiques à la machine source. Les administrateurs changent souvent ces fichiers de configuration après avoir installé les logiciels. Dès lors que l'inclusion des fichiers de configuration pourrait poser des problèmes de diffusion de données importantes (et parfois même confidentielles) dans les paquets, par défaut n'inclut pas les fichiers de configuration qui sont protégés par la méthode CONFIG_PROTECT. Pour forcer l'inclusion de ces fichiers de configuration, utiliser les options  ou.

Par exemple, pour créer les paquets binaires de toutes les versions installées de GCC :

To create binary packages for the system set:

Pour créer les paquets binaires de tous les paquets installés sur le système, utiliser le glob  :

Utilisation de --buildpkg comme option de emerge
Lorsque l'installation du logiciel est opérée par, Portage peut installer des fichiers binaires si l'option   est ajoutée à la ligne de commande :

Il est aussi possible de demander à Portage de créer seulement un paquet binaire mais sans installer le logiciel sur le système à chaud. Dans ce cas, utiliser l'option   :

Cette dernière approche nécessite toutefois que toutes les dépendances de compilation soient préalablement installées.

Utilisation de buildpkg comme variable FEATURE de Portage
La façon la plus courante de créer automatiquement des paquets binaires lorsqu'un paquet est installé par Portage est d'utiliser la fonctionnalité, qui peut être spécifiée comme suit dans :

Une fois cette fonctionnalité activée, chaque fois que Portage installera un logiciel, il créera un paquet binaire également.

Comment exclure la création de certains paquets
Il est possible de dire à Portage de ne pas créer de paquets binaires pour quelques paquets ou catégories sélectionnés. Cela se fait en passant l'option  à emerge :

Cette façon de faire peut être retenue pour les paquets dont le déploiement au format binaire ne présente que peu ou pas d'avantage. Des exemples pourraient être les paquets source du noyau Linux ou les packages binaires déployés en amont (ceux se terminant par -bin comme ).

Binary package compression formats
It is possible to use a specific compression type on binary packages. Currently, the following formats are supported:,  ,  ,  ,  ,  , and. Defaults to. Review and search for BINPKG_COMPRESS for the most up-to-date information.

The compression format can be specified via.

Note that the compression type used might require extra dependencies to be installed, for example, in this case.

Binary package OpenPGP signing
GPG signature allows users to check the creator and integrity of a binary package, and to perform trust management based on keys. The binary package signing feature is disabled by default, to use it users need to enable the  feature. Note that whether this feature is enabled does not affect the signature verification feature.

Users also need to set the BINPKG_GPG_SIGNING_GPG_HOME and BINPKG_GPG_SIGNING_KEY variables for Portage to find the signing key.

Portage will only try to unlock the GPG private key at the beginning. If the user's key will expire over time, then consider enabling  to prevent signing failures.

Mise en place d'un serveur de paquets binaires
Portage prend en charge un certain nombre de protocoles pour télécharger des paquets binaires : FTP, FTPS, HTTP, HTTPS et SSH/SFTP. Cela permet d'envisager de nombreuses implémentations éventuelles de serveurs de paquets binaires.

Il n'y a cependant aucune méthode "prête à l'emploi" fournie par Portage pour distribuer des paquets binaires. Selon la configuration souhaitée, des logiciels supplémentaires devront être installés.

Un serveur de paquets binaires sur Internet
Une approche courante pour distribuer des packages binaires consiste à créer un hôte de packages binaires raccordé à Internet.

Utilisez un serveur Web tel que lighttpd et configurez-le pour fournir un accès en lecture à l'emplacement de la variable PKGDIR de.

Puis, sur les systèmes clients, configurer la variable PORTAGE_BINHOST en conséquence:

SSH binary package host
To provide an authenticated approach for binary package mirrors, Portage can be configured to use the SSH protocol to access binary packages.

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

To accomplish this, make sure that the root user's SSH key is allowed on the server. This will need to happen for each machine that will connect to the SSH capable binary host:

The PORTAGE_BINHOST variable could then look like so:

NFS exported
When using binary packages on an internal network, it might be easier to 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:

The NFS share is mounted on the local filesystem, so there is no need to set PORTAGE_BINHOST or use the  option. Instead, follow the normal procedures for, remembering to point PKGDIR to the NFS share so that portage knows where to find the packages:

Utiliser des paquets binaires
For binary packages to be usable on other systems they must fulfill some requirements:


 * The client and server architecture and must match.
 * The CFLAGS and CXXFLAGS variables used to build the binary packages must be compatible with all clients.
 * USE flags for processor specific instruction set features (like MMX, SSE, etc.) have to be carefully selected; all clients need to support them.

The utility can be used to find a subset of CFLAGS that is supported by both the server and client(s). For example, the host might return:

While the client might return:

In this example CFLAGS could be set to  since   is a full subset of. and  are not included as these are not supported but the client. However,  is included as the client does not support. To find which 's are subsets of others, check the [//gcc.gnu.org/onlinedocs/gcc/x86-Options.html gcc manual], if there is no suitable subset set e.g..

Optionally, it is also possible to set  or   to tell gcc to tune code to a specific arch. In contrast to, the   argument does not prevent code from being executed on other processors. For example, to compile code which is compatible with ivybridge and up but is tuned to run best on skylake set CFLAGS to. When  is not set it defaults to whatever   is set to.

When changing  to a lower subset for using binary packages on a client, a full recompilation is required to make sure that all binaries are compatible with the client's processor, to save time packages that are not compiled with e.g. gcc/clang can be excluded:

Similarly, can be used to find a suitable subset of processor specific instruction set USE flags. For example, the host might return:

While the client might return:

In this example CPU_FLAGS_X86 can be set to  in  because these flags are supported by both the client and the host

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 to the command upon invocation (see ).

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

Installer des paquets binaires
There are a few options that can be passed on to the command that inform Portage about using binary packages:

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

There is a Portage feature that automatically implements the equivalent of   without the need for updating the EMERGE_DEFAULT_OPTS variable with the   value:

Verify binary package's OpenPGP signature
This feature is only available in GPKG format.

Portage will try to verify the binary package's signature whenever possible, but users must first set up trusted local keys. A GPG key management tool for portage is in the plan, but for now, users have to manage it manually.

The GPG database of portage is stored in by default.

The following script will create a local trusted master key, import key  from keys.openpgp.org, and trust it. Please modify it to a key trusted by the user.

Make sure is global readable, portage will drop root privileges when verifying binary packages.

By default, Portage will only verify GPG signatures when a signature file is found in a package, which allows the user to mix signed and unsigned GPKG binary packages from different sources, and allows to use of old XPAK format binary packages.

If the user needs to force signature verification, the  feature needs to be enabled. This feature assumes that all packages should be signed and rejects any unsigned package. Note that this feature does not support per binhost configuration.

Pulling packages from a binary package host
When using a binary package host, clients need to have the PORTAGE_BINHOST variable set in or the sync-uri variable in. The latter option is preferred over setting the PORTAGE_BINHOST. Without this configuration, the client will not know where the binary packages are stored which results in Portage being unable to retrieve them.

The PORTAGE_BINHOST 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.

For each binhost, a name can be configured in the brackets. sync-uri must point to the directory in which the file resides. Optionally, priority can be set. When a package exists in multiple binary package repositories, the package is pulled from the binary package host with the highest priority. This way, a preferred binary package host can be set up.

Réinstaller des paquets binaires modifiés
Passing the  option to  will reinstall every binary that has been rebuilt since the package was installed. This is useful in case rebuilding tools like 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  feature, Portage also listens to the   feature. This one controls if log files for successful binary package installations should be kept. It is only relevant if the PORT_LOGDIR variable has been 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:

To enable such additional settings for each emerge command, add the options to the EMERGE_DEFAULT_OPTS variable in the file:

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 in the installed ebuild repositories:

For more details please read the article.

Another tool that can be used is the tool from the  package. 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 exists a manifest file called. 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 must be recreated. This is done using command:

Building for other architectures
is a tool that will easily build cross compile toolchains to allow setting up a binary host for a different architecture, for example for a device like a from a more powerful desktop PC.

An installation guide for this package can be found at the page.

Build a cross compiler
Using crossdev with the following command can build a toolchain for the desired system:

For the rest of this section, the example target will be for a Raspberry Pi 4:

After this has built, a toolchain will have been created in, and will look like a bare bones Gentoo install where it is possible to edit settings as normal.

Basic setup
Removing the  flag from the USE line in  is generally recommended in a setup like this:

Profiles
List available profiles for the device by running:

Next, select the profile that best suits:

Build a single package
To build a single binary package for use on the device, use the following:

Build world file
To build every package in the world file, then the following command is needed:

Binary location
By default, all binary packages will be stored in, so this is the location needed to be selected when.

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 do not use the packages directory directly but use binary packages from the snapshot.

Snapshots can be created using the or  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.
 * 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.

XPAK format
XPAK format binary packages created by Portage have the file name ending with. These files consist of two parts:


 * 1) A  archive containing the files that will be installed on the system.
 * 2) A  archive containing package 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  and  files.

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

The file can be examined using the  utility.

To list the contents:

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

GPKG format
GPKG format binary packages created by Portage have the file name ending with. These files consist of four parts at least:


 * 1) A  empty file that used to identify the format.
 * 2) A  archive containing package metadata, the ebuild, and the environment file.
 * 3) A  archive containing the files that will be installed on the system.
 * 4) A  file containing all files checksum that will be used to check for file corruption.
 * 5) Multiple optional  files containing OpenPGP signature are used for integrity checking and trust management.

The format can be extracted by tar without the need for additional tools.

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

The file 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.

In portage-3.0.15 and later, FEATURES=binpkg-multi-instance is enabled by default:

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

External resources
quickpkg man page.