add union-type support fot mk-sbuild-lv (rename -> mk-sbuild)

This commit is contained in:
Scott Moser 2010-02-08 20:04:33 -05:00
parent 07451d8631
commit 3997415b8f
4 changed files with 112 additions and 48 deletions

3
debian/changelog vendored
View File

@ -1,5 +1,8 @@
ubuntu-dev-tools (0.93) UNRELEASED; urgency=low ubuntu-dev-tools (0.93) UNRELEASED; urgency=low
[ Scott Moser ]
* rename mk-sbuild-lv to mk-sbuild, support union-type=aufs
[ Emmet Hikory ] [ Emmet Hikory ]
* Support qemu-arm-static -> qemu-kvm-extras-static transition * Support qemu-arm-static -> qemu-kvm-extras-static transition

View File

@ -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 .SH NAME
mk\-sbuild\-lv \- creates LVM snapshot chroots via schroot and sbuild mk\-sbuild \- creates chroots via schroot and sbuild
.SH SYNOPSIS .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\-\-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 .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 .SH OPTIONS
Listed below are the command line options for mk\-sbuild\-lv: Listed below are the command line options for mk\-sbuild:
.TP .TP
.B \-\-arch=ARCH .B \-\-arch=ARCH
What architecture to select (defaults to the native architecture). 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. Do not include the \-updates pocket in the installed sources.list.
.TP .TP
.B \-\-source\-template=FILE .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 .TP
.B \-\-debootstrap\-mirror=URL .B \-\-debootstrap\-mirror=URL
Use URL as the debootstrap source (defaults to http://ports.ubuntu.com for lpia, 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 .B \-\-distro
Enable distro-specific logic. Currently known distros: "ubuntu" (default) Enable distro-specific logic. Currently known distros: "ubuntu" (default)
and "debian". and "debian".
.TP
.B \-\-volume-group
Specify a volume group, and subsequently use lvm-snapshot rather than aufs mounts.
.SH ENVIRONMENT VARIABLES .SH ENVIRONMENT VARIABLES
.TP .TP
@ -53,18 +56,21 @@ Lines to append to schroot entries.
.TP .TP
.B SKIP_UPDATES .B SKIP_UPDATES
Do not include the \-updates pocket in the installed sources.list. 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 .SH FILES
.TP .TP
.B $HOME/.mk\-sbuild\-lv.rc .B $HOME/.mk\-sbuild.rc
Sourced for environment variables (defined above). Sourced for environment variables (defined above).
.TP .TP
.B $HOME/.mk\-sbuild\-lv.sources .B $HOME/.mk\-sbuild.sources
Can contain a customized sources.list. Can contain a customized sources.list.
It will be read when creating the schroot. It will be read when creating the schroot.
See sources.list(5) for more details on the format. See sources.list(5) for more details on the format.
.TP .TP
.B $HOME/.mk\-sbuild\-lv.schroot.conf .B $HOME/.mk\-sbuild.schroot.conf
Can contain a customized configuration section to be inserted into Can contain a customized configuration section to be inserted into
/etc/schroot/schroot.conf. /etc/schroot/schroot.conf.
See schroot.conf(5) for more details on the format. 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 https://help.ubuntu.com/community/SbuildLVMHowto
.SH AUTHOR .SH AUTHOR
\fBmk\-sbuild\-lv\fR was written by Kees Cook <kees@ubuntu.com>. \fBmk\-sbuild\fR was written by Kees Cook <kees@ubuntu.com>.
This man page was written by Ryan Kavanagh <ryanakca@kubuntu.org>. This man page was written by Ryan Kavanagh <ryanakca@kubuntu.org>.
Both are released under the GNU General Public License, version 3 or later. Both are released under the GNU General Public License, version 3 or later.

View File

@ -40,11 +40,6 @@ fi
if [ ! -w /var/lib/sbuild ]; then if [ ! -w /var/lib/sbuild ]; then
# Load all the packages you'll need to do work # 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 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 # Add self to the sbuild group
sudo adduser "$USER" sbuild sudo adduser "$USER" sbuild
@ -98,10 +93,11 @@ fi
# Set up configurable defaults (loaded after option processing) # Set up configurable defaults (loaded after option processing)
LV_SIZE="5G" LV_SIZE="5G"
SNAPSHOT_SIZE="4G" SNAPSHOT_SIZE="4G"
SOURCE_CHROOTS_DIR=/srv/chroot
function usage() function usage()
{ {
echo "Usage: $0 [OPTIONS] VG Release" >&2 echo "Usage: $0 [OPTIONS] Release" >&2
echo "Options:" echo "Options:"
echo " --arch=ARCH What architecture to select" echo " --arch=ARCH What architecture to select"
echo " --name=NAME Base name for the schroot (arch is appended)" 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 " --source-template=FILE Use FILE as the sources.list template"
echo " --debootstrap-mirror=URL Use URL as the debootstrap source" 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 (defaults to 'ubuntu')"
echo " --volume-group=VG use LVM snapshots, with group VG"
echo "" 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 " LV_SIZE Size of source LVs (default ${LV_SIZE})"
echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})" echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})"
echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries" echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries"
@ -126,9 +124,10 @@ function usage()
if [ -z "$1" ]; then if [ -z "$1" ]; then
usage usage
fi 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" eval set -- "$OPTS"
VG=""
DISTRO="ubuntu" DISTRO="ubuntu"
name="" name=""
while :; do while :; do
@ -176,6 +175,10 @@ while :; do
DISTRO="$2" DISTRO="$2"
shift 2 shift 2
;; ;;
--volume-group)
VG="$2"
shift 2
;;
--) --)
shift shift
break break
@ -188,9 +191,8 @@ done
# To build the LV, we need to know which volume group to use, and which # To build the LV, we need to know which volume group to use, and which
# release of Ubuntu to debootstrap # release of Ubuntu to debootstrap
VG="$1" RELEASE="$1"
RELEASE="$2" if [ -z "$RELEASE" ]; then
if [ -z "$VG" ] || [ -z "$RELEASE" ]; then
usage usage
fi fi
@ -199,9 +201,9 @@ if [ -z "$name" ]; then
name="$RELEASE" name="$RELEASE"
fi fi
# Set up some variables for use in the paths and names SRC_TYPE="union"
CHROOT_LV="${name}_chroot${arch_suffix}" SCHROOT_CONF_TYPE="directory"
CHROOT_PATH="/dev/$VG/$CHROOT_LV"
CHROOT_NAME="${name}${arch_suffix}" CHROOT_NAME="${name}${arch_suffix}"
HOST_ARCH=$(dpkg --print-architecture) HOST_ARCH=$(dpkg --print-architecture)
@ -210,14 +212,35 @@ if [ -z "$CHROOT_ARCH" ]; then
fi fi
# Load customizations # Load customizations
if [ -r ~/.mk-sbuild-lv.rc ]; then if [ -r ~/.mk-sbuild.rc ]; then
. ~/.mk-sbuild-lv.rc . ~/.mk-sbuild.rc
fi fi
# Does the specified VG exist? (vgdisplay doesn't set error codes...) [ -n "${VG}" ] && { SRC_TYPE="lvm"; SCHROOT_CONF_TYPE="lvm-snapshot"; }
if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then
exit 1 case "$SRC_TYPE" in
fi "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? # Is the specified release known to debootstrap?
if [ ! -r "/usr/share/debootstrap/scripts/$RELEASE" ]; then if [ ! -r "/usr/share/debootstrap/scripts/$RELEASE" ]; then
@ -305,14 +328,6 @@ debian)
;; ;;
esac 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 DEBOOTSTRAP_COMMAND=debootstrap
# Use qemu-arm-static / build-arm-chroot for foreign armel chroots # Use qemu-arm-static / build-arm-chroot for foreign armel chroots
if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then
@ -323,12 +338,33 @@ if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then
fi fi
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}" sudo $DEBOOTSTRAP_COMMAND $arch_opt $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}"
# Update the package sources # Update the package sources
TEMP_SOURCES=`mktemp -t sources-XXXXXX` TEMP_SOURCES=`mktemp -t sources-XXXXXX`
if [ -z "$TEMPLATE_SOURCES" ]; then if [ -z "$TEMPLATE_SOURCES" ]; then
TEMPLATE_SOURCES=~/.mk-sbuild-lv.sources TEMPLATE_SOURCES=~/.mk-sbuild.sources
fi fi
if [ -r "$TEMPLATE_SOURCES" ]; then if [ -r "$TEMPLATE_SOURCES" ]; then
cat "$TEMPLATE_SOURCES" > "$TEMP_SOURCES" cat "$TEMPLATE_SOURCES" > "$TEMP_SOURCES"
@ -357,12 +393,16 @@ rm -f "$TEMP_SOURCES"
sudo cp /etc/localtime /etc/timezone "$MNT"/etc/ sudo cp /etc/localtime /etc/timezone "$MNT"/etc/
# Create an LVM-snapshot-based schroot entry for this LV # Create an LVM-snapshot-based schroot entry for this LV
TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX` TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX`
TEMPLATE_SCHROOTCONF=~/.mk-sbuild-lv.schroot.conf TEMPLATE_SCHROOTCONF=~/.mk-sbuild.schroot.conf
if [ -r "$TEMPLATE_SCHROOTCONF" ]; then TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_CONF_TYPE}"
cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF"
else
cat > "$TEMP_SCHROOTCONF" <<EOM
if [ -r "${TEMPLATE_SCHROOT}" ]; then
cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF"
elif [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then
cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF"
else
if [ "${SRC_TYPE}" = "lvm" ]; then
cat > "$TEMP_SCHROOTCONF" <<EOM
[CHROOT_NAME] [CHROOT_NAME]
type=lvm-snapshot type=lvm-snapshot
description=CHROOT_NAME description=CHROOT_NAME
@ -377,6 +417,18 @@ lvm-snapshot-options=--size SNAPSHOT_SIZE
#source-root-users=root,sbuild,admin #source-root-users=root,sbuild,admin
#source-root-groups=root,sbuild,admin #source-root-groups=root,sbuild,admin
EOM EOM
elif [ "${SRC_TYPE}" = "union" ]; then
cat > "${TEMP_SCHROOTCONF}" <<EOM
[CHROOT_NAME]
type=directory
union-type=aufs
directory=CHROOT_PATH
description=CHROOT_NAME
priority=3
groups=sbuild,root,admin
root-groups=root,sbuild,admin
EOM
fi
fi fi
if [ ! -z "$personality" ]; then if [ ! -z "$personality" ]; then
echo "personality=$personality" >> "$TEMP_SCHROOTCONF" echo "personality=$personality" >> "$TEMP_SCHROOTCONF"
@ -417,8 +469,11 @@ apt-get clean
rm /finish.sh rm /finish.sh
EOM EOM
sudo chmod +x "$MNT"/finish.sh 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. # Run finalization script on the "golden" copy via schroot.
sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh

View File

@ -29,7 +29,7 @@ setup(name='ubuntu-dev-tools',
'lp-shell', 'lp-shell',
'manage-credentials', 'manage-credentials',
'massfile', 'massfile',
'mk-sbuild-lv', 'mk-sbuild',
'pbuilder-dist', 'pbuilder-dist',
'pbuilder-dist-simple', 'pbuilder-dist-simple',
'pull-debian-debdiff', 'pull-debian-debdiff',