Creating LVM-backed schroots
I use sbuild to build my Debian packages 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
[${RELEASE}-${ARCH}-snap]
type=lvm-snapshot
description=Debian ${RELEASE} LVM snapshot
groups=sbuild,root
root-groups=root,sbuild
device=/dev/${VG}/${LV}
lvm-snapshot-options=--size 5G
aliases=${RELEASE},${RELEASE}-${ARCH}
EOF
To keep the schroot up to date, you can then run the sbuild-update command, e.g.,
$ sudo sbuild-update -udr source:buster
Comments: To comment on this post, send me an email following the template below. Your email address will not be posted, unless you choose to include it in the link: field. If your web browser is configured to handle mailto: links, click comment to load the template into your mail client.
To: Ryan Kavanagh <rak@rak.ac> Subject: [blog-comment] /blog/2020-01-23-creating-lvm-backed-schroots/ post_id: /blog/2020-01-23-creating-lvm-backed-schroots/ author: [How should you be identified? Usually your name or "Anonymous"] link: [optional link to your website] Your comments here. Markdown syntax accepted.
0 Comments