pbuilder 利用マニュアル

利用と操作方法について

Uekawa Junichi [FAMILY Given]

草稿


目次

1. pbuilder の紹介
1. pbuilder の目的
2. pbuilder を利用する
1. base chroot イメージの tar 玉の作成
2. base.tgz の更新
3. base.tgz を利用してパッケージをビルドする
4. Debian Developer のタイピングを省略する、pdebuild
5. 設定ファイル
6. chroot 内部で root 以外でパッケージをビルドする
7. pbuilder をバックポートに活用する
8. パッケージを大量にビルドする
9. 自動バックポートスクリプト
10. pbuilder を自動テストに利用する
11. pbuilder でその他のコンパイラでのビルドを試験する
3. user-mode-linux を pbuilder で利用する
1. user-mode-linux の設定
2. rootstrap の設定
3. pbuilder-uml の設定
4. pbuilder-user-mode-linuxを実行する場合の検討項目
5. Parallel running of pbuilder-user-mode-linux
6. Using pbuilder-user-mode-linux as a wrapper script to start up a virtual machine
4. FAQ (よくある質問)
1. pbuilder create が失敗する
2. Directories that cannot be bind-mounted
3. Logging in to pbuilder to investigate build failure
4. Logging in to pbuilder to modify the environment
5. BUILDRESULTUID を sudo のセッションに追加する
6. $TMPDIRの使い方について
7. Creating a shortcut for running pbuilder with a specific distribution
8. Using environmental variables for running pbuilder for specific distribution
9. Using special apt sources lists, and local packages
10. How to get pbuilder to run apt-get update before trying to satisfy build-dependency
11. pbuilder login で bash のプロンプトを変更する
12. Creating a chroot reminder
13. Using /var/cache/apt/archives for the package cache
14. pbuilder back ported to stable Debian releases
15. Warning about LOGNAME not being defined
16. Cannot Build-conflict against an essential package
17. Avoiding the "ln: Invalid cross-device link" message
18. Using fakechroot
19. Using debconf inside pbuilder sessions
20. nodev mount options hinder pbuilder activity
21. pbuilder が遅い
22. Using pdebuild to sponsor package
23. Why is there a source.changes file in ../?
24. amd64 and i386-mode
25. How to use ccache
26. Using tmpfs for buildplace
27. svn-buildpackage を pbuilder で利用する
5. Troubleshooting and development
1. Reporting bugs
2. Mailing list
3. IRC Channel
4. Information for pbuilder developers
6. Other uses of pbuilder
1. Using pbuilder for small experiments
2. Running little programs inside the chroot
7. Experimental or wish-list features of pbuilder
1. Using LVM
2. Using cowdancer
2.1. Using cowdancer for sarge
3. tar.gz を利用しないで pbuilder を利用する
4. pbuilder を vserver で利用する
8. 参考文献
1. chroot 外部のディレクトリ構造
2. chroot 内部のディレクトリ構造
9. 些細な過去の経緯の詳細
1. マニュアルの履歴
2. Possibly inaccurate Background History of pbuilder
2.1. The Time Before pbuilder
2.2. pbuilder の誕生
2.3. And the second year of its life
2.4. pbuilder の5年目

表目次

5.1. Directory structure of the testsuite
8.1. chroot 内部のディレクトリ構造
8.2. chroot 内部のディレクトリ構造

第1章 pbuilder の紹介

1. pbuilder の目的

pbuilder は Personal Builder の略です。個人的なワークステーションなどの開発環境で、Debianパッケージをビルドするためのシステムです。pbuilder はパッケージが Debian のインストール環境のほとんどでビルドできることを確認するため、Debianパッケージをクリーンルーム内部で自動にビルドするシステムとして簡単に利用できるようになることを目指しています。クリーンルーム環境は最小限のパッケージを chroot にインストールすることで実現しています。

Debian ディストリビューションはソースコードつきのフリーソフトウェアにより構成されています。Debianの「main」セクションにあるソフトウェアは、Build-depend (ビルド時依存関係)として指定されたDebianの「main」セクションにあるパッケージのみがインストールされている状態でビルドできなければなりません。

主なる pbuilder の目的は、他の自動ビルドシステムとは違います。それは、パッケージをできるだけビルドできるようなことを目的としていないところです。パッケージが何を必要としているのかを想像しようとはしません。また選択が可能であれば、最悪な選択をする場合もあります。

この方針を採用することで、 pbuilder は、 pbuilder で試験したパッケージはほとんどのDebianがインストールされた環境でビルドできるように確認することができます。これによってDebian全体としてのソースコードのビルドしやすさの向上を目指しています。

Debian をソースからビルドできるようにするという目標はほぼ完了し、よく進捗しています。Debian 3.0の時代ではソースからビルドするのに問題が多数ありましたが、最近のリリースではましになってきています。

第2章 pbuilder を利用する

操作には、いくつかの簡単なコマンドがあります。pbuilder createpbuilder update、そして pbuilder build コマンドがよく使われます。ひとつづつ見ていきましょう。

1. base chroot イメージの tar 玉の作成

pbuilder create はベース chroot イメージの tar 玉を作成します。その他のコマンドはこのコマンドで作成されたベース chroot イメージにたいしての操作になります。chrootで利用するDebianリリースをsid(デフォルト)以外にするのであればディストリビューションのコード名は --distributionコマンドラインオプションで指定する必要があります。

debootstrap [1] はDebianの最小インストールを作成するために利用されます。その上に apt-get コマンドを利用して Build-Essential パッケージが chroot 内部にインストールされます。

さらに詳しいドキュメントは、pbuilder.8 マニュアルページを参照してください。利用するミラーサイトの設定をするために /etc/pbuilderrc でいくつか設定が必要になります[2] 、またプロキシの設定もHTTP経由でのアクセスのため、変更の必要があるでしょう。詳細は pbuilderrc.5 マニュアルページを参照してください。

