Guide sur les paquets binaires

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Binary package guide and the translation is 45% complete.

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.

Introduction

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 chroot 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.

Remarque
Tous les outils utilisés dans ce guide font partie de sys-apps/portage, sauf mention contraire.

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 quickpkg.
  2. Explicitement, au cours d'une opération emerge en utilisant l'option --buildpkg (-b)
  3. Automatiquement, en utilisant la valeur de buildpkg 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 /var/cache/binpkgs).

Utilisation de quickpkg

L'application quickpkg 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.

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

root #quickpkg sys-devel/gcc

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

root #quickpkg "*/*"

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 quickpkg 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 --include-config ou --include-unmodified-config.

Utilisation de --buildpkg comme option de emerge

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

root #emerge --ask --buildpkg sys-devel/gcc

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 --buildpkgonly (-B) :

root #emerge --ask --buildpkgonly sys-devel/gcc

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é buildpkg, qui peut être spécifiée comme suit dans /etc/portage/make.conf:

FILE /etc/portage/make.confActiver la fonctionnalité buildpkg de Portage
FEATURES="buildpkg"

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 --buildpkg-exclude à emerge :

root #emerge -uDN @world --buildpkg --buildpkg-exclude "virtual/* sys-kernel/*-sources"

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 www-client/firefox-bin).

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 (www-servers/lighttpd) et configurez-le pour fournir un accès en lecture à l'emplacement de la variable PKGDIR de /etc/portage/make.conf.

FILE /etc/lighttpd/lighttpd.conflighttpd: exemple de configuration
# Ajouter ceci à la fin de la configuration standard
server.modules += ( "mod_alias" )
alias.url = ( "/packages" => "/var/cache/binpkgs/" )

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

FILE /etc/portage/make.confUtilisation d'un serveur de paquets binaires sur Internet
PORTAGE_BINHOST="http://binhost.example.com/packages"

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 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:

root #cat root.id_rsa.pub >> /home/binpkguser/.ssh/authorized_keys

The PORTAGE_BINHOST variable could then look like so:

FILE /etc/portage/make.confSetting up PORTAGE_BINHOST for SSH access
PORTAGE_BINHOST="ssh://binpkguser@binhostserver/var/cache/binpkgs"
Remarque
Do not use the SSH configuration files found in ~/.ssh/config for setting ports or username. This location is ignored when Portage tries to rsync the packages back onto the client. Instead set all the options correctly in the PORTAGE_BINHOST variable.

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 /etc/exports file could look like so:

FILE /etc/exportsExporting the packages directory
/var/cache/binpkgs   2001:db8:81:e2::/48(ro,no_subtree_check,root_squash) 192.168.100.1/24(ro,no_subtree_check,root_squash)

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

FILE /etc/fstabEntry for mounting the packages folder
binhost:/var/cache/binpkgs      /var/cache/binpkgs    nfs    defaults    0 0

Utiliser des paquets binaires

For binary packages to be usable on other systems they must fulfill some requirements:

  • The client and server architecture and CHOST 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.
Important
Portage can not validate if these requirements match. It is the responsibility of the system administrator to guard these settings.

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 emerge command upon invocation (see Installing binary packages).

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 emerge command that inform Portage about using binary packages:

Option Description
--usepkg (-k) Tries to use the binary package(s) in the locally available packages directory. Useful when using NFS or SSHFS mounted binary package hosts. If the binary packages are not found, a regular (source-based) installation will be performed.
--usepkgonly (-K) Similar to --usepkg (-k) but fail if the binary package cannot be found. This option is useful if only pre-built binary packages are to be used.
--getbinpkg (-g) Download the binary package(s) from a remote binary package host. If the binary packages are not found, a regular (source-based) installation will be performed.
--getbinpkgonly (-G) Similar to --getbinpkg (-g) but will fail if the binary package(s) cannot be downloaded. This option is useful if only pre-built binary packages are to be used.

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

FILE /etc/portage/make.confAutomatically fetch binary packages and fail the package if not available
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkgonly"

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

FILE /etc/portage/make.confEnabling getbinpkg in the FEATURES variable
FEATURES="getbinpkg"

Pulling packages from a binary package host

When using a binary package host, clients need to have the PORTAGE_BINHOST variable set. Otherwise the client will not know where the binary packages are stored which results in Portage being unable to retrieve them.

FILE /etc/portage/make.confSetting PORTAGE_BINHOST
PORTAGE_BINHOST="http://binhost.example.com/packages"

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 Packages file resides.

Remarque
The support for multiple binary package servers is somewhat incomplete. If several servers serve a binary package for the same package version, then only the first one will be considered. This can be problematic when these binary packages differ in their USE variable configuration and the USE variable configuration of a later binary package would match the systems configuration.

Réinstaller des paquets binaires modifiés

Passing the --rebuilt-binaries option to emerge will reinstall every binary that has been rebuilt since the package was installed. This is useful in case rebuilding tools like revdep-rebuild are run on the binary package server.

A related option is --rebuilt-binaries-timestamp. 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 --rebuilt-binaries 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 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 --usepkg-exclude option:

root #emerge -uDNg @world --usepkg-exclude "sys-kernel/gentoo-sources virtual/*"

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

FILE /etc/portage/make.confEnabling emerge settings on every invocation
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg-exclude 'sys-kernel/gentoo-sources virtual/*'"

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 app-portage/gentoolkit package an application called eclean 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:

root #eclean packages

For more details please read the Eclean article.

Another tool that can be used is the qpkg tool from the app-portage/portage-utils 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):

root #qpkg -c

Maintaining the Packages file

Inside the packages directory exists a manifest file called Packages. 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, eclean updates it when it removes binary packages.

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

root #emaint binhost --fix

Advanced topics

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 /usr/lib64/portage/python2.7/binhost-snapshot or /usr/lib64/portage/python3.3/binhost-snapshot 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 Packages 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 binhost-snapshot. This URI has to refer to the target directory.

Comprendre le format des paquets binaires

Binary packages created by Portage have the file name ending with .tbz2. These files consist of two parts:

  1. A .tar.bz2 archive containing the files that will be installed on the system.
  2. A xpak archive containing package metadata, the ebuild, and the environment file.

See man xpak for a description of the format.

In app-portage/portage-utils some tools exists that are able to split or create tbz2 and xpak files.

The following command will split the tbz2 into a .tar.bz2 and an .xpak file:

user $qtbz2 -s <paquet>.tbz2

The .xpak file can be examined using the qxpak utility.

To list the contents:

user $qxpak -l <paquet>.xpak

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

user $qxpak -x package-manager-0.xpak USE

The PKGDIR layout

The currently used format version 2 has the following layout:

CODE Packages directory layout (version 2)
PKGDIR
`+- Packages
 +- app-accessibility/
 |  +- pkg1-version.tbz2
 |  `- pkgN-version.tbz2
 +- app-admin/
 |  `- ...
 `- ...

The Packages 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 All/) and the category directories only had symbolic links to the binary packages inside the All/ directory.

Unpacking with quickunpkg

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