Difference between revisions of "DeveloperWiki:Building in a Clean Chroot"

From ArchWiki
Jump to: navigation, search
(written in third person and added variable $CHROOT to avoid confusion and simplify)
(removed prefixes to users and just copy/paste)
Line 37: Line 37:
 
Firstly, make sure the chroot is up to date with:
 
Firstly, make sure the chroot is up to date with:
  
  $ sudo mkarchroot -u $CHROOT/root
+
  sudo mkarchroot -u $CHROOT/root
  
 
Then, to build a package in in the chroot, run the following from the dir containing the PKGBUILD:
 
Then, to build a package in in the chroot, run the following from the dir containing the PKGBUILD:
  
  $ sudo makechrootpkg -c -r $CHROOT
+
  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.
 
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.
Line 49: Line 49:
 
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:
 
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 mkdir $CHROOT/root/repo
  $ sudo chmod 777 <$CHROOT/root/repo
+
  sudo chmod 777 <$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.
 
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> $CHROOT/root/repo
+
  cp <package> $CHROOT/root/repo
  $ cd $CHROOT/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 {{ic|$CHROOT/root/etc/pacman.conf}}
 
Then add the local repo to {{ic|$CHROOT/root/etc/pacman.conf}}
Line 65: Line 65:
 
and update the repo:
 
and update the repo:
  
  $ sudo mkarchroot -u $CHROOT/root
+
  sudo mkarchroot -u $CHROOT/root
  
 
With every additional package rebuilt, copy the package to the local repo directory, it to the repo database and update the chroot.
 
With every additional package rebuilt, copy the package to the local repo directory, it to the repo database and update the chroot.
Line 77: Line 77:
  
 
Build packages using:
 
Build packages using:
  $ sudo makechrootpkg -r $CHROOT -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 $CHROOT -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 ==
 
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.
  $ sudo makechrootpkg -r $CHROOT -- -i
+
  sudo makechrootpkg -r $CHROOT -- -i

Revision as of 18:17, 8 January 2012


Introduction

This article is part of the DeveloperWiki.

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: $REPO-$ARCH-build

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/tmp/archbuild, updates it, and builds a package for the extra repository. For multilib builds there is just multilib-build without an architecture.

Classic Way

Setting Up A Chroot

The devtools package provides tools for creating and building within clean chroots. To make a clean chroot, create a directory in which the chroot will reside. For example, /tmp/WORK/chroot.

Now create the chroot:

$ CHROOT=/tmp/WORK/chroot
$ mkdir $CHROOT
$ sudo mkarchroot $CHROOT/root base base-devel sudo

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] $CHROOT/root/etc/pacman.conf if desired.

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

$ sudo mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base base-devel sudo

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 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 777 <$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.

cp <package> $CHROOT/root/repo
cd $CHROOT/root/repo
repo-add local.db.tar.gz <package>

Then add the local repo to $CHROOT/root/etc/pacman.conf

[local]
Server = file:///repo

and update the repo:

sudo mkarchroot -u $CHROOT/root

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

Alternate Rebuild Handling

The above directions will work fine, but they can dirty the "pristine" chroot that makechrootpkg tries to keep in check (that is the point of using unionfs - dirtying a separate 'rw' directory).

Using a custom repo

Follow the steps above to setup a local repo inside the chroot.

Build packages using:

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.

Manual package installation

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

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

Installation after building

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.

sudo makechrootpkg -r $CHROOT -- -i