mk-sbuild: Add support for btrfs-snapshot based chroots

This commit is contained in:
Christopher James Halse Rogers 2010-10-25 12:27:50 -04:00
parent 19399b71c9
commit 47bc5bf351
3 changed files with 39 additions and 4 deletions

5
debian/changelog vendored
View File

@ -19,7 +19,10 @@ ubuntu-dev-tools (0.105) UNRELEASED; urgency=low
* doc/syncpackage.1: * doc/syncpackage.1:
- Add a warning that the use of syncpackage is discouraged. - Add a warning that the use of syncpackage is discouraged.
-- Stefano Rivera <stefanor@ubuntu.com> Fri, 22 Oct 2010 17:23:58 +0200 [ Christopher James Halse Rogers ]
* mk-sbuild: Add support for btrfs-snapshot based chroots
-- Christopher James Halse Rogers <raof@ubuntu.com> Sun, 24 Oct 2010 12:49:40 -0400
ubuntu-dev-tools (0.104) experimental; urgency=low ubuntu-dev-tools (0.104) experimental; urgency=low

View File

@ -56,7 +56,8 @@ Specify a volume group, and subsequently use a default SCHROOT_TYPE of
.TP .TP
.B \-\-type=SHROOT_TYPE .B \-\-type=SHROOT_TYPE
Specify a SCHROOT_TYPE. Supported values are "directory" (default if Specify a SCHROOT_TYPE. Supported values are "directory" (default if
\-\-vg not specified), "lvm-snapshot" (default if \-\-vg specified), and "file". \-\-vg not specified), "lvm-snapshot" (default if \-\-vg specified),
"btrfs-snapshot", and "file".
.SH ENVIRONMENT VARIABLES .SH ENVIRONMENT VARIABLES
.TP .TP
@ -88,6 +89,11 @@ use SOURCE_CHROOTS_DIR as home of schroot source directories. (default
.B SOURCE_CHROOTS_TGZ .B SOURCE_CHROOTS_TGZ
use SOURCE_CHROOTS_TGZ as home of schroot source tarballs. (default use SOURCE_CHROOTS_TGZ as home of schroot source tarballs. (default
/var/lib/schroot/tarballs) /var/lib/schroot/tarballs)
.TP
.B CHROOT_SNAPSHOT_DIR
use CHROOT_SNAPSHOT_DIR as home of mounted btfrs snapshots (default
/var/lib/schroot/snapshots)
.SH FILES .SH FILES
.TP .TP

View File

@ -99,6 +99,7 @@ LV_SIZE="5G"
SNAPSHOT_SIZE="4G" SNAPSHOT_SIZE="4G"
SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots" SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots"
SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs" SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs"
CHROOT_SNAPSHOT_DIR="/var/lib/schroot/snapshots"
function usage() function usage()
{ {
@ -117,7 +118,7 @@ function usage()
echo " --distro=DISTRO Install specific distro:" echo " --distro=DISTRO Install specific distro:"
echo " 'ubuntu'(default), or 'debian'" echo " 'ubuntu'(default), or 'debian'"
echo " --type=SCHROOT_TYPE Define the schroot type:" echo " --type=SCHROOT_TYPE Define the schroot type:"
echo " 'directory'(default), or 'file'" echo " 'directory'(default), 'file', or 'btrfs-snapshot'"
echo " 'lvm-snapshot' is selected via --vg" echo " 'lvm-snapshot' is selected via --vg"
echo "" echo ""
echo "Configuration (via ~/.mk-sbuild.rc)" echo "Configuration (via ~/.mk-sbuild.rc)"
@ -125,6 +126,7 @@ function usage()
echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})" echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})"
echo " SOURCE_CHROOTS_DIR Directory to store directory source chroots" echo " SOURCE_CHROOTS_DIR Directory to store directory source chroots"
echo " SOURCE_CHROOTS_TGZ Directory to store file source chroots" echo " SOURCE_CHROOTS_TGZ Directory to store file source chroots"
echo " CHROOT_SNAPSHOT_DIR Directory to mount open btrfs snaphshot chroots (default ${CHROOT_SNAPSHOT_DIR})"
echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries" echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries"
echo " SKIP_UPDATES Enable --skip-updates" echo " SKIP_UPDATES Enable --skip-updates"
echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)" echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)"
@ -283,6 +285,15 @@ case "$SCHROOT_TYPE" in
# Set up some variables for use in the paths and names # Set up some variables for use in the paths and names
CHROOT_PATH="${SOURCE_CHROOTS_TGZ}/${CHROOT_NAME}.tgz" CHROOT_PATH="${SOURCE_CHROOTS_TGZ}/${CHROOT_NAME}.tgz"
;; ;;
"btrfs-snapshot")
if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then
sudo mkdir -p "${SOURCE_CHROOTS_DIR}"
fi
if [ ! -d "${CHROOT_SNAPSHOT_DIR}" ]; then
sudo mkdir -p "${CHROOT_SNAPSHOT_DIR}"
fi
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
;;
*) *)
echo 'unknown source type!?' >&2 echo 'unknown source type!?' >&2
exit 1 exit 1
@ -419,6 +430,14 @@ case "$SCHROOT_TYPE" in
fi fi
sudo mkdir -p "${MNT}" sudo mkdir -p "${MNT}"
;; ;;
"btrfs-snapshot")
MNT="${CHROOT_PATH}"
if sudo btrfs subvolume list "${MNT}" >/dev/null 2>&1; then
echo "E: Subvolume ${MNT} already exists; aborting" >&2
exit 1
fi
sudo btrfs subvolume create "${MNT}"
;;
"file") "file")
MNT=`mktemp -d -t schroot-XXXXXX` MNT=`mktemp -d -t schroot-XXXXXX`
esac esac
@ -494,6 +513,12 @@ EOM
cat >> "${TEMP_SCHROOTCONF}" <<EOM cat >> "${TEMP_SCHROOTCONF}" <<EOM
union-type=aufs union-type=aufs
${SCHROOT_TYPE}=CHROOT_PATH ${SCHROOT_TYPE}=CHROOT_PATH
EOM
;;
btrfs-snapshot)
cat >> "${TEMP_SCHROOTCONF}" <<EOM
btrfs-source-subvolume=CHROOT_PATH
btrfs-snapshot-directory=CHROOT_SNAPSHOT_DIR
EOM EOM
;; ;;
esac esac
@ -509,6 +534,7 @@ cat "$TEMP_SCHROOTCONF" | sed \
-e "s|CHROOT_PATH|$CHROOT_PATH|g" \ -e "s|CHROOT_PATH|$CHROOT_PATH|g" \
-e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \ -e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \
-e "s|SCHROOT_TYPE|$SCHROOT_TYPE|g" \ -e "s|SCHROOT_TYPE|$SCHROOT_TYPE|g" \
-e "s|CHROOT_SNAPSHOT_DIR|$CHROOT_SNAPSHOT_DIR|g" \
| \ | \
sudo bash -c "cat >> /etc/schroot/schroot.conf" sudo bash -c "cat >> /etc/schroot/schroot.conf"
rm -f "$TEMP_SCHROOTCONF" rm -f "$TEMP_SCHROOTCONF"
@ -544,7 +570,7 @@ case "$SCHROOT_TYPE" in
sudo umount "$MNT" sudo umount "$MNT"
rmdir "$MNT" rmdir "$MNT"
;; ;;
"directory") "directory"|"btrfs-snapshot")
;; ;;
"file") "file")
cd "$MNT" cd "$MNT"