Building in a clean chroot prevents missing dependancies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows you to build a package for the stable repositories (core, extra, community) while having packages from [testing] installed on your system.

+

Building in a clean chroot prevents missing dependencies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows users to build a package for the stable repositories (core, extra, community) while having packages from [testing] installed.

−

= Prerequisites =

+

= Convenience Way =

+

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

−

Building with chroots requires aufs2. You will need to install the aufs2 and aufs2-util packages before you get started

+

These helper scripts should be called in the same directory where the PKGBUILD is, just like with makepkg. For instance, {{ic|extra-i686-build}} automatically sets up chroot in {{ic|/var/lib/archbuild}}, updates it, and builds a package for the extra repository. For multilib builds there is just {{ic|multilib-build}} without an architecture.

−

# pacman -S aufs2 aufs2-util

−

= Setting Up A Chroot =

+

{{Tip|Consult the table below for information on which script to use when building for a specific repository and architecture.}}

−

The devtools package provides tools for creating and building within clean chroots. To make a clean chroot, create a directory you want it to reside in (example: <tt>~/chroot</tt>). For the purposes of this article this will be called <tt><chrootdir></tt>. Now create your chroot:

+

{{Note|[core] is omitted because those packages are required to go through [testing] first before landing in [core].}}

−

$ sudo mkarchroot <chrootdir>/root base base-devel sudo

+

{| class="wikitable"

+

! Target repository || Architecture || Build script to use

+

|-

+

| extra / community || i686 || extra-i686-build

+

|-

+

| extra / community || x86_64 || extra-x86_64-build

+

|-

+

| testing / community-testing || i686 || testing-i686-build

+

|-

+

| testing / community-testing || x86_64 || testing-x86_64-build

+

|-

+

| staging / community-staging || i686 || staging-i686-build

+

|-

+

| staging / community-staging || x86_64 || staging-x86_64-build

+

|-

+

| multilib || x86_64 || multilib-build

+

|-

+

| multilib-testing || x86_64 || multilib-testing-build

+

|-

+

| multilib-staging || x86_64 || multilib-staging-build

+

|}

−

Edit the <tt><chrootdir>/root/etc/makepkg.conf</tt> file to set the packager name and any makeflags. Also adjust the mirror list in <tt><chrootdir>/root/etc/pacman.d/mirrorlist</tt> and enable '''[testing]''' in <tt><chrootdir>/root/etc/pacman.conf</tt> if desired.

+

= Classic Way =

+

== Setting Up A Chroot ==

−

Alternatively, you can provide your own <tt>pacman.conf</tt> and <tt>makepkg.conf</tt> files with the following:

+

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

It is recommended however that you do not use custom <tt>pacman.conf</tt> and <tt>makepkg.conf</tt> files during the initial creation of clean chroot to ensure no user-specific adjustments are made. ''Use with caution.''

+

pacman -S devtools

−

= Building in the Chroot =

+

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

−

Firstly, make sure your chroot is up to date with:

+

Now create the chroot:

−

$ sudo mkarchroot -u <chrootdir>/root

+

CHROOT=$HOME/chroot

+

mkdir $CHROOT

+

sudo mkarchroot $CHROOT/root base base-devel sudo

−

Then, to build a package in your chroot run

+

{{Note|One can also define the CHROOT variable in $HOME/.bashrc using the export command if the location is to be repeatedly used. }}

−

$ sudo makechrootpkg -c -r <chrootdir>

+

Edit {{ic|$CHROOT/root/etc/makepkg.conf}} to set the packager name and any makeflags. Also adjust the mirror list in {{ic|$CHROOT/root/etc/pacman.d/mirrorlist}} and enable '''[testing]''' in {{ic|$CHROOT/root/etc/pacman.conf}} if desired.

−

A unionfs is used to maintain the clean chroot during building. All installed dependencies or makedepends and other changes made during building are done in <chrootdir>/rw. Passing the -c flag to makechrootpkg ensures that this directory is cleaned before building starts.

+

Alternatively, provide a custom{{ic|pacman.conf}} and {{ic|makepkg.conf}} with the following:

It is recommended however users do not use custom {{ic|pacman.conf}} and {{ic|makepkg.conf}} during the initial creation of clean chroot to ensure no user-specific adjustments are made. ''Use with caution.''

+

+

== Building in the Chroot ==

+

+

Firstly, make sure the chroot is up to date with:

+

+

sudo mkarchroot -u $CHROOT/root

+

+

Then, to build a package in the chroot, run the following from the dir containing the PKGBUILD:

+

+

sudo makechrootpkg -c -r $CHROOT

+

+

A unionfs is used to maintain the clean chroot during building. All installed dependencies or makedepends and other changes made during building are done in $CHROOT/rw. Passing the -c flag to makechrootpkg ensures that this directory is cleaned before building starts.

= Handling Major Rebuilds =

= Handling Major Rebuilds =

−

The cleanest way to handle a major rebuild is to create a new chroot and build your first package (typically the package you are doing the rebuild for). Then create a local repo in your new chroot. To do this:

+

The cleanest way to handle a major rebuild is to create a new chroot and build the first package (typically the package for which the rebuild is meant). Then create a local repo inside the new chroot. To do this:

−

