Руководство по бинарным пакетам

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

Other languages:
Deutsch • ‎English • ‎español • ‎日本語 • ‎한국어 • ‎русский • ‎中文(中国大陆)‎

На ряду с обычной поддержкой ebuild, Portage поддерживает сборку и установку бинарных пакетов. Это руководство объясняет, как создать их, установить и как настроить сервер бинарных пакетов.


Есть много причин, почему некоторым системным администраторам нравится устанавливать пакеты Gentoo в виде бинарных пакетов.

  1. First of all, it allows administrators to keep similar systems updated. Having to compile everything from source can become time consuming. Maintaining several similar systems, possibly some of them with older hardware, 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 to itself. Once the staging server is in a good state the updates can then be applied to the critical systems. 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. Often binary packages are the only way of recovering a broken system (i.e. broken compiler). Having pre-compiled binaries around either on a binary package server or locally can be of great help in case of a broken toolchain.
  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 helpful to install binary packages on old systems because they do not require build time dependencies to be installed/updated. Binaries packages also avoid failures in build processes since they are pre-compiled.

В этом руководстве основное внимание будет уделено следующим темам:

  • как создать бинарные пакеты;
  • как предоставить бинарные пакеты клиенту;
  • как использовать бинарные пакеты;
  • как обслуживать бинарные пакеты.

Near the end a few more advanced topics on dealing with binary packages will be covered.

Все инструменты, которые используются в этом руководстве, являются частью пакета sys-apps/portage, если не указано иное.

Создание бинарных пакетов

Существует три основных способа создания бинарных пакетов:

  1. после обычной установки использовать приложение quickpkg;
  2. явно, во время каждого запуска emerge, использовать опцию --buildpkg (-b);
  3. автоматически, с помощью функции Portage buildpkg.

Все три метода создадут бинарные пакеты в каталоге, который указан в переменной PKGDIR (по умолчанию это /usr/portage/packages).

Использование quickpkg

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

Например, для создания бинарных пакетов для всех установленных версий GCC:

root #quickpkg sys-devel/gcc

Используйте *, для того чтобы создать бинарные пакеты для всех установленных пакетов в системе:

root #quickpkg "*/*"

There is a caveat with this method: 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 (perhaps even confidential) data into the packages, quickpkg by default does not include configuration files that are protected through the CONFIG_PROTECT method. To force inclusion of configuration files, use the --include-config or --include-unmodified-config options.

Использование --buildpkg как опции emerge

При установке программ с помощью emerge можно попросить Portage создавать бинарные пакеты, использовав опцию --buildpkg (-b):

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

Так же можно попросить Portage только создать бинарный пакет без установки пакета в систему. Для этого необходимо использовать опцию --buildpkgonly (-B):

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

The latter approach however requires all build time dependencies to be previously installed.

Implementing buildpkg as a Portage feature

The most common way to automatically create binary packages whenever a package is installed by Portage is to use the buildpkg feature, which can be set in /etc/portage/make.conf like so:

Файл /etc/portage/make.confВключение функции Portage buildpkg

With this feature enabled, every time Portage installs software it will create a binary package as well.

Исключение для некоторых пакетов

It is possible to tell Portage not to create binary packages for a select few packages or categories. This is done by passing the --buildpkg-exclude option to emerge:

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

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

Настройка хоста бинарных пакетов

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 desired setup additional software will need to be installed.

Хост бинарных пакетов на основе веб

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

Use a web server such as lighttpd (www-servers/lighttpd) and configure it to provide read access to /etc/portage/make.conf's PKGDIR location.

Файл /etc/lighttpd/lighttpd.confПример конфигурации lighttpd
# добавьте это в конец стандартной конфигурации
server.modules += ( "mod_alias" )
alias.url = ( "/packages" => "/usr/portage/packages/" )

Then, on the client systems, configure the PORTAGE_BINHOST variable accordingly:

Файл /etc/portage/make.confUsing a web-based binary package host

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 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 Portage 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 portage.id_rsa.pub >> /home/binpkguser/.ssh/authorized_keys

The PORTAGE_BINHOST variable could then look like so:

Файл /etc/portage/make.confНастройка PORTAGE_BINHOST для SSH-доступа
Don't use ssh's config in ~/.ssh/config for setting ports or username as it'll be 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.

Файл /etc/exports может выглядеть так:

Файл /etc/exportsExporting the packages directory
/usr/portage/packages                            2001:db8:81:e2::/48(ro,no_subtree_check,root_squash),no_subtree_check,root_squash)

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

Файл /etc/fstabЗапись для монтирования папки с пакетами
binhost:/usr/portage/packages      /usr/portage/packages    nfs    defaults    0 0

Использование бинарных пакетов

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 features (like MMX, SSE,...) have to be carefully selected; all clients need to support them.
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.

Установка бинарных пакетов

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

Option Description
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.
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.
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.
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:

Файл /etc/portage/make.confAutomatically fetching binary packages and fail if not available

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

Файл /etc/portage/make.confВключение функции Portage getbinpkg

Получение пакетов с хоста бинарных пакетов

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.

Файл /etc/portage/make.confНастройка PORTAGE_BINHOST

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.

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.

Reinstalling modified binary packages

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 or python-updater 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.

Дополнительные настройки клиента

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/*"

Обслуживание бинарных пакетов

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

Удаление устаревших бинарных пакетов

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:

root #eclean packages

Для дополнительной, пожалуйста, прочтите статью Eclean.

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, a file called Packages 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, 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

Создание снимка каталога пакетов

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.

Understanding the binary package format

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.

Для описания формата смотрите man xpak.

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 <package>.tbz2

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

To list the contents:

user $qxpak -l <package>.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:

Код Схема каталога с пакетами (версия 2)
`+- 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.

Распаковка с помощью quickunpkg

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