2. base.tgz の更新

pbuilder update コマンドが base.tgz を更新します。 chroot を展開し、 apt-get updateapt-get dist-upgrade を chroot 内部で実行し、base.tgz (ベースの tar 玉) を作成します。

この時点で、base.tgz が対象とするディストリビューションを指定することが可能です。--distribution sid --override-config を指定すると、ディストリビューションを sid に変更できます。 [3]

コマンドラインオプションの詳細なドキュメントについては、pbuilder.8 マニュアルを参照

3. base.tgz を利用してパッケージをビルドする

chroot 内部でパッケージをビルドするには、 pbuilder build なんたら.dsc. pbuilder は base.tgz を一時作業用のディレクトリに展開し、そこに chroot 内部でビルド時の依存関係(Build-Depends) を満たし、パッケージをビルドします。ビルドされてできたパッケージは次のコマンドで指定したディレクトリに移動されます: --buildresultコマンドラインオプションで指定する必要があります。

--basetgz オプションでどの base.tgz を利用するべきかを指定することができます。

pbuilder は base.tgz から新しい chroot イメージを展開します。(base.tgz は pbuilder create で作成され、 pbuilder update で更新されます)。 chroot には Build-Depend関係のパッケージが debian/control を解析して apt-get を実行することで追加されます。

コマンドラインオプションの詳細なドキュメントについては、pbuilder.8 マニュアルを参照

4. Debian Developer のタイピングを省略する、pdebuild

pdebuild は、あらゆる操作の中でももっとも頻繁に行われるだろう作業を簡略化するためのラッパースクリプトです。Debian Developerは Debian パッケージのソースディレクトリで debuild コマンドをうつことでパッケージをビルドします。 pdebuild は同様の操作をすることで、パッケージを chroot 内部でビルドし、 現在のツリーが chroot 内部でもビルドすることを確認します。

pdebuild はまず dpkg-source コマンドを起動し、ソースパッケージを作成し、pbuilder をそのソースパッケージに対して実行します。 debuild とは違い、生成されたdeb ファイルは --buildresult で指定されたディレクトリに生成されます。

詳細は pdebuild.1 マニュアルページを参照してください。

pdebuild 0.97 から一つ違う実行モードが追加されています。 pdebuilddebian/rules clean chroot 外部で実行するのですが、chroot内部で実行するように --use-pdebuild-internal を指定することができます。 chroot 内部に作業中のディレクトリをバインドマウントし、 dpkg-buildpackage を内部で実行します。 以下の特徴があり、まだデフォルトにはなっていません。

  • ソースパッケージを作成する際に、Build-Depend を chroot 内部で満たします。 (以前の pdebuild でできなかったよい点です)。

  • 作業ディレクトリに chroot 内部から変更を加えられます。

  • pdebuild でビルドできることは pbuilder で必ず動くということが保証されるわけではないです。

  • ソースパッケージを作るステップ自体が失敗した場合に、その chroot を利用するセッションは無駄に終わります(chroot の作成には時間がかかる、cowdancer 等で改善します。)

  • 以前と同じ方法で動作してくれない。たとえば、--buildresult がきかない。

  • chroot 内部でのビルドは chroot 外部での現在のユーザで実行される。

5. 設定ファイル

設定をすべてコマンドラインで指定することも可能です。しかし、入力を簡便にするために、設定ファイルを利用することもできます。

/etc/pbuilderrc${HOME}/.pbuilderrcpbuilder を実行すると読み込まれます。可能なオプションについては、 pbuilderrc.5 に解説されています。

別のディストリビューション向けに複数の設定ファイルを活用するためには --configfile オプションが便利です

${HOME}/.pbuilderrc がシステムの設定より優先されることに注意してください。たとえば、 sarge から etch にアップグレードする場合に、自分の設定の一部を /usr/share/pbuilder/pbuilderrc にあわせて変更する必要がある可能性があります。例えば新しいバージョンの cdebootstrap に対応するために "unset DEBOOTSTRAPOPTS" を入れる、などの例が考えられます。同じことが、/etc/pbuilderrc にシステムの設定を入れている場合には当てはまります。

6. chroot 内部で root 以外でパッケージをビルドする

pbuilder は依存関係を充足させる際には root 権限を必要とします、しかしほとんどのパッケージはビルド時に root 権限を必要とはせず、rootではビルドできないパッケージも一部存在します。pbuilder pbuilder 内部専用のユーザを作成し、そのユーザIDを利用してビルドを実行することができます。root権限が必要な時にはfakeroot コマンドを利用します。

BUILDUSERID 設定オプションは既存のユーザIDと異なるIDに設定しておきましょう。そうするとパッケージが pbuilder 内部でビルドしている際に、chroot 外部の環境に影響をあたえにくくなります。BUILDUSERNAME が設定されている場合、その名前を pbuilder は利用し、 chroot 内部でroot権限で動作する代わりに、fakeroot を利用してパッケージをビルドします。

fakeroot の方法を利用している場合でも、pbuilder は root 権限が必要な場面では root 権限で稼働します。例えば、chroot内部にパッケージをインストールする時にはpbuilder は root 権限で稼働します。

pbuilder を root 権限を必要としないで利用する方法については、 user-mode-linux の利用が必要です。 第3章 で説明しています。

7. pbuilder をバックポートに活用する

