diff --git a/debian/changelog b/debian/changelog index 2a48220..34cd719 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 @@ -10,8 +13,11 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low [ Kees Cook ] * requestsync: add -C to allow manually adding changelog when missing (LP: #518574). + * mk-sbuild: clean up and make slight adjustments to new lvm/aufs logic. + * mk-sbuild.1: update documentation to reflect alternative config file + names for distro and schroot type overrides. - -- Kees Cook Mon, 08 Feb 2010 10:12:23 -0800 + -- Kees Cook Tue, 09 Feb 2010 00:14:26 -0800 ubuntu-dev-tools (0.92) lucid; urgency=low diff --git a/doc/mk-sbuild-lv.1 b/doc/mk-sbuild.1 similarity index 66% rename from doc/mk-sbuild-lv.1 rename to doc/mk-sbuild.1 index 9c178e4..8be08ac 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" "09 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,10 @@ official Ubuntu repositories for the supported architectures). .B \-\-distro 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. .SH ENVIRONMENT VARIABLES .TP @@ -53,24 +57,32 @@ 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 +/var/lib/schroot/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[.$DISTRO] Can contain a customized sources.list. It will be read when creating the schroot. +If a file with ".ubuntu" or ".debian" is found (based on the \-\-distro +argument) that file will use used instead. See sources.list(5) for more details on the format. .TP -.B $HOME/.mk\-sbuild\-lv.schroot.conf +.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. See schroot.conf(5) for more details on the format. .SH USING THE CHROOTS .TP -To CHANGE the golden image: \fBschroot \-c ${CHROOT_NAME}\-source \-u root\fR +To CHANGE the golden image: \fBsudo schroot \-c ${CHROOT_NAME}\-source \-u root\fR .TP To ENTER an image snapshot: \fBschroot \-c ${CHROOT_NAME}\fR .TP @@ -83,6 +95,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 80% rename from mk-sbuild-lv rename to mk-sbuild index 3df0855..a939648 100755 --- a/mk-sbuild-lv +++ b/mk-sbuild @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright 2006-2009 (C) Canonical Ltd. +# Copyright 2006-2010 (C) Canonical Ltd. # Author: Kees Cook # # ################################################################## @@ -19,7 +19,8 @@ # # ################################################################## # -# This script creates LVM snapshot chroots via schroot and sbuild. +# This script creates chroots designed to be used in a snapshot mode +# (either with LVM or aufs) with schroot and sbuild. # Much love to "man sbuild-setup", https://wiki.ubuntu.com/PbuilderHowto, # and https://help.ubuntu.com/community/SbuildLVMHowto. # @@ -40,11 +41,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,23 +94,27 @@ fi # Set up configurable defaults (loaded after option processing) LV_SIZE="5G" SNAPSHOT_SIZE="4G" +SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots" 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)" echo " --personality=PERSONALITY What personality to use (defaults to match --arch)" + echo " --vg=VG use LVM snapshots, with group VG" echo " --debug Turn on script debugging" echo " --skip-updates Do not include -updates pocket in sources.list" 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 " --distro=DISTRO Install specific distro:" + echo " 'ubuntu'(default), or 'debian'" echo "" - echo "Configuration (via ~/.mk-sbuild-lv.rc)" + echo "Configuration (via ~/.mk-sbuild.rc)" echo " LV_SIZE Size of source LVs (default ${LV_SIZE})" echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})" + echo " SOURCE_CHROOTS_DIR Directory to put aufs source chroots into" echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries" echo " SKIP_UPDATES Enable --skip-updates" echo " TEMPLATE_SOURCES A template for sources.list" @@ -126,9 +126,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:,vg:" -- "$@"` eval set -- "$OPTS" +VG="" DISTRO="ubuntu" name="" while :; do @@ -176,6 +177,10 @@ while :; do DISTRO="$2" shift 2 ;; + --volume-group|--vg) + VG="$2" + shift 2 + ;; --) shift break @@ -186,11 +191,9 @@ while :; do esac 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 +# We need to know the release to debootstrap +RELEASE="$1" +if [ -z "$RELEASE" ]; then usage fi @@ -199,9 +202,6 @@ 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" CHROOT_NAME="${name}${arch_suffix}" HOST_ARCH=$(dpkg --print-architecture) @@ -210,21 +210,50 @@ 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 +SRC_TYPE="union" +SCHROOT_CONF_TYPE="directory" +# To build the LV, we need to know which volume group to use +if [ -n "${VG}" ]; then + SRC_TYPE="lvm" + SCHROOT_CONF_TYPE="lvm-snapshot" fi +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 -p "${SOURCE_CHROOTS_DIR}" + fi + ;; +*) + echo 'unknown source type!?' >&2 + exit 1 + ;; +esac + # Is the specified release known to debootstrap? +variant_opt="--variant=buildd" if [ ! -r "/usr/share/debootstrap/scripts/$RELEASE" ]; then echo "Specified release not known to debootstrap" >&2 exit 1 -else - variant_opt="--variant=buildd" fi BUILD_PKGS="build-essential fakeroot devscripts apt-utils" @@ -305,30 +334,45 @@ 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 if [ -f "/usr/bin/build-arm-chroot" ]; then - DEBOOTSTRAP_COMMAND=build-arm-chroot + DEBOOTSTRAP_COMMAND=build-arm-chroot else - echo Please install qemu-arm-static to use foreign armel chroots + echo 'Please install qemu-arm-static to use foreign armel chroots' >&2 + exit 1 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 "E: ${MNT} already exists; aborting" >&2 + 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" @@ -355,28 +399,41 @@ cat "$TEMP_SOURCES" | sed -e "s|RELEASE|$RELEASE|g" | \ rm -f "$TEMP_SOURCES" # Copy the timezone (comment this out if you want to leave the chroot at UTC) sudo cp /etc/localtime /etc/timezone "$MNT"/etc/ -# Create an LVM-snapshot-based schroot entry for this LV +# Create a schroot entry for this chroot TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX` -TEMPLATE_SCHROOTCONF=~/.mk-sbuild-lv.schroot.conf -if [ -r "$TEMPLATE_SCHROOTCONF" ]; then +TEMPLATE_SCHROOTCONF=~/.mk-sbuild.schroot.conf +TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_CONF_TYPE}" + +if [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then + cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF" +elif [ -r "${TEMPLATE_SCHROOT}" ]; then cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF" else - cat > "$TEMP_SCHROOTCONF" < "$TEMP_SCHROOTCONF" <> "$TEMP_SCHROOTCONF" <> "${TEMP_SCHROOTCONF}" <> "$TEMP_SCHROOTCONF" @@ -388,6 +445,7 @@ cat "$TEMP_SCHROOTCONF" | sed \ -e "s|CHROOT_NAME|$CHROOT_NAME|g" \ -e "s|CHROOT_PATH|$CHROOT_PATH|g" \ -e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \ + -e "s|SCHROOT_CONF_TYPE|$SCHROOT_CONF_TYPE|g" \ | \ sudo bash -c "cat >> /etc/schroot/schroot.conf" rm -f "$TEMP_SCHROOTCONF" @@ -416,9 +474,12 @@ if [ ! -r /dev/stderr ]; then ln -s /proc/self/fd/2 /dev/stderr; fi apt-get clean rm /finish.sh EOM -sudo chmod +x "$MNT"/finish.sh -sudo umount "$MNT" -rmdir "$MNT" +sudo chmod a+x "$MNT"/finish.sh + +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',