From 32d0e916d35088b666707409afe5eeee9b18a59d Mon Sep 17 00:00:00 2001 From: Emmet Hikory Date: Tue, 9 Feb 2010 11:34:20 +0900 Subject: [PATCH 1/5] mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots --- debian/changelog | 3 ++- mk-sbuild | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2c8d468..1f79ad6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low [ Emmet Hikory ] * Support qemu-arm-static -> qemu-kvm-extras-static transition + * mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots [ Loïc Minier ] * Demote qemu-kvm-extras-static to a Suggests since most people don't build @@ -14,7 +15,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low * requestsync: add -C to allow manually adding changelog when missing (LP: #518574). - -- Kees Cook Mon, 08 Feb 2010 10:12:23 -0800 + -- Emmet Hikory Tue, 09 Feb 2010 11:32:02 +0900 ubuntu-dev-tools (0.92) lucid; urgency=low diff --git a/mk-sbuild b/mk-sbuild index e646540..2bd6b18 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -1,4 +1,4 @@ -#!/bin/bash +# !/bin/bash # # Copyright 2006-2009 (C) Canonical Ltd. # Author: Kees Cook @@ -36,10 +36,10 @@ if [ -w /etc/passwd ]; then exit 1 fi -# Perform once-only things to initially set up for using sbuild+schroot+lvm +# Perform once-only things to initially set up for using sbuild+schroot if [ ! -w /var/lib/sbuild ]; then # Load all the packages you'll need to do work - sudo apt-get install sbuild schroot debootstrap lvm2 + sudo apt-get install sbuild schroot debootstrap # Add self to the sbuild group sudo adduser "$USER" sbuild @@ -340,6 +340,9 @@ fi case "$SRC_TYPE" in "lvm") + # Install lvm2 if missing + dpkg -l lvm2 > /dev/null || sudo apt-get install lvm2 + # Allocate the "golden" chroot LV sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG" sudo mkfs -t ext4 "$CHROOT_PATH" From c2fa61372186fbf28f20c45571101e1705741de7 Mon Sep 17 00:00:00 2001 From: Emmet Hikory Date: Tue, 9 Feb 2010 11:40:16 +0900 Subject: [PATCH 2/5] mk-sbuild: rationalise architecture variables --- debian/changelog | 3 ++- mk-sbuild | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1f79ad6..290eb25 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low [ Emmet Hikory ] * Support qemu-arm-static -> qemu-kvm-extras-static transition * mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots + * mk-sbuild: rationalise architecture variables [ Loïc Minier ] * Demote qemu-kvm-extras-static to a Suggests since most people don't build @@ -15,7 +16,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low * requestsync: add -C to allow manually adding changelog when missing (LP: #518574). - -- Emmet Hikory Tue, 09 Feb 2010 11:32:02 +0900 + -- Emmet Hikory Tue, 09 Feb 2010 11:38:48 +0900 ubuntu-dev-tools (0.92) lucid; urgency=low diff --git a/mk-sbuild b/mk-sbuild index 2bd6b18..904a447 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -137,9 +137,6 @@ while :; do shift ;; --arch) - # By default, use the native architecture. - arch_opt="--arch=$2" - arch_suffix="-$2" CHROOT_ARCH="$2" if [ "$2" = "i386" ] || [ "$2" = "lpia" ] && [ -z "$personality" ]; then @@ -204,13 +201,14 @@ fi SRC_TYPE="union" SCHROOT_CONF_TYPE="directory" -CHROOT_NAME="${name}${arch_suffix}" - +# By default, use the native architecture. HOST_ARCH=$(dpkg --print-architecture) if [ -z "$CHROOT_ARCH" ]; then - CHROOT_ARCH=$HOST_ARCH + CHROOT_ARCH="$HOST_ARCH" fi +CHROOT_NAME="${name}-${CHROOT_ARCH}" + # Load customizations if [ -r ~/.mk-sbuild.rc ]; then . ~/.mk-sbuild.rc @@ -227,7 +225,7 @@ case "$SRC_TYPE" in fi # Set up some variables for use in the paths and names - CHROOT_LV="${name}_chroot${arch_suffix}" + CHROOT_LV="${name}_chroot-${CHROOT_ARCH}" CHROOT_PATH="/dev/$VG/$CHROOT_LV" # Does the specified VG exist? (vgdisplay doesn't set error codes...) if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then @@ -362,7 +360,7 @@ case "$SRC_TYPE" in esac # debootstrap the chroot -sudo $DEBOOTSTRAP_COMMAND $arch_opt $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" +sudo "$DEBOOTSTRAP_COMMAND" --arch="$CHROOT_ARCH" $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" # Update the package sources TEMP_SOURCES=`mktemp -t sources-XXXXXX` From 7a5de7c8776b765241acbc4c7f5cd19f7512f1df Mon Sep 17 00:00:00 2001 From: Emmet Hikory Date: Tue, 9 Feb 2010 12:07:35 +0900 Subject: [PATCH 3/5] mk-sbuild: automatically install qemu-kvm-extras-static if requested --- debian/changelog | 1 + mk-sbuild | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index 290eb25..52d7e23 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low [ Emmet Hikory ] * Support qemu-arm-static -> qemu-kvm-extras-static transition + * mk-sbuild: automatically install qemu-kvm-extras-static if requested * mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots * mk-sbuild: rationalise architecture variables diff --git a/mk-sbuild b/mk-sbuild index 904a447..e0a7ced 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -327,13 +327,12 @@ debian) esac DEBOOTSTRAP_COMMAND=debootstrap -# Use qemu-arm-static / build-arm-chroot for foreign armel chroots +# Use qemu-kvm-extras-static / build-arm-chroot for foreign armel chroots if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then - if [ -f "/usr/bin/build-arm-chroot" ]; then - DEBOOTSTRAP_COMMAND=build-arm-chroot - else - echo Please install qemu-arm-static to use foreign armel chroots + if [ ! -f "/usr/bin/build-arm-chroot" ]; then + sudo apt-get install qemu-kvm-extras-static fi + DEBOOTSTRAP_COMMAND=build-arm-chroot fi case "$SRC_TYPE" in From acf2ebb9243df905501ff3768d3f8e0d304e1ecb Mon Sep 17 00:00:00 2001 From: Emmet Hikory Date: Tue, 9 Feb 2010 21:29:29 +0900 Subject: [PATCH 4/5] mk-sbuild: Generalise --type support and add "file"|"tarball" type --- debian/changelog | 1 + mk-sbuild | 88 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/debian/changelog b/debian/changelog index 52d7e23..eaae468 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low * mk-sbuild: automatically install qemu-kvm-extras-static if requested * mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots * mk-sbuild: rationalise architecture variables + * mk-sbuild: Generalise --type support and add "file"|"tarball" type [ Loïc Minier ] * Demote qemu-kvm-extras-static to a Suggests since most people don't build diff --git a/mk-sbuild b/mk-sbuild index e0a7ced..0c0ac34 100755 --- a/mk-sbuild +++ b/mk-sbuild @@ -94,6 +94,7 @@ fi LV_SIZE="5G" SNAPSHOT_SIZE="4G" SOURCE_CHROOTS_DIR=/srv/chroot +SOURCE_CHROOTS_TGZ=/var/lib/schroot/tarballs function usage() { @@ -108,9 +109,11 @@ function usage() echo " --debootstrap-mirror=URL Use URL as the debootstrap source" echo " --distro=DISTRO Install specific distro (defaults to 'ubuntu')" echo " --volume-group=VG use LVM snapshots, with group VG" + echo " --type=SCHROOT_TYPE Define the schroot type" echo "" echo "Configuration (via ~/.mk-sbuild.rc)" - echo " SOURCE_CHROOTS_DIR directory to put source chroots in" + echo " SOURCE_CHROOTS_DIR directory to store source chroots" + echo " SOURCE_CHROOTS_TGZ directory to store source chroot tarballs" echo " LV_SIZE Size of source LVs (default ${LV_SIZE})" echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})" echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries" @@ -124,7 +127,7 @@ function usage() if [ -z "$1" ]; then usage fi -OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group" -- "$@"` +OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group:,type:" -- "$@"` eval set -- "$OPTS" VG="" @@ -176,6 +179,10 @@ while :; do VG="$2" shift 2 ;; + --type) + SCHROOT_TYPE="$2" + shift 2 + ;; --) shift break @@ -186,8 +193,7 @@ while :; do esac done -# To build the LV, we need to know which volume group to use, and which -# release of Ubuntu to debootstrap +# To build the chroot, we need to know which release of Ubuntu to debootstrap RELEASE="$1" if [ -z "$RELEASE" ]; then usage @@ -198,9 +204,6 @@ if [ -z "$name" ]; then name="$RELEASE" fi -SRC_TYPE="union" -SCHROOT_CONF_TYPE="directory" - # By default, use the native architecture. HOST_ARCH=$(dpkg --print-architecture) if [ -z "$CHROOT_ARCH" ]; then @@ -214,10 +217,16 @@ if [ -r ~/.mk-sbuild.rc ]; then . ~/.mk-sbuild.rc fi -[ -n "${VG}" ] && { SRC_TYPE="lvm"; SCHROOT_CONF_TYPE="lvm-snapshot"; } +if [ -z "$SCHROOT_TYPE" ]; then + if [ -n "$VG" ]; then + SCHROOT_TYPE=lvm-snapshot + else + SCHROOT_TYPE=directory + fi +fi -case "$SRC_TYPE" in -"lvm") +case "$SCHROOT_TYPE" in +"lvm-snapshot") # Make sure LVM tools that operate on the snapshots have needed module if ! sudo dmsetup targets | grep -q ^snapshot; then sudo modprobe dm_snapshot @@ -227,17 +236,27 @@ case "$SRC_TYPE" in # Set up some variables for use in the paths and names CHROOT_LV="${name}_chroot-${CHROOT_ARCH}" CHROOT_PATH="/dev/$VG/$CHROOT_LV" + # Does the specified VG exist? (vgdisplay doesn't set error codes...) if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then + echo "Volume group ${VG} does not appear to exist" >&2 exit 1 fi ;; -"union") +"directory") if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then - sudo mkdir "${SOURCE_CHROOTS_DIR}" + sudo mkdir -p "${SOURCE_CHROOTS_DIR}" fi ;; -*) echo "unknown source type" >&2; exit 1;; +"tarball"| "file") + if [ ! -d "$SOURCE_CHROOTS_TGZ" ]; then + sudo mkdir -p "$SOURCE_CHROOTS_TGZ" + fi + ;; +*) + echo "unknown source type" >&2 + exit 1 + ;; esac # Is the specified release known to debootstrap? @@ -335,8 +354,8 @@ if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then DEBOOTSTRAP_COMMAND=build-arm-chroot fi -case "$SRC_TYPE" in -"lvm") +case "$SCHROOT_TYPE" in +"lvm-snapshot") # Install lvm2 if missing dpkg -l lvm2 > /dev/null || sudo apt-get install lvm2 @@ -348,7 +367,7 @@ case "$SRC_TYPE" in MNT=`mktemp -d -t schroot-XXXXXX` sudo mount "$CHROOT_PATH" "$MNT" ;; -"union") +"directory") CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}" MNT="${CHROOT_PATH}" if [ -d "${MNT}" ]; then @@ -356,6 +375,9 @@ case "$SRC_TYPE" in fi sudo mkdir -p "${MNT}" ;; +"tarball"|"file") + CHROOT_PATH="${SOURCE_CHROOTS_TGZ}/${CHROOT_NAME}.tgz" + MNT=`mktemp -d -t schroot-XXXXXX` esac # debootstrap the chroot @@ -401,7 +423,8 @@ if [ -r "${TEMPLATE_SCHROOT}" ]; then elif [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF" else - if [ "${SRC_TYPE}" = "lvm" ]; then + case "$SCHROOT_TYPE" in + "lvm-snapshot") cat > "$TEMP_SCHROOTCONF" < "${TEMP_SCHROOTCONF}" < "$TEMP_SCHROOTCONF" << EOM +[CHROOT_NAME] +type=file +union-type=aufs +file=CHROOT_PATH +description=CHROOT_NAME +priority=3 +groups=sbuild,root,admin +root-groups=root,sbuild,admin +EOM + ;; + esac fi if [ ! -z "$personality" ]; then echo "personality=$personality" >> "$TEMP_SCHROOTCONF" @@ -470,10 +507,19 @@ rm /finish.sh EOM sudo chmod +x "$MNT"/finish.sh -if [ "$SRC_TYPE" = "lvm" ]; then +case "$SCHROOT_TYPE" in +"lvm-snapshot") sudo umount "$MNT" rmdir "$MNT" -fi + ;; +"directory") + ;; +"tarball"|"file") + (cd "$MNT" && sudo tar czf "$CHROOT_PATH" .) + sudo rm -r "$MNT" + ;; +esac + # Run finalization script on the "golden" copy via schroot. sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh From 4c598a92470fb1f8d4048788604d66d06e5c6049 Mon Sep 17 00:00:00 2001 From: Emmet Hikory Date: Tue, 9 Feb 2010 22:10:58 +0900 Subject: [PATCH 5/5] * mk-sbuild: Generalise --type support and add "file" SCHROOT_TYPE * mk-sbuild.1: Document the --type argument --- debian/changelog | 5 +++-- doc/mk-sbuild.1 | 15 +++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 155c55b..38451b6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,7 +8,8 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low * mk-sbuild: automatically install qemu-kvm-extras-static if requested * mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots * mk-sbuild: rationalise architecture variables - * mk-sbuild: Generalise --type support and add "file"|"tarball" type + * mk-sbuild: Generalise --type support and add "file" SCHROOT_TYPE + * mk-sbuild.1: Document the --type argument [ Loïc Minier ] * Demote qemu-kvm-extras-static to a Suggests since most people don't build @@ -21,7 +22,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low * mk-sbuild.1: update documentation to reflect alternative config file names for distro and schroot type overrides. - -- Kees Cook Tue, 09 Feb 2010 00:14:26 -0800 + -- Emmet Hikory Tue, 09 Feb 2010 22:08:56 +0900 ubuntu-dev-tools (0.92) lucid; urgency=low diff --git a/doc/mk-sbuild.1 b/doc/mk-sbuild.1 index 8be08ac..7da0745 100644 --- a/doc/mk-sbuild.1 +++ b/doc/mk-sbuild.1 @@ -41,8 +41,11 @@ Enable distro-specific logic. Currently known distros: "ubuntu" (default) and "debian". .TP .B \-\-vg -Specify a volume group, and subsequently use SCHROOT_TYPE of "lvm-snapshot" -rather than "directory" (via aufs) mounts. +Specify a volume group, and subsequently use a default SCHROOT_TYPE of +"lvm-snapshot" rather than "directory" (via aufs) mounts. +.TP +.B \-\-type +Specify a SCHROOT_TYPE. Supported values are "directory" (default if --vg not specified), "lvm-snapshot" (default if --vg specified), and "file". .SH ENVIRONMENT VARIABLES .TP @@ -61,6 +64,10 @@ Do not include the \-updates pocket in the installed sources.list. .B SOURCE_CHROOTS_DIR use SOURCE_CHROOTS_DIR as home of schroot source directories. (default /var/lib/schroot/chroots) +.TP +.B SOURCE_CHROOTS_TGZ +use SOURCE_CHROOTS_TGZ as home of schroot source tarballs. (default +/var/lib/schroot/tarballs) .SH FILES .TP @@ -77,8 +84,8 @@ See sources.list(5) for more details on the format. .B $HOME/.mk\-sbuild.schroot.conf[.$SCHROOT_TYPE] Can contain a customized configuration section to be inserted into /etc/schroot/schroot.conf. -If a file with ".lvm-snapshot" or ".directory" is found (based on the presence -of the \-\-vg argument) that file will use used instead. +If a file with ".lvm-snapshot", ".directory", or ".file" is found (based on the +values of the \-\-vg and \-\-type arguments) that file will use used instead. See schroot.conf(5) for more details on the format. .SH USING THE CHROOTS .TP