$ sudo mkdir <chrootdir>/root/repo

+

sudo mkdir $CHROOT/root/repo

−

$ sudo chmod 777 <chrootdir>/root/repo

+

sudo chmod 0777 $CHROOT/root/repo

−

The chmod statement allows you to copy package files and create the local repo as your user rather than root.

+

The chmod statement allows for the coping of package files and for the creation of the local repo as your user rather than root.

−

$ cp <package> <chrootdir>/root/repo

+

cp <package> $CHROOT/root/repo

−

$ cd <chrootdir>/root/repo

+

cd $CHROOT/root/repo

−

$ repo-add local.db.tar.gz <package>

+

repo-add local.db.tar.gz <package>

−

Then add the local repo to <chrootdir>/root/etc/pacman.conf

+

Then add the local repo to {{ic|$CHROOT/root/etc/pacman.conf}}

[local]

[local]

Server = file:///repo

Server = file:///repo

−

and update your repo

+

As long as you add only self built packages to this repo, you can add

+

+

SigLevel = TrustAll

+

+

and update the repo:

−

$ sudo mkarchroot -u <chrootdir>/root

+

sudo mkarchroot -u $CHROOT/root

−

With every additional package rebuilt, copy the package to the local repo directory, add it to the repo database and update your chroot.

+

With every additional package rebuilt, copy the package to the local repo directory, add it to the repo database and update the chroot.

= Alternate Rebuild Handling =

= Alternate Rebuild Handling =

Line 71:

Line 113:

Build packages using:

Build packages using:

−

$ sudo makechrootpkg -r <chrootdir> -u

+

sudo makechrootpkg -r $CHROOT -u

The -u will update the chroot before building (-Syu) but updates will be installed to the rw layer, maintaining a clean chroot.

The -u will update the chroot before building (-Syu) but updates will be installed to the rw layer, maintaining a clean chroot.

== Manual package installation ==

== Manual package installation ==

Packages can be installed manually to the rw layer of the chroot by using:

Packages can be installed manually to the rw layer of the chroot by using:

−

$ sudo makechrootpkg -r <chrootdir> -I package-1.0-1-i686.pkg.tar.gz

+

sudo makechrootpkg -r $CHROOT -I package-1.0-1-i686.pkg.tar.gz

== Installation after building ==

== Installation after building ==

−

You can tell makechrootpkg to simply install a package to the rw layer of the chroot after building by passing the -i arg. Unrecognized args get passed to makepkg, so this calls `makepkg` with the -i arg.

+

Tell makechrootpkg to simply install a package to the rw layer of the chroot after building by passing the -i arg. Unrecognized args get passed to makepkg, so this calls `makepkg` with the -i arg.

Introduction

Why

Building in a clean chroot prevents missing dependencies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows users to build a package for the stable repositories (core, extra, community) while having packages from [testing] installed.

Convenience Way

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

These helper scripts should be called in the same directory where the PKGBUILD is, just like with makepkg. For instance, extra-i686-build automatically sets up chroot in /var/lib/archbuild, updates it, and builds a package for the extra repository. For multilib builds there is just multilib-build without an architecture.

Tip: Consult the table below for information on which script to use when building for a specific repository and architecture.

Note: [core] is omitted because those packages are required to go through [testing] first before landing in [core].

Target repository

Architecture

Build script to use

extra / community

i686

extra-i686-build

extra / community

x86_64

extra-x86_64-build

testing / community-testing

i686

testing-i686-build

testing / community-testing

x86_64

testing-x86_64-build

staging / community-staging

i686

staging-i686-build

staging / community-staging

x86_64

staging-x86_64-build

multilib

x86_64

multilib-build

multilib-testing

x86_64

multilib-testing-build

multilib-staging

x86_64

multilib-staging-build

Classic Way

Setting Up A Chroot

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

pacman -S devtools

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

Note: One can also define the CHROOT variable in $HOME/.bashrc using the export command if the location is to be repeatedly used.

Edit $CHROOT/root/etc/makepkg.conf to set the packager name and any makeflags. Also adjust the mirror list in $CHROOT/root/etc/pacman.d/mirrorlist and enable [testing] in $CHROOT/root/etc/pacman.conf if desired.

Alternatively, provide a custompacman.conf and makepkg.conf with the following:

It is recommended however users do not use custom pacman.conf and makepkg.conf during the initial creation of clean chroot to ensure no user-specific adjustments are made. Use with caution.

Building in the Chroot

Firstly, make sure the chroot is up to date with:

sudo mkarchroot -u $CHROOT/root

Then, to build a package in the chroot, run the following from the dir containing the PKGBUILD:

sudo makechrootpkg -c -r $CHROOT

A unionfs is used to maintain the clean chroot during building. All installed dependencies or makedepends and other changes made during building are done in $CHROOT/rw. Passing the -c flag to makechrootpkg ensures that this directory is cleaned before building starts.

Handling Major Rebuilds

The cleanest way to handle a major rebuild is to create a new chroot and build the first package (typically the package for which the rebuild is meant). Then create a local repo inside the new chroot. To do this:

sudo mkdir $CHROOT/root/repo
sudo chmod 0777 $CHROOT/root/repo

The chmod statement allows for the coping of package files and for the creation of the local repo as your user rather than root.