pbuilder は古いディストリビューションのchroot を作成し、そこでパッケージをビルドすることで、Debian の最新版のディストリビューションからソフトウエアをバックポートするのに利用することが可能です。いくつかの点を検討する必要があり、次の理由により全自動でバックポートすることは現実的では無く、手動での作業も必要になるでしょう:

  • unstableのパッケージが unstable にしかないパッケージや、unstable にしかないバージョンのパッケージに依存している場合がある。つまり、stable では Build-Depends: を充足することができない(さらなるバックポートが必要になる)。

  • stable ディストリビューションには unstable で修正しているバグが含まれており、ワークアラウンドが必要になる。

  • unstable のパッケージが unstable 上であってもビルドしない場合がある。

8. パッケージを大量にビルドする

pbuilder は操作がインタラクティブではないため、自動的に動かすことができる。pbuilder を複数のパッケージに関して、インタラクティブじゃないように実行することができます。それをするためのスクリプトはいくつか存在します。上川は2001年からそのようなスクリプトを実行し、 pbuilder でビルドできない場合についてバグ報告をしていました。次のような問題が発見されました:

  • 依存関係を充足させるためのインストールは非インタラクティブに行われる必要がありますが、一部のパッケージはインタラクティブな操作がないとインストールできないくらいに壊れているものがあります(postgresqlなど).

  • ライブラリパッケージに問題があったり、gcc/gcj/g++ に問題がある場合、また bison もそうですが、多くのビルド失敗が報告されます。 (gcj-3.0 に "javac" がなくなったり、bison がより厳密になったり、など)

  • 一部の人はビルド失敗の報告に敵対的なので注意しましょう。

2002年ころのpbuilder の実行により初期のバグは洗いだされました。しかし、このように移行に関連したDebian全体に影響するような問題はときどき発生します。回帰テストには価値があるのです。

A script that was used by Junichi Uekawa in the initial run is now included in the pbuilder distribution, as pbuildd.sh. It is available in /usr/share/doc/pbuilder/examples/pbuildd/ and its configuration is in /etc/pbuilder/pbuildd-config.sh. It should be easy enough to set up for people who are used to pbuilder. It has been running for quite a while, and it should be possible to set the application up on your system also. This version of the code is not the most tested, but should function as a starter.

pbuildd の設定について気にしておくところがいくつかあります。

  • ビルドしないパッケージの一覧ファイル ./avoidlist が存在する必要があります。

  • 自分のアーキテクチャ向けでないものを含めて、あらゆるものをビルドしようとします。

  • 任意のビルドスクリプトを実行しているため、 root 権限で実行しないために、 pbuilder のfakeroot オプションを利用するのがよいでしょう。

  • Because not all builds are guaranteed to finish in a finite time, setting a timeout is probably necessary, or pbuildd may stall with a bad build.

  • Some packages require a lot of disk space, around 2GB seems to be sufficient for the largest packages for the time being. If you find otherwise, please inform the maintainer of this documentation.

9. 自動バックポートスクリプト

一部の人は pbuilder を一部のパッケージを自動的に stable ディストリビューションにバックポートするために利用しています。

I would like some information on how people are doing it, I would appreciate any feedback or information on how you are doing, or any examples.

10. pbuilder を自動テストに利用する

pbuilder は、自動的なテストのために利用することができます。フックを配置することができ、そのフックは chroot 内部にパッケージをインストールしたり実行したりその他のいろいろなことを実行することができます。実行可能なテストとアイデアは次です:

  • 自動的にインストール・アップグレード・削除・インストール・パージ・アップグレード・パージするようなテスト(例として、B91dpkg-iが配布されています)、もしくは全部インストールできることを確認する(execute_installtest.sh)。

  • Automatically running lintian (distributed as an example in /usr/share/doc/pbuilder/examples/B90lintian).

  • Automatic debian-test of the package? The debian-test package has been removed from Debian. A pbuilder implementation can be found as debian/pbuilder-test directory, implemented through B92test-pkg script.

To use B92test-pkg script, first, add it to your hook directory. [4]. The test files are shell scripts placed in debian/pbuilder-test/NN_name (where NN is number) following run-parts standard[5] for file names. After a successful build, packages are first tested for installation and removal, and then each test is ran inside the chroot. The current directory is the top directory of the source-code. This means you can expect to be able to use ./debian/ directory from inside your scripts.

pbuilder-test を利用するスクリプト例は /usr/share/doc/pbuilder/examples/pbuilder-test以下に配布されている。

11. pbuilder でその他のコンパイラでのビルドを試験する

Most packages are compiled with gcc or g++ and using the default compiler version, which was gcc 2.95 for Debian GNU/Linux 3.0 (i386). However, Debian 3.0 was distributed with other compilers, under package names such as gcc-3.2 for gcc compiler version 3.2. It was therefore possible to try compiling packages against different compiler versions. pentium-builder provides an infrastructure for using a different compiler for building packages than the default gcc, by providing a wrapper script called gcc which calls the real gcc. To use pentium-builder in pbuilder, it is possible to set up the following in the configuration:

EXTRAPACKAGES="pentium-builder gcc-3.2 g++-3.2"
export DEBIAN_BUILDARCH=athlon
export DEBIAN_BUILDGCCVER=3.2
	

It will instruct pbuilder to install the pentium-builder package and also the GCC 3.2 compiler packages inside the chroot, and set the environment variables required for pentium-builder to function.



[1] debootstrap か cdebootstrap か選択することができます

[2] 公開ミラーに多数のアクセス負荷をかけないため、ミラーはローカルミラーであることが望ましいです。apt-proxy などのツールの活用を推奨します。

[3] アップグレードしかサポートされていません。Debianはダウングレードをサポートしていません(現時点では?)。

[4] It is possible to specify --hookdir /usr/share/doc/pbuilder/examples command-line option to include all example hooks as well.

[5] run-parts(8) を参照してください。例えば、ファイル名に '.' はふくめられません。

第3章 user-mode-linux を pbuilder で利用する

