Debian GNU/Linux has its sbuild and (much easier) pbuilder, but can you imagine that Debian includes software to create RPM-based chroots and build RPM packages under them?! Package called mach provides tool similar to pbuilder. It create chroots, manage them and allow user to create RPMs in separated, clear and reproducible environment. Just like packages should be build. Moreover its as easy to use as pbuilder is (if not even easier).
This package is available in current stable release of Debian (named “etch”), so installing is easy:
# aptitude install mach
According to bug #484514 installing createrepo which is its dependency have to be done by hand:
# aptitude install createrepo
Setting mach users
To give user permision to run mach add him to mach group with command:
# adduser username mach
Re-login or use sg mach command to obtain new rights.
Creating chroots with mach is really simple. Just choose your target distribution and run:
$ mach -r centos-5-i386-updates setup base
Full list of supported distributions, version and their options is available at /etc/mach/dist.d/. This includes CentOS 4 and 5; Fedora 1, 2, 3, 4, and 6 for both i386 and x86_64; RedHat 7.0, 7.1, 7.2, 7.3, 8.0 and 9; SUSE 8.1, 8.2 and 9.0 and… other. Distributions also have -os, -updates and other suffixes that enables additional repositories.
RPM locking (bug)
As I reported in #507500 documentation about setting host’s rpm is a bit misleading. If method that invole /etc/rpm/macros.mach does not work try to create /var/lib/rpm (and don’t forget to remove /etc/rpm/macros.mach).
To enter chroot run:
$ mach -r centos-5-i386-updates chroot
To leave it use exit.
Installing additional packages in chroot
Major difference between pbuilder and mach is in approach to use of package manager. While pbuilder use apt and dpkg from chroot, mach always use host’s yum and rpm. Also RPM database is kept outside the chroot. This approach make yum and rpm in chroot useless for package managing.
To install or uninstall package you need to use:
$ mach -r centos-5-i386-updates rpm -Uhv package.rpm
or yum with:
$ mach -r centos-5-i386-updates yum install package
APT-based RPM repository support is currently broken in Debian’s mach package (according to README.Debian), because Debian’s APT only support “deb” repositories.
Finally, if you make too much mess you can always clean your chroot with:
$ mach -r centos-5-i386-updates clean
Packages are cached in /var/cache/mach on host, so re-creating chroots is fast and do not involve any package downloading.
(Re)building a (source) RPM
This is probably the easiest part of the whole process. Just run:
$ mach -r centos-5-i386-updates rebuild package.src.rpm
Results will be placed in /var/tmp/mach/centos-5-i386-updates/package.
Whole process can be a bit simpler if you create a configuration file. You can set default chroot name in it and omit -r option in all commands:
Also you can set yum as default package manager (to keep it if package default will change in future):