2020-01-23: Creating LVM-backed schroots                     rak

I use sbuild to build my Debian under a clean environment. To
save time I prefer to store my clean chroots on LVM volumes and
use snapshotting, instead of extracting the chroots from
tarballs every time.

I rarely need to create new schroots and I can never remember
the steps. To help future me remember (and to help whoever else
needs to create an LVM-backed schroot), I've decided to write
down the steps.

# Edit these to your heart's content
export VG="tosh"         # volume group
export RELEASE="buster"  # debian release
export ARCH="amd64"      # arch for the chroot
export MIRROR="http://localhost:3142/debian/"

export MOUNT_PT=$(mktemp -d)
export LV="${RELEASE}_${ARCH}_chroot"
lvcreate -L 5G "${VG}" -n "${LV}"
mkfs.ext4 "/dev/${VG}/${LV}"
mount "/dev/${VG}/${LV}" "${MOUNT_PT}"
sbuild-createchroot --chroot-mode schroot "${RELEASE}" \
    "${MOUNT_PT}" "${MIRROR}"
umount "${MOUNT_PT}"
# sbuild-createchroot's automatically generated config
# file does not configure our schroot to use LVM's
# snapshot mechanism. Let's delete it and create our
# own instead.
rm "/etc/schroot/chroot.d/${RELEASE}-${ARCH}-sbuild-"*
cat <<EOF >/etc/schroot/chroot.d/${RELEASE}-${ARCH}-snap
description=Debian ${RELEASE} LVM snapshot
lvm-snapshot-options=--size 5G

To keep the schroot up to date, you can then run the
sbuild-update command, e.g.,

$ sudo sbuild-update -udr source:buster