It is possible to use user-mode-linux by invoking pbuilder-user-mode-linux instead of pbuilder. pbuilder-user-mode-linux doesn't require root privileges, and it uses the copy-on-write (COW) disk access method of User-mode-linux which typically makes it much faster than the traditional pbuilder.

User-mode-linux is a somewhat less proven platform than the standard Unix tools which pbuilder relies on (chroot, tar, and gzip) but mature enough to support pbuilder-user-mode-linux since its version 0.59. And since then, pbuilder-user-mode-linux has seen a rapid evolution.

The configuration of pbuilder-user-mode-linux goes in three steps:

  • user-mode-linux の設定

  • rootstrap の設定

  • pbuilder-uml の設定

1. user-mode-linux の設定

user-mode-linux isn't completely trivial to set up. It would probably be useful to acquaint yourself with it a bit before attempting to use rootstrap or pbuilder-user-mode-linux. For details, read /usr/share/doc/uml-utilities/README.Debian and the user-mode-linux documentation. (It's in a separate package, user-mode-linux-doc.)

user-mode-linux requires the user to be in the uml-net group in order to configure the network unless you are using slirp.

If you compile your own kernel, you may want to verify that you enable TUN/TAP support, and you might want to consider the SKAS patch.

2. rootstrap の設定

rootstrap is a wrapper around debootstrap. It creates a Debian disk image for use with UML. To configure rootstrap, there are several requirements.

  • rootstrap パッケージをインストールします。

  • TUN/TAPを利用している場合:ユーザを uml-net グループに追加し、ネットワークが利用できるようにします

    adduser dancer uml-net
    	    
  • TUN/TAPを利用している場合: カーネルが TUN/TAP インタフェースをサポートしていることを確認してください。必要であればカーネルをリビルドしてください。

  • Set up /etc/rootstrap/rootstrap.conf. For example, if the current host is 192.168.1.2, changing following entries to something like this seems to work.

    transport=tuntap
    interface=eth0
    gateway=192.168.1.1
    mirror=http://192.168.1.2:8081/debian
    host=192.168.1.198
    uml=192.168.1.199
    netmask=255.255.255.0
    	    

    Some experimentation with configuration and running rootstrap ~/test.uml to actually test it would be handy.

    Using slirp requires less configuration. The default configuration comes with a working example.

3. pbuilder-uml の設定

以下の設定が必要です:

  • pbuilder-uml をインストールする

  • Set up the configuration file /etc/pbuilder/pbuilder-uml.conf in the following manner. It will be different for slirp.

    MY_ETH0=tuntap,,,192.168.1.198
    UML_IP=192.168.1.199
    UML_NETMASK=255.255.255.0
    UML_NETWORK=192.168.1.0
    UML_BROADCAST=255.255.255.255
    UML_GATEWAY=192.168.1.1
    PBUILDER_UML_IMAGE="/home/dancer/uml-image"
    	      

    Also, it needs to match the rootstrap configuration.

  • Make sure BUILDPLACE is writable by the user. Change BUILDPLACE in the configuration file to a place where the user has access.

  • Run pbuilder-user-mode-linux create --distribution sid to create the image.

  • Try running pbuilder-user-mode-linux build.

4. pbuilder-user-mode-linuxを実行する場合の検討項目

pbuilder-user-mode-linux emulates most of pbuilder, but there are some differences.

  • pbuilder-user-mode-linux does not support all options of pbuilder properly yet. This is a problem, and will be addressed as specific areas are discovered.

  • /tmp is handled differently inside pbuilder-user-mode-linux. In pbuilder-user-mode-linux, /tmp is mounted as tmpfs inside UML, so accessing files under /tmp from outside user-mode-linux does not work. It affects options like --configfile, and when trying to build packages placed under /tmp.

5. Parallel running of pbuilder-user-mode-linux

To run pbuilder-user-mode-linux in parallel on a system, there are a few things to bear in mind.

  • The create and update methods must not be run when a build is in progress, or the COW file will be invalidated.

  • If you are not using slirp, user-mode-linux processes which are running in parallel need to have different IP addresses. Just trying to run the pbuilder-user-mode-linux several times will result in failure to access the network. But something like the following will work:

    for IP in 102 103 104 105; do
      xterm -e pbuilder-user-mode-linux build --uml-ip 192.168.0.$IP \
        20030107/whizzytex_1.1.1-1.dsc &
    done
    	    

    When using slirp, this problem does not exist.

6. Using pbuilder-user-mode-linux as a wrapper script to start up a virtual machine

It is possible to use pbuilder-user-mode-linux for other uses than just building Debian packages. pbuilder-user-mode-linux login will let a user use a shell inside the user-mode-linux pbuilder base image, and pbuilder-user-mode-linux execute will allow the user to execute a script inside the image.

You can use the script to install ssh and add a new user, so that it is possible to access inside the user-mode-linux through ssh.

Note that it is not possible to use a script from /tmp due to the way pbuilder-user-mode-linux mounts a tmpfs at /tmp.

The following example script may be useful in starting a sshd inside user-mode-linux.

#!/bin/bash

apt-get install -y ssh xbase-clients xterm
echo "enter root password"
passwd
cp /etc/ssh/sshd_config{,-}
sed 's/X11Forwarding.*/X11Forwarding yes/' /etc/ssh/sshd_config- > /etc/ssh/sshd_config

/etc/init.d/ssh restart
ifconfig
echo "Hit enter to finish"
read
      

第4章 FAQ (よくある質問)

Here, known problems and frequently asked questions are documented. This portion was initially available in README.Debian file, but moved here.

1. pbuilder create が失敗する

It often happens that pbuilder cannot create the latest chroot. Try upgrading pbuilder and debootstrap. It is currently only possible to create software that handles the past. Future prediction is a feature which may be added later after we have become comfortable with the past.

There are people who occasionally back port debootstrap to stable versions; hunt for them.

