#
-# Copyright (C) 2007, 2008, 2009 Google Inc.
+# Copyright (C) 2007, 2008, 2009, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
+CLEANUP=( )
log_error() {
echo "$@" >&2
format_disk0() {
# Create one big partition, and make it bootable
- # some versions of sfdisk need manual specification of
- # head/sectors for devices such as drbd which don't
+ # some versions of sfdisk need manual specification of
+ # head/sectors for devices such as drbd which don't
# report geometry
- sfdisk -H 255 -S 63 --quiet --Linux "$1" <<EOF
-0,,L,*
+ sfdisk -H 64 -S 32 -u S --quiet --Linux "$1" <<EOF
+${PARTITION_ALIGNMENT},,L,*
EOF
}
map_disk0() {
blockdev="$1"
- block_base=`basename $blockdev`
filesystem_dev_base=`kpartx -l -p- $blockdev | \
- grep -m 1 "^$block_base.*$blockdev" | \
+ grep -m 1 -- "-1.*$blockdev" | \
awk '{print $1}'`
- kpartx -a -p- $blockdev
- echo "/dev/mapper/$filesystem_dev_base"
+ if [ -z "$filesystem_dev_base" ]; then
+ log_error "Cannot interpret kpartx output and get partition mapping"
+ exit 1
+ fi
+ kpartx -a -p- $blockdev > /dev/null
+ filesystem_dev="/dev/mapper/$filesystem_dev_base"
+ if [ ! -b "$filesystem_dev" ]; then
+ log_error "Can't find kpartx mapped partition: $filesystem_dev"
+ exit 1
+ fi
+ echo "$filesystem_dev"
}
unmap_disk0() {
fi
}
+trap cleanup EXIT
+
DEFAULT_FILE="@sysconfdir@/default/ganeti-instance-debootstrap"
if [ -f "$DEFAULT_FILE" ]; then
. "$DEFAULT_FILE"
# will use it, this declaration is to make sure the variable is set
: ${MIRROR:=""}
: ${PROXY:=""}
-: ${SUITE:="lenny"}
+: ${SUITE:="wheezy"}
: ${ARCH:=""}
: ${EXTRA_PKGS:=""}
-: ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/instance-debootstrap.d"}
+: ${COMPONENTS:=""}
+: ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/instance-debootstrap/hooks"}
+: ${VARIANTS_DIR:="@sysconfdir@/ganeti/instance-debootstrap/variants"}
: ${GENERATE_CACHE:="yes"}
: ${CLEAN_CACHE:="14"} # number of days to keep a cache file
+: ${PARTITION_ALIGNMENT:=2048} # sectors to align partition (1Mib default)
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
DEFAULT_PARTITION_STYLE="none"
else
DEFAULT_PARTITION_STYLE="msdos"
fi
: ${PARTITION_STYLE:=$DEFAULT_PARTITION_STYLE} # disk partition style
+: ${OSP_FILESYSTEM:="ext4"}
CACHE_DIR="@localstatedir@/cache/ganeti-instance-debootstrap"
SCRIPT_NAME=$(basename $0)
-for dir in /lib/udev /sbin; do
- if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
- VOL_ID=$dir/vol_id
- fi
-done
+if [ -f /sbin/blkid -a -x /sbin/blkid ]; then
+ VOL_ID="/sbin/blkid -o value -s UUID"
+ VOL_TYPE="/sbin/blkid -o value -s TYPE"
+else
+ for dir in /lib/udev /sbin; do
+ if [ -f $dir/vol_id -a -x $dir/vol_id ]; then
+ VOL_ID="$dir/vol_id -u"
+ VOL_TYPE="$dir/vol_id -t"
+ fi
+ done
+fi
if [ -z "$VOL_ID" ]; then
- log_error "vol_id not found, please install udev"
- exit 1
+ log_error "vol_id or blkid not found, please install udev or util-linux"
+ exit 1
fi
if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
GETOPT_RESULT=`getopt -o o:n:i:b:s: -n '$0' -- "$@"`
if [ $? != 0 ] ; then log_error "Terminating..."; exit 1 ; fi
get_api5_arguments $GETOPT_RESULT
-elif [ "$OS_API_VERSION" = "10" ]; then
+elif [ "$OS_API_VERSION" = "10" -o "$OS_API_VERSION" = "15" -o \
+ "$OS_API_VERSION" = "20" ]; then
get_api10_arguments
else
log_error "Unknown OS API VERSION $OS_API_VERSION"
exit 1
fi
+
+if [ -n "$OS_VARIANT" ]; then
+ if [ ! -d "$VARIANTS_DIR" ]; then
+ log_error "OS Variants directory $VARIANTS_DIR doesn't exist"
+ exit 1
+ fi
+ VARIANT_CONFIG="$VARIANTS_DIR/$OS_VARIANT.conf"
+ if [ -f "$VARIANT_CONFIG" ]; then
+ . "$VARIANT_CONFIG"
+ else
+ if grep -qxF "$OS_VARIANT" variants.list; then
+ log_error "ERROR: instance-debootstrap configuration error"
+ log_error " Published variant $OS_VARIANT is missing its config file"
+ log_error " Please create $VARIANT_CONFIG or unpublish the variant"
+ log_error " (by removing $OS_VARIANT from variants.list)"
+ else
+ log_error "Unofficial variant $OS_VARIANT is unsupported"
+ log_error "Most probably this is a user error, forcing a wrong name"
+ log_error "To support this variant please create file $VARIANT_CONFIG"
+ fi
+ exit 1
+ fi
+fi