Quick guide: set up chroot environment and build Debian packages (sbuild version)

TL;DR: Pbuilder-related tools are ineffective and redundant. By installing sbuild and schroot, one can set up clean and reusable chroot environments quickly and use the sole sbuild command to build Debian source packages (using src tree or .dsc files).
Fade away please pbuilder/cowbuilder; long live sbuild!


Quick example

Install tools and preparation

sudo apt update;
sudo apt install sbuild schroot;
sudo mkdir -p /var/lib/sbuild/chroots; # the last component is made by us
sudo chown sbuild:sbuild /var/lib/sbuild/chroots;

Initialize a chroot environment using sbuild-createchroot

# Assume host machine is of x86_64 architecture, create an unstable chroot
sudo sbuild-createchroot unstable /var/lib/sbuild/chroots/unstable-amd64 \
  --alias=sid --alias=UNRELEASED http://deb.debian.org/debian;

Keep (s)chroot environment updated

sudo sbuild-update -ud unstable;

Build a Debian package using sbuild with previously created chroot environment

# If you want to drop superuser privilege, add yourself into sbuild group first.
# Other settings might be needed. See sbuild-adduser(1).
# #################################
# Option 1: have proper Debian source package
sbuild -A -v -d unstable /path/to/package.dsc
#
# Option 2: chdir into extracted source tree with .orig tarball in parent directory
sbuild -A -v -d unstable
# Option 3: integrate with git-buildpackage (gbp)
gbp buildpackage --git-builder=sbuild -A -v -d unstable
#
# Notes:
# 1. If you need source-only changes (https://wiki.debian.org/SourceOnlyUpload),
#    append "--source" to sbuild's invocation
# 2. If you want to sign your build, append "-kxxxxxxxx"
#    to your sbuild's invocation, where xxxxxxxx is you gpg keyid

How to destroy schroot environment properly

If you do not wish to use schroot and sbuild anymore, you may use the following tool to properly destroy the schroot environment:

# Destroy the chroot instance named "unstable"
sudo sbuild-destroychroot unstable
# This script actually does nothing other than providing instructions.
# You will need to follow the printed instruction and safely
# destroy the schroot instance by yourself.

References

To be continued…


Updates

  • July 19, 2020: Replace httpredir.debian.org with CDN-enabled deb.debian.org.
  • July 19, 2020: Add text related to sbuild-destroychroot.
  • July 22, 2020: Remove “sudo” from sbuild invocation. No privilege is needed in this case.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注