When there are errors with the debootstrap phase, the debootstrap script needs to be fixed. pbuilder does not provide a way to work around debootstrap.

2. Directories that cannot be bind-mounted

Because of the way pbuilder works, there are several directories which cannot be bind-mounted when running pbuilder. The directories include /tmp, /var/cache/pbuilder, and system directories such as /etc and /usr. The recommendation is to use directories under the user's home directory for bind-mounts.

3. Logging in to pbuilder to investigate build failure

It is possible to invoke a shell session after a build failure. Example hook script are provided as C10shell and C11screen scripts. C10shell script will start bash inside chroot, and C11screen script will start GNU screen inside the chroot.

4. Logging in to pbuilder to modify the environment

It is sometimes necessary to modify the chroot environment. login will remove the contents of the chroot after logout. It is possible to invoke a shell using hook scripts. pbuilder update executes 'E' scripts, and a sample for invoking a shell is provided as C10shell.

$ mkdir ~/loginhooks
$ cp C10shell ~/loginhooks/E10shell
$ sudo pbuilder update --hookdir ~/loginhooks/E10shell
      

It is also possible to add --save-after-exec もしくは --save-after-login オプションを pbuilder login セッションに追加することで達成することができます。 --uml-login-nocow オプションを pbuilder-user-mode-linux login セッションに追加することも可能です。

5. BUILDRESULTUID を sudo のセッションに追加する

pbuilderrc で

BUILDRESULTUID=$SUDO_UID

と設定することで sudo の際に BUILDRESULTUID を適切に設定することが可能です。

6. $TMPDIRの使い方について

If you are setting $TMPDIR to an unusual value, of other than /tmp, you will find that some errors may occur inside the chroot, such as dpkg-source failing.

There are two options, you may install a hook to create that directory, or set

export TMPDIR=/tmp

in pbuilderrc. Take your pick.

An example script is provided as examples/D10tmp with pbuilder.

7. Creating a shortcut for running pbuilder with a specific distribution

When working with multiple chroots, it would be nice to work with scripts that reduce the amount of typing. An example script pbuilder-distribution.sh is provided as an example. Invoking the script as pbuilder-etch will invoke pbuilder with a etch chroot.

8. Using environmental variables for running pbuilder for specific distribution

This section[6] describes briefly a way to setup and use multiple pbuilder setups by creating a pbuilderrc configuration in your home path ($HOME/.pbuilderrc) and using the variable "DIST" when running pbuilder or pdebuild.

First, setup $HOME/.pbuilderrc to look like:

if [ -n "${DIST}" ]; then
        BASETGZ="`dirname $BASETGZ`/$DIST-base.tgz"
        DISTRIBUTION="$DIST"
        BUILDRESULT="/var/cache/pbuilder/$DIST/result/"
        APTCACHE="/var/cache/pbuilder/$DIST/aptcache/"
fi

Then, whenever you wish to use pbuilder for a particular distro, assign a value to "DIST" that is one of the distros available for Debian or any Debian based distro you happen to be running (i.e. whatever is found under /usr/lib/debootstrap/scripts).

Here's some examples on running pbuilder or pdebuild:

DIST=gutsy sudo pbuilder create

DIST=sid sudo pbuilder create --mirror http://http.us.debian.org/debian

DIST=gutsy sudo pbuilder create \
        --othermirror "deb http://archive.ubuntu.com/ubuntu gutsy universe \
        multiverse"

DIST=gutsy sudo pbuilder update

DIST=sid sudo pbuilder update --override-config --mirror \
http://http.us.debian.org/debian \
--othermirror "deb http://http.us.debian.org/debian sid contrib non-free"

DIST=gutsy pdebuild

9. Using special apt sources lists, and local packages

If you have some very specialised requirements on your apt setup inside pbuilder, it is possible to specify that through the --othermirror option. Try something like: --othermirror "deb http://local/mirror stable main|deb-src http://local/source/repository ./"

To use the local file system instead of HTTP, it is necessary to do bind-mounting. --bindmounts is a command-line option useful for such cases.

It might be convenient to use your built packages from inside the chroot. It is possible to automate the task with the following configuration. First, set up pbuilderrc to bindmount your build results directory.

BINDMOUNTS="/var/cache/pbuilder/result"
	

Then, add the following hook

# cat /var/cache/pbuilder/hooks/D70results
#!/bin/sh
cd /var/cache/pbuilder/result/
/usr/bin/dpkg-scanpackages . /dev/null > /var/cache/pbuilder/result/Packages
/usr/bin/apt-get update
	

This way, you can use deb file:/var/cache/pbuilder/result

10. How to get pbuilder to run apt-get update before trying to satisfy build-dependency

You can use hook scripts for this. D scripts are run before satisfying build-dependency.

This snippet comes from Ondrej Sury.

11. pbuilder login で bash のプロンプトを変更する

To make distinguishing bash prompts inside pbuilder easier, it is possible to set environment variables such as PS1 inside pbuilderrc

With versions of bash more recent than 2.05b-2-15, the value of the debian_chroot variable, if set, is included in the value of PS1 (the Bash prompt) inside the chroot. In prior versions of bash,[7] setting PS1 in pbuilderrc worked.

example of debian_chroot

	export debian_chroot="pbuild$$"
      

example of PS1

	export PS1="pbuild chroot 32165 # "
      

12. Creating a chroot reminder

Bash prompts will help you remember that you are inside a chroot. There are other cases where you may want other signs of being inside a chroot. Check out the examples/F90chrootmemo hook script. It will create a file called /CHROOT inside your chroot.

13. Using /var/cache/apt/archives for the package cache

For the help of low-bandwidth systems, it is possible to use /var/cache/apt/archives as the package cache. Just specify it instead of the default /var/cache/pbuilder/aptcache.

