Movatterモバイル変換


[0]ホーム

URL:


Jump to content
ArchWiki
Search

DeveloperWiki:Building in a clean chroot

From ArchWiki

Building in a clean chroot prevents missing dependencies in packages, whether due to unwanted linking or packages missing in thedepends array in aPKGBUILD file. It also allows users to build a package for the stable repositories (core,extra) while having packages fromcore-testing orextra-testing installed.

Convenience way

To quickly build a package in a clean chroot without any further tinkering, one can use the helper scripts from thedevtools package.

These helper scripts—for example,pkgctl build—should be called in the same directory where thePKGBUILD file is, just like with makepkg. For instance,extra-x86_64-build automatically sets up a chroot from a clean chroot matrix in/var/lib/archbuild, updates it, and builds a package for the extra repository. For multilib builds there is justmultilib-build without an architecture. Consult the table below for information on which script to use when building for a specific repository and architecture.

The-c parameter resets the chroot matrix, which can be useful in case of breakage. It is not needed for building in a clean chroot.

Note
  • core is omitted because those packages are required to go throughcore-testing first before landing incore.
  • If the objective is to build acore package for your own local usage, it may be desirable to use the stable repositories instead of the testing ones. In this case you may simply use the extra build scripts.
Target repositoryArchitectureBuild script to usePacman configuration file used
extrax86_64extra-x86_64-build/usr/share/devtools/pacman.conf.d/extra.conf
core-testing / extra-testingx86_64extra-testing-x86_64-build/usr/share/devtools/pacman.conf.d/extra-testing.conf
core-staging / extra-stagingx86_64extra-staging-x86_64-build/usr/share/devtools/pacman.conf.d/extra-staging.conf
multilibx86_64multilib-build/usr/share/devtools/pacman.conf.d/multilib.conf
multilib-testingx86_64multilib-testing-build/usr/share/devtools/pacman.conf.d/multilib-testing.conf
multilib-stagingx86_64multilib-staging-build/usr/share/devtools/pacman.conf.d/multilib-staging.conf
Tippkgctl-build(1) automatically chooses the right build script to build in a clean chroot.

Classic way

Setting up a chroot

Thedevtools package provides tools for creating and building within clean chroots. Install it if not done already.

To make a clean chroot, create a directory in which the chroot will reside. For example,$HOME/chroot.

$ mkdir ~/chroot

Define theCHROOT variable:

$ CHROOT=$HOME/chroot

Now create the chroot (the sub directoryroot is required because the$CHROOT directory will get other sub directories for clean working copies):

$ mkarchroot $CHROOT/root base-devel
Note
  • One can also define theCHROOT variable in$HOME/.bashrc using the export command if the location is to be repeatedly used.
  • OnBtrfs, the chroot is created as asubvolume.

Edit~/.makepkg.conf to set the packager name and any makeflags. Also adjust themirrorlist in$CHROOT/root/etc/pacman.d/mirrorlist and enable thetesting repositories in$CHROOT/root/etc/pacman.conf, if desired.

Note The~ and$HOME variable are resolved to/root/ by themakechrootpkg script (described below).

Custom pacman.conf

Alternatively, provide a custompacman.conf andmakepkg.conf with the following:

$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
Warning Using a custompacman.conf ormakepkg.conf during the initial creation of clean chroot can result in unintended custom adjustments to the chroot environment.Use with caution.

Building in the chroot

Firstly, make sure the base chroot ($CHROOT/root) is up to date:

$ arch-nspawn $CHROOT/root pacman -Syu

Then, build a package by callingmakechrootpkg in the directory containing itsPKGBUILD file:

$ makechrootpkg -c -r $CHROOT
Note Passing the-c flag tomakechrootpkg ensures that the working chroot ($CHROOT/$USER) is cleaned before building.

Pre-install required packages

To build a package with dependencies unavailable from the repositories enabled in$CHROOT/root/pacman.conf, pre-install them to the working chroot with-Ipackage:

$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.zst -I required-package-2.0-2-x86_64.pkg.tar.zst

Passing arguments to makepkg

To pass arguments tomakepkg, list them after an end-of-options marker--. E.g., to force acheck():

$ makechrootpkg -c -r $CHROOT -- --check

Handling major rebuilds

The cleanest way to handle a major rebuild is to use thestaging repositories. Build the first package againstextra and push it tostaging. Then rebuild all following packages againststaging and push them there.

If you cannot usestaging, you can build against custom packages using a command like this:

# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.zst

You can specify more than one package to be installed using multiple-I arguments.

A simpler, but dirtier way to handle a major rebuild is to install all built packages in the chroot, never cleaning it. Build the first package using:

# extra-x86_64-build

And build all following packages using:

# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64

Running namcap (the-n argument) implies installing the package in the chroot.*-build also does this by default.

Tips and tricks

Build in tmpfs

If the system has enough RAM, it is possible to specify atmpfs for thedevtools build scripts:

# mount --mkdir -t tmpfs -o defaults,size=20G tmpfs /mnt/chroots/arch# extra-x86_64-build -c -r /mnt/chroots/arch

Deleting a chroot

Just delete the chroot directory and its corresponding.lock file.

Retrieved from "https://wiki.archlinux.org/index.php?title=DeveloperWiki:Building_in_a_clean_chroot&oldid=853640"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp