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

From ArchWiki
Jump to: navigation, search
m (added pacman code snippet)
m (prepended credentials prompt character)
Line 16: Line 16:
 
The devtools package provides tools for creating and building within clean chroots.  To make a clean chroot, firstly create the directory you want it to reside in. For the purposes of this article this will be called <chrootdir>.  The create your chroot using
 
The devtools package provides tools for creating and building within clean chroots.  To make a clean chroot, firstly create the directory you want it to reside in. For the purposes of this article this will be called <chrootdir>.  The create your chroot using
  
  sudo mkarchroot -C <pacman.conf> -M <makepkg.conf> <chrootdir>/root base base-devel sudo
+
  $ sudo mkarchroot -C <pacman.conf> -M <makepkg.conf> <chrootdir>/root base base-devel sudo
  
 
The -C and -M flags are optional, but it is recommended to provide these with clean pacman.conf and makepkg.conf files (directly from the pacman package) during first creation of clean chroot to ensure lack of user specific adjustments.
 
The -C and -M flags are optional, but it is recommended to provide these with clean pacman.conf and makepkg.conf files (directly from the pacman package) during first creation of clean chroot to ensure lack of user specific adjustments.
Line 26: Line 26:
 
Firstly, make sure your chroot is up to date with:
 
Firstly, make sure your chroot is up to date with:
  
  sudo mkarchroot -u <chrootdir>/root
+
  $ sudo mkarchroot -u <chrootdir>/root
  
 
Then, to build a package in your chroot run
 
Then, to build a package in your chroot run
  
  sudo makechrootpkg -c -r <chrootdir>
+
  $ sudo makechrootpkg -c -r <chrootdir>
  
 
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.
 
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.
Line 38: Line 38:
 
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 you chroot.  To do this:
 
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 you chroot.  To do this:
  
  sudo mkdir <chrootdir>/root/repo
+
  $ sudo mkdir <chrootdir>/root/repo
  sudo chmod 777 <chrootdir>/root/repo
+
  $ sudo chmod 777 <chrootdir>/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 you to copy package files and create the local repo as your user rather than root.
  
  cp <package> <chrootdir>/root/repo
+
  $ cp <package> <chrootdir>/root/repo
  cd <chrootdir>/root/repo
+
  $ cd <chrootdir>/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 <chrootdir>/root/etc/pacman.conf
Line 54: Line 54:
 
and update your repo
 
and update your repo
  
  sudo mkarchroot -u <chrootdir>/root
+
  $ sudo mkarchroot -u <chrootdir>/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 your chroot.
Line 66: Line 66:
  
 
Build packages using:
 
Build packages using:
  sudo makechrootpkg -r <chrootdir> -u
+
  $ sudo makechrootpkg -r <chrootdir> -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 <chrootdir> -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.
 
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.
  sudo makechrootpkg -r <chrootdir> -- -i
+
  $ sudo makechrootpkg -r <chrootdir> -- -i

Revision as of 16:04, 10 December 2009

Introduction

This article is part of the DeveloperWiki.

Why

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.

Prerequisites

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

# pacman -S aufs2 aufs2-util

Setting Up A Chroot

The devtools package provides tools for creating and building within clean chroots. To make a clean chroot, firstly create the directory you want it to reside in. For the purposes of this article this will be called <chrootdir>. The create your chroot using

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

The -C and -M flags are optional, but it is recommended to provide these with clean pacman.conf and makepkg.conf files (directly from the pacman package) during first creation of clean chroot to ensure lack of user specific adjustments.

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

Building in the Chroot

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

$ sudo mkarchroot -u <chrootdir>/root

Then, to build a package in your chroot run

$ sudo makechrootpkg -c -r <chrootdir>

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.

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 you chroot. To do this:

$ sudo mkdir <chrootdir>/root/repo
$ sudo chmod 777 <chrootdir>/root/repo

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

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

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

[local]
Server = file:///repo

and update your repo

$ sudo mkarchroot -u <chrootdir>/root

With every additional package rebuilt, copy the package to the local repo directory, add it to the repo database and update your 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 <chrootdir> -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 <chrootdir> -I package-1.0-1-i686.pkg.tar.gz

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.

$ sudo makechrootpkg -r <chrootdir> -- -i