It is however not possible to do so currently with the user-mode-linux version of pbuilder, because /var/cache/apt/archives is usually only writable by root.

Use of dedicated tools such as apt-proxy is recommended, since caching of packages would benefit the system outside the scope of pbuilder.

14. pbuilder back ported to stable Debian releases

Currently stable back port of pbuilder is avialable at backports.org.

15. Warning about LOGNAME not being defined

You might see a lot of warning messages when running pbuilder.

	dpkg-genchanges: warning: no utmp entry available and LOGNAME not defined; using uid of process (1234)
	

It is currently safe to ignore this warning message. Please report back if you find any problem with having LOGNAME unset. Setting LOGNAME caused a few problems when invoking chroot. For example, dpkg requires getpwnam to succeed inside chroot, which means LOGNAME and the related user information have to be set up inside chroot.

16. Cannot Build-conflict against an essential package

pbuilder does not currently allow Build-Conflicts against essential packages. It should be obvious that essential packages should not be removed from a working Debian system, and a source package should not try to force removal of such packages on people building the package.

17. Avoiding the "ln: Invalid cross-device link" message

By default, pbuilder uses hard links to manage the pbuilder package cache. It is not possible to make hard links across different devices; and thus this error will occur, depending on your set up. If this happens, set

APTCACHEHARDLINK=no

in your pbuilderrc file.

18. Using fakechroot

It is possible to use fakechroot instead of being root to run pbuilder; however, several things make this impractical. fakechroot overrides library loads and tries to override default libc functions when providing the functionality of virtual chroot. However, some binaries do no use libc to function, or override the overriding provided by fakechroot. One example is ldd. Inside fakechroot, ldd will check the library dependency outside of the chroot, which is not the expected behaviour.

To work around the problem, debootstrap has a --variant fakechroot option. Use that, so that ldd and ldconfig are overridden.

Make sure you have set your LD_PRELOAD path correctly, as described in the fakechroot manpage.

19. Using debconf inside pbuilder sessions

To use debconf inside pbuilder, setting DEBIAN_FRONTEND to 「readline」 in pbuilderrc should work. Setting it to 「dialog」 should also work, but make sure whiptail or dialog is installed inside the chroot.

20. nodev mount options hinder pbuilder activity

If you see messages such as this when building a chroot, you are mounting the file system with the nodev option.

	/var/lib/dpkg/info/base-files.postinst: /dev/null: Permission denied
      

You will also have problems if you mount the file system with the noexec option, or nosuid. Make sure you do not have these flags set when mounting the file system for /var/cache/pbuilder or $BUILDPLACE.

This is not a problem when using user-mode-linux.

See 316135 for example.

21. pbuilder が遅い

pbuilder is often slow. The slowest part of pbuilder is extracting the tar.gz every time pbuilder is invoked. That can be avoided by using pbuilder-user-mode-linux. pbuilder-user-mode-linux uses COW file system, and thus does not need to clean up and recreate the root file system.

pbuilder-user-mode-linux is slower in executing the actual build system, due to the usual user-mode-linux overhead for system calls. It is more friendly to the hard drive.

pbuilder with cowdancer is also an alternative that improves speed of pbuilder startup.

22. Using pdebuild to sponsor package

To sign a package marking for sponsorship, it is possible to use --auto-debsign and --debsign-k options of pdebuild.

	pdebuild  --auto-debsign  --debsign-k XXXXXXXX
      

23. Why is there a source.changes file in ../?

When running pdebuild, pbuilder will run dpkg-buildpackage to create a Debian source package to pass it on to pbuilder. File named XXXX_YYY_source.changes is what remains from that process. It is harmless unless you try to upload it to the Debian archive.

This behaviour is different when running through --use-pdebuild-internal

24. amd64 and i386-mode

amd64 architectures are capable of running binaries in i386 mode. It is possible to use pbuilder to run packages, using linux32 and debootstrap --arch option. Specifically, a command-line option like the following will work.

pbuilder create --distribution sid --debootstrapopts --arch --debootstrapopts i386 \
  --basetgz /var/cache/pbuilder/base-i386.tgz --mirror http://ftp.jp.debian.org/debian
linux32 pbuilder build --basetgz /var/cache/pbuilder/base-i386.tgz
	

25. How to use ccache

To use ccache with pbuilder, use the following for configuration. Note that the directory used for CCACHE_DIR needs to exist, and be writable by user within chroot. The default user within chroot is

uid=1234

.

Example is provided as pbuilderrc.ccache.

export CCACHE_DIR="/var/cache/pbuilder/ccache"
export PATH="/usr/lib/ccache:${PATH}"

EXTRAPACKAGES=ccache
BINDMOUNTS="${CCACHE_DIR}"
      

This entry created thanks to a blog posting.

26. Using tmpfs for buildplace

To improve speed of operation, it is possible to use tmpfs for pbuilder build location. Mount tmpfs to /var/cache/pbuilder/build, and set

APTCACHEHARDLINK=no

.

27. svn-buildpackage を pbuilder で利用する

pdebuild command can be used with svn-buildpackage --svn-builder command-line option. [8]

alias svn-cowbuilder="svn-buildpackage --svn-builder='pdebuild --pbuilder cowbuilder"
      


[6] This part of the documentation contributed by Andres Mejia

