From 3997415b8f63c2602a18990c50072ae7a397d7ed Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 8 Feb 2010 20:04:33 -0500 Subject: [PATCH] add union-type support fot mk-sbuild-lv (rename -> mk-sbuild) --- debian/changelog | 3 + doc/{mk-sbuild-lv.1 => mk-sbuild.1} | 28 +++--- mk-sbuild-lv => mk-sbuild | 127 ++++++++++++++++++++-------- setup.py | 2 +- 4 files changed, 112 insertions(+), 48 deletions(-) rename doc/{mk-sbuild-lv.1 => mk-sbuild.1} (75%) rename mk-sbuild-lv => mk-sbuild (84%) diff --git a/debian/changelog b/debian/changelog index 2a48220..2c8d468 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,8 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low + [ Scott Moser ] + * rename mk-sbuild-lv to mk-sbuild, support union-type=aufs + [ Emmet Hikory ] * Support qemu-arm-static -> qemu-kvm-extras-static transition diff --git a/doc/mk-sbuild-lv.1 b/doc/mk-sbuild.1 similarity index 75% rename from doc/mk-sbuild-lv.1 rename to doc/mk-sbuild.1 index 9c178e4..90fbaca 100644 --- a/doc/mk-sbuild-lv.1 +++ b/doc/mk-sbuild.1 @@ -1,18 +1,18 @@ -.TH MK\-SBUILD\-LV "1" "27 August 2008" "ubuntu-dev-tools" +.TH MK\-SBUILD "1" "08 February 2010" "ubuntu-dev-tools" .SH NAME -mk\-sbuild\-lv \- creates LVM snapshot chroots via schroot and sbuild +mk\-sbuild \- creates chroots via schroot and sbuild .SH SYNOPSIS -\fBmk\-sbuild\-lv\fR [\fB\-\-arch=ARCH\fR] [\fB\-\-name=NAME\fR] +\fBmk\-sbuild\fR [\fB\-\-arch=ARCH\fR] [\fB\-\-name=NAME\fR] [\fB\-\-personality=PERSONALITY\fR] [\fB\-\-debug\fR] [\fB\-\-source\-template=FILE\fR] -[\fB\-\-debootstrap\-mirror=URL\fR] <\fBVG\fR> <\fBRelease\fR> +[\fB\-\-debootstrap\-mirror=URL\fR] <\fBRelease\fR> .SH DESCRIPTION -\fBmk\-sbuild\-lv\fR creates LVM snapshot chroots via schroot and sbuild. +\fBmk\-sbuild\fR creates chroots via schroot and sbuild. .SH OPTIONS -Listed below are the command line options for mk\-sbuild\-lv: +Listed below are the command line options for mk\-sbuild: .TP .B \-\-arch=ARCH What architecture to select (defaults to the native architecture). @@ -30,7 +30,7 @@ Turn on script debugging. Do not include the \-updates pocket in the installed sources.list. .TP .B \-\-source\-template=FILE -Use FILE as the sources.list template (defaults to $HOME/.mk\-sbuild\-lv.sources). +Use FILE as the sources.list template (defaults to $HOME/.mk\-sbuild.sources). .TP .B \-\-debootstrap\-mirror=URL Use URL as the debootstrap source (defaults to http://ports.ubuntu.com for lpia, @@ -39,6 +39,9 @@ official Ubuntu repositories for the supported architectures). .B \-\-distro Enable distro-specific logic. Currently known distros: "ubuntu" (default) and "debian". +.TP +.B \-\-volume-group +Specify a volume group, and subsequently use lvm-snapshot rather than aufs mounts. .SH ENVIRONMENT VARIABLES .TP @@ -53,18 +56,21 @@ Lines to append to schroot entries. .TP .B SKIP_UPDATES Do not include the \-updates pocket in the installed sources.list. +.TP +.B SOURCE_CHROOTS_DIR +use SOURCE_CHROOTS_DIR as home of schroot source directories. (default /srv/chroots) .SH FILES .TP -.B $HOME/.mk\-sbuild\-lv.rc +.B $HOME/.mk\-sbuild.rc Sourced for environment variables (defined above). .TP -.B $HOME/.mk\-sbuild\-lv.sources +.B $HOME/.mk\-sbuild.sources Can contain a customized sources.list. It will be read when creating the schroot. See sources.list(5) for more details on the format. .TP -.B $HOME/.mk\-sbuild\-lv.schroot.conf +.B $HOME/.mk\-sbuild.schroot.conf Can contain a customized configuration section to be inserted into /etc/schroot/schroot.conf. See schroot.conf(5) for more details on the format. @@ -83,6 +89,6 @@ sbuild\-setup (7), sources.list (5), schroot.conf (5), https://help.ubuntu.com/community/SbuildLVMHowto .SH AUTHOR -\fBmk\-sbuild\-lv\fR was written by Kees Cook . +\fBmk\-sbuild\fR was written by Kees Cook . This man page was written by Ryan Kavanagh . Both are released under the GNU General Public License, version 3 or later. diff --git a/mk-sbuild-lv b/mk-sbuild similarity index 84% rename from mk-sbuild-lv rename to mk-sbuild index 3df0855..e646540 100755 --- a/mk-sbuild-lv +++ b/mk-sbuild @@ -40,11 +40,6 @@ fi if [ ! -w /var/lib/sbuild ]; then # Load all the packages you'll need to do work sudo apt-get install sbuild schroot debootstrap lvm2 - # Make sure LVM tools that operate on the snapshots have needed module - if ! sudo dmsetup targets | grep -q ^snapshot; then - sudo modprobe dm_snapshot - echo dm_snapshot | sudo tee -a /etc/modules >/dev/null - fi # Add self to the sbuild group sudo adduser "$USER" sbuild @@ -98,10 +93,11 @@ fi # Set up configurable defaults (loaded after option processing) LV_SIZE="5G" SNAPSHOT_SIZE="4G" +SOURCE_CHROOTS_DIR=/srv/chroot function usage() { - echo "Usage: $0 [OPTIONS] VG Release" >&2 + echo "Usage: $0 [OPTIONS] Release" >&2 echo "Options:" echo " --arch=ARCH What architecture to select" echo " --name=NAME Base name for the schroot (arch is appended)" @@ -111,8 +107,10 @@ function usage() echo " --source-template=FILE Use FILE as the sources.list template" 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 "" - echo "Configuration (via ~/.mk-sbuild-lv.rc)" + echo "Configuration (via ~/.mk-sbuild.rc)" + echo " SOURCE_CHROOTS_DIR directory to put source chroots in" 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" @@ -126,9 +124,10 @@ function usage() if [ -z "$1" ]; then usage fi -OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:" -- "$@"` +OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group" -- "$@"` eval set -- "$OPTS" +VG="" DISTRO="ubuntu" name="" while :; do @@ -176,6 +175,10 @@ while :; do DISTRO="$2" shift 2 ;; + --volume-group) + VG="$2" + shift 2 + ;; --) shift break @@ -188,9 +191,8 @@ done # To build the LV, we need to know which volume group to use, and which # release of Ubuntu to debootstrap -VG="$1" -RELEASE="$2" -if [ -z "$VG" ] || [ -z "$RELEASE" ]; then +RELEASE="$1" +if [ -z "$RELEASE" ]; then usage fi @@ -199,9 +201,9 @@ if [ -z "$name" ]; then name="$RELEASE" fi -# Set up some variables for use in the paths and names -CHROOT_LV="${name}_chroot${arch_suffix}" -CHROOT_PATH="/dev/$VG/$CHROOT_LV" +SRC_TYPE="union" +SCHROOT_CONF_TYPE="directory" + CHROOT_NAME="${name}${arch_suffix}" HOST_ARCH=$(dpkg --print-architecture) @@ -210,14 +212,35 @@ if [ -z "$CHROOT_ARCH" ]; then fi # Load customizations -if [ -r ~/.mk-sbuild-lv.rc ]; then - . ~/.mk-sbuild-lv.rc +if [ -r ~/.mk-sbuild.rc ]; then + . ~/.mk-sbuild.rc fi -# Does the specified VG exist? (vgdisplay doesn't set error codes...) -if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then - exit 1 -fi +[ -n "${VG}" ] && { SRC_TYPE="lvm"; SCHROOT_CONF_TYPE="lvm-snapshot"; } + +case "$SRC_TYPE" in +"lvm") + # Make sure LVM tools that operate on the snapshots have needed module + if ! sudo dmsetup targets | grep -q ^snapshot; then + sudo modprobe dm_snapshot + echo dm_snapshot | sudo tee -a /etc/modules >/dev/null + fi + + # Set up some variables for use in the paths and names + CHROOT_LV="${name}_chroot${arch_suffix}" + 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 + exit 1 + fi + ;; +"union") + if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then + sudo mkdir "${SOURCE_CHROOTS_DIR}" + fi + ;; +*) echo "unknown source type" >&2; exit 1;; +esac # Is the specified release known to debootstrap? if [ ! -r "/usr/share/debootstrap/scripts/$RELEASE" ]; then @@ -305,14 +328,6 @@ debian) ;; esac -# Allocate the "golden" chroot LV -sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG" -sudo mkfs -t ext4 "$CHROOT_PATH" - -# Mount and debootstrap the chroot -MNT=`mktemp -d -t schroot-XXXXXX` -sudo mount "$CHROOT_PATH" "$MNT" - DEBOOTSTRAP_COMMAND=debootstrap # Use qemu-arm-static / build-arm-chroot for foreign armel chroots if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then @@ -323,12 +338,33 @@ if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then fi fi +case "$SRC_TYPE" in +"lvm") + # Allocate the "golden" chroot LV + sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG" + sudo mkfs -t ext4 "$CHROOT_PATH" + + # Mount + MNT=`mktemp -d -t schroot-XXXXXX` + sudo mount "$CHROOT_PATH" "$MNT" + ;; +"union") + CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}" + MNT="${CHROOT_PATH}" + if [ -d "${MNT}" ]; then + echo "${MNT} exists. exiting"; exit 1; + fi + sudo mkdir -p "${MNT}" + ;; +esac + +# debootstrap the chroot sudo $DEBOOTSTRAP_COMMAND $arch_opt $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" # Update the package sources TEMP_SOURCES=`mktemp -t sources-XXXXXX` if [ -z "$TEMPLATE_SOURCES" ]; then - TEMPLATE_SOURCES=~/.mk-sbuild-lv.sources + TEMPLATE_SOURCES=~/.mk-sbuild.sources fi if [ -r "$TEMPLATE_SOURCES" ]; then cat "$TEMPLATE_SOURCES" > "$TEMP_SOURCES" @@ -357,12 +393,16 @@ rm -f "$TEMP_SOURCES" sudo cp /etc/localtime /etc/timezone "$MNT"/etc/ # Create an LVM-snapshot-based schroot entry for this LV TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX` -TEMPLATE_SCHROOTCONF=~/.mk-sbuild-lv.schroot.conf -if [ -r "$TEMPLATE_SCHROOTCONF" ]; then - cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF" -else - cat > "$TEMP_SCHROOTCONF" < "$TEMP_SCHROOTCONF" +elif [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then + cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF" +else + if [ "${SRC_TYPE}" = "lvm" ]; then + cat > "$TEMP_SCHROOTCONF" < "${TEMP_SCHROOTCONF}" <> "$TEMP_SCHROOTCONF" @@ -417,8 +469,11 @@ apt-get clean rm /finish.sh EOM sudo chmod +x "$MNT"/finish.sh -sudo umount "$MNT" -rmdir "$MNT" + +if [ "$SRC_TYPE" = "lvm" ]; then + sudo umount "$MNT" + rmdir "$MNT" +fi # Run finalization script on the "golden" copy via schroot. sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh diff --git a/setup.py b/setup.py index fb97517..25007a3 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup(name='ubuntu-dev-tools', 'lp-shell', 'manage-credentials', 'massfile', - 'mk-sbuild-lv', + 'mk-sbuild', 'pbuilder-dist', 'pbuilder-dist-simple', 'pull-debian-debdiff',