This example was taken from a wiki (https://wiki.ubuntu.com/PbuilderHowto).

[7] Debian 3.0 以前のbash

第5章 Troubleshooting and development

1. Reporting bugs

To report bugs, it would be important to have a log of what's going wrong. Most of the time, adding a --debug option and re-running the session should do the trick. Please send the log of such session along with your problem to ease the debugging process.

2. Mailing list

There is a mailing list for pbuilder on alioth (pbuilder-maint@lists.alioth.debian.org). You can subscribe through the alioth web interface. http://alioth.debian.org/mail/?group_id=30778.

3. IRC Channel

For coordination and communication, IRC channel #pbuilder on irc.oftc.net is used. Please log your intent there when you are going to start doing some changes and committing some change.

4. Information for pbuilder developers

This section tries to document current development practices and how things generally operate in development.

pbuilder is co-maintained with resources provided by Alioth. There is an Alioth project page at http://alioth.debian.org/projects/pbuilder. Home page is also available, at http://alioth.debian.org/projects/pbuilder which shows this text. git repository is available through http, git, or (if you have an account on alioth, ) ssh.

git-clone git://git.debian.org/git/pbuilder/pbuilder.git
git-clone http://git.debian.org/git/pbuilder/pbuilder.git
git-clone ssh://git.debian.org/git/pbuilder/pbuilder.git
      

Test-suites are available in ./testsuite/ directory. Changes are expected not to break the test-suites. ./run-test.sh is a basic test-suite, which puts a summary in run-test.log, and run-test-cdebootstrap.log. ./run-test-regression.sh is a regression test-suite, which puts the result in run-test-regression.log. Currently, run-test.sh is ran automatically daily to ensure that pbuilder is working.

表 5.1. Directory structure of the testsuite

DirectoryMeaning
./testsuite/Directory for testsuite
./testsuite/run-test.shDaily regression test to test against Debian Archive changes breaking pbuilder.
./testsuite/run-test.logA summary of testsuite
./testsuite/normal/Directory for testsuite results of running pbuilder with debootstrap
./testsuite/cdebootstrap/Directory for testsuite results of running pbuilder with cdebootstrap
./testsuite/run-regression.shRegression testsuite, ran every time change is made to pbuilder to make sure there is no regression.
./testsuite/run-regression.logSummary of test result
./testsuite/regression/BugID-*.shRegression tests, exit 0 for success, exit 1 for failure
./testsuite/regression/BugID-*Files used for the regression testsuite.
./testsuite/regression/log/BugID-*.sh.logOutput of the regression test, output from the script is redirected by run-regression.sh

When making changes, changes should be documented in the Git commit log. git-dch will generate debian/changelog from the commit log. Make the first line of your commit log meaningful, and add any bug-closing information available.

A TODO file is available in debian/TODO. It's mostly not well-maintained, but hopefully it will be more up-to-date when people start using it. emacs todoo-mode is used in editing the file.

When releasing a new version of pbuilder, the version is tagged with the git tag X.XXX (version number). This is done with ./git-tag.sh script available in the source tree.

第6章 Other uses of pbuilder

1. Using pbuilder for small experiments

There are cases when some small experimenting is required, and you do not want to damage the main system, like when installing experimental library packages, or compiling with experimental compilers. For such cases, the pbuilder login command is available.

pbuilder login is a debugging feature for pbuilder itself, but it also allows users to have a temporary chroot.

Note that the chroot is cleaned after logging out of the shell, and mounting file systems inside it is considered harmful.

2. Running little programs inside the chroot

To facilitate using pbuilder for other uses, pbuilder execute is available. pbuilder execute will take a script specified in the command-line argument, and invoke the script inside the chroot.

The script can be useful for sequences of operations such as installing ssh and adding a new user inside the chroot.

第7章 Experimental or wish-list features of pbuilder

There are some advanced features, above that of the basic feature of pbuilder, for some specific purposes.

1. Using LVM

LVM2 has a useful snapshot function that features Copy-on-write images. That could be used for pbuilder just as it can be used for the user-mode-linux pbuilder port. lvmpbuilder script in the examples directory implements such port. The scripts and documentation can be found under /usr/share/doc/pbuilder/examples/lvmpbuilder/

2. Using cowdancer

cowdancer allows copy-on-write semantics on file system using hard links and hard-link-breaking-on-write tricks. pbuilder using cowdancer seems to be much faster and it is one ideal point for improvement. cowbuilder, a wrapper for pbuilder for using cowdancer is available from cowdancer package since 0.14

Example command-lines for cowbuilder look like the following.

# cowbuilder --create --distribution sid
# cowbuilder --update --distribution sid
# cowbuilder --build XXX.dsc
	

It is also possible to use cowdancer with pdebuild command. Specify with command-line option --pbuilder or set it in PDEBUILD_PBUILDER configuration option.

$ pdebuild --pbuilder cowbuilder
	

2.1. Using cowdancer for sarge

This section is mostly obsolete now that etch is released, but left for reference, and will be removed after lenny release.

cowdancer was introduced after the release of Debian sarge; if you want to build packages for sarge with cowbuilder, you will need to workaround its unavailability.

One way to workaround the problem is to set APTCONFDIR in pbuilderrc to point to a directory with a list of sources for APT which has both sarge and sarge-backports.

$ cat sources.list
# sarge-backports
deb     http://www.backports.org/debian sarge-backports main
deb-src http://www.backports.org/debian sarge-backports main

# sarge
deb     http://ftp.de.debian.org/debian sarge main
deb-src http://ftp.de.debian.org/debian sarge main
          

It is recommended to "Pin" the cowdancer package appropriately in this case, via the APT preferences mechanism.

$ cat preferences
Explanation: use cowdancer from backports
Package: cowdancer
Pin: release a=sarge-backports
Pin-Priority: 950
          

3. tar.gz を利用しないで pbuilder を利用する

--no-targz option of pbuilder will allow usage of pbuilder in a different way from conventional usage. It will try to use an existing chroot, and will not try to clean up after working on it. It is an operation mode more like sbuild.

It should be possible to create base chroot images for dchroot with the following commands:

# pbuilder create --distribution etch --no-targz --basetgz /chroot/etch
# pbuilder create --distribution lenny --no-targz --basetgz /chroot/lenny
# pbuilder create --distribution sid --no-targz --basetgz /chroot/sid
	

4. pbuilder を vserver で利用する

It is possible to use pbuilder in a vserver environment. This requires either vserver-patches in version 2.1.1-rc14 or higher, or a Linux kernel version 2.6.16 or higher.

To use pbuilder in a vserver, you need to set the secure_mount CAPS in the ccapabilities of this vserver.

第8章 参考文献

1. chroot 外部のディレクトリ構造

表 8.1. chroot 内部のディレクトリ構造

DirectoryMeaning
/etc/pbuilderrc設定ファイル
/usr/share/pbuilder/pbuilderrcデフォルト設定
/var/cache/pbuilder/base.tgzDefault location pbuilder uses for base.tgz, the tar-ball containing a basic Debian installation with only the build-essential packages.
/var/cache/pbuilder/build/PID/pbuilder がデフォルトでchroot のために利用する場所
/var/cache/pbuilder/aptcacheDefault location pbuilder will use as apt cache, to store deb packages required during pbuilder build.
/var/cache/pbuilder/resultDefault location pbuilder puts the deb files and other files created after build
/var/cache/pbuilder/pbuilder-umlresultDefault location pbuilder-user-mode-linux puts the deb files and other files created after build
/var/cache/pbuilder/pbuilder-mntDefault location pbuilder-user-mode-linux uses for mounting the COW file system, for chrooting.
/tmppbuilder-user-mode-linux will mount tmpfs for work.
${HOME}/tmp/PID.cowpbuilder-user-mode-linux use this directory for location of COW file system.
${HOME}/uml-imagepbuilder-user-mode-linux use this directory for user-mode-linux full disk image.

2. chroot 内部のディレクトリ構造

表 8.2. chroot 内部のディレクトリ構造

DirectoryMeaning
/etc/mtab /proc/mountsへのシンボリックリンク。
/tmp/builddDefault place used in pbuilder to place the Debian package to be processed. /tmp/buildd/packagename-version/ will be the root directory of the package being processed. HOME environment variable is set to this value inside chroot by pbuilder-buildpackage
/runThe script passed as an argument to pbuilder execute is passed on.
/tmp/hooks フックの場所。
/var/cache/apt/archives pbuilder は chroot 外部の aptcache ディレクトリからコピーしてきたり、chroot 外部の aptcache ディレクトリへコピーしたりします。
/tmp/XXXXpbuilder-user-mode-linux/tmp のスクリプトを利用して user-mode-linux にブートストラップします。

第9章 些細な過去の経緯の詳細

1. マニュアルの履歴

This document was started on 28 Dec 2002 by Junichi Uekawa, trying to document what is known about pbuilder.

This documentation is available from the pbuilder source tar-ball, and from the git repository of pbuilder (web-based access is possible). A copy of this documentation can be found on the Alioth project page for pbuilder. There is also a PDF version. The homepage for pbuilder is http://pbuilder.alioth.debian.org/ hosted by alioth project.

Documentation is written using DocBook XML, with emacs PSGML mode, and using wysidocbookxml for live previewing.

2. Possibly inaccurate Background History of pbuilder

The following is a most possibly inaccurate account of how pbuilder came to happen, and other attempts to make something like pbuilder happen. This part of the document was originally in the AUTHORS file, to give credit to those who existed before pbuilder.

2.1. The Time Before pbuilder

There was once dbuild, which was a shell script to build Debian packages from source. Lars Wirzenius wrote that script, and it was good, short, and simple (probably). There was nothing like build-depends then (I think), and it was simple. It could have been improved, I could only find references and no actual source.

debbuild was probably written by James Troup. I don't know it because I have never seen the actual code, I could only find some references to it on the net, and mailing list logs.

sbuild is a perl script to build Debian packages from source. It parses Build-Depends, and performs other miscellaneous checks, and has a lot of hacks to actually get things building, including a table of what package to use when virtual packages are specified (does it do that still?). It supports the use of a local database for packages which do not have build-dependencies. It was written by Ronan Hodek, and I think it was patched and fixed and extended by several people. It is part of wanna-build, and used extensively in the Debian buildd system. I think it was maintained mostly by Ryan Murray.

2.2. pbuilder の誕生

wanna-build (sbuild) was (at the time of year 2001) quite difficult to set up, and it was never a Debian package. dbuild was something that predated Build-Depends.

Building packages from source using Build-Depends information within a chroot sounded trivial; and pbuilder was born. It was initially a shell script with only a few lines, which called debootstrap and chroot and dpkg-buildpackage in the same run, but soon, it was decided that that's too slow.

Yes, and it took almost an year to get things somewhat right, and in the middle of the process, Debian 3.0 was released. Yay. Debian 3.0 wasn't completely buildable with pbuilder, but the amount of packages which are not buildable is steadily decreasing. (I hope)

2.3. And the second year of its life

Someone wanted pbuilder to not run as root, and as User-mode-linux has become more useful as time passed, I've started experimenting with pbuilder-user-mode-linux. pbuilder-user-mode-linux has not stayed functional as much as I would have liked, and bootstrapping user-mode-linux environment has been pretty hard, due to the quality of user-mode-linux code or packaging at that time, which kept on breaking network support in one way or the other.

2.4. pbuilder の5年目

pbuilder is now widely adopted as a 'almost standard' tool for testing packages, and building packages in a pristine environment. There are other similar tools that do similar tasks, but they do not share the exact same goal. To commemorate this fact, pbuilder is now co-maintained with several people.

sbuild is now a well-maintained Debian package within Debian, and with pbuilder being such a slow monster, some people prefer the approach of sbuild. Development to use LVM-snapshots, cowloop, or cowdancer is hoped to improve the situation somewhat.