Add raw image support

This commit is contained in:
Dean Troyer 2011-09-16 17:22:23 -05:00
parent 120713c181
commit 57794d4842
2 changed files with 30 additions and 22 deletions

View File

@ -3,7 +3,7 @@
# #
# make_image.sh release format # make_image.sh release format
# #
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc) # Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
# #
# Requires sudo to root # Requires sudo to root
@ -36,22 +36,29 @@ FORMAT=$2
case $FORMAT in case $FORMAT in
kvm|qcow2) FORMAT=qcow2 kvm|qcow2) FORMAT=qcow2
TARGET=kvm QFORMAT=qcow2
HYPER=kvm
;; ;;
vmserver|vmdk) vmserver|vmdk)
FORMAT=vmdk FORMAT=vmdk
TARGET=vmserver QFORMAT=vmdk
HYPER=vmserver
;; ;;
vbox|vdi) FORMAT=qcow2 vbox|vdi) FORMAT=vdi
TARGET=kvm QFORMAT=vdi
FINAL_FORMAT=vdi HYPER=kvm
;; ;;
vhd|vpc) FORMAT=qcow2 vhd|vpc) FORMAT=vhd
TARGET=kvm QFORMAT=vpc
FINAL_FORMAT=vhd HYPER=kvm
;; ;;
xen) FORMAT=raw xen) FORMAT=raw
TARGET=xen QFORMAT=raw
HYPER=xen
;;
raw) FORMAT=raw
QFORMAT=raw
HYPER=kvm
;; ;;
*) echo "Unknown format: $FORMAT" *) echo "Unknown format: $FORMAT"
usage usage
@ -74,24 +81,23 @@ if [ -z `which vmbuilder` ]; then
fi fi
# Build the image # Build the image
sudo vmbuilder $TARGET ubuntu --suite $RELEASE \ TMPDISK=`mktemp imgXXXXXXXX`
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE
sudo vmbuilder $HYPER ubuntu --suite $RELEASE \
-o \ -o \
--rootsize=$ROOTSIZE \ --rootsize=$ROOTSIZE \
--swapsize=$SWAPSIZE \ --swapsize=$SWAPSIZE \
--tmpfs - \ --tmpfs - \
--addpkg=openssh-server \ --addpkg=openssh-server \
--raw=$TMPDISK \
# --mirror=$MIRROR \ if [ "$FORMAT" = "raw" ]; then
if [ -z "$FINAL_FORMAT" ]; then
# Get image # Get image
mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT mv $TMPDISK $RELEASE.$FORMAT
else else
# Convert image # Convert image
tgt=$FINAL_FORMAT qemu-img convert -O $QFORMAT $TMPDISK $RELEASE.$FORMAT
if [ "$tgt" = "vhd" ]; then rm $TMPDISK
tgt=vpc
fi fi
qemu-img convert -O $tgt ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT rm -rf ubuntu-$HYPER
fi
rm -rf ubuntu-$TARGET

View File

@ -63,6 +63,7 @@ if [ -z "$GLANCE" ]; then
# Look for stack.sh's install # Look for stack.sh's install
GLANCE="/opt/glance/bin/glance" GLANCE="/opt/glance/bin/glance"
else else
# Install Glance client in /opt
echo "Glance not found, must install client" echo "Glance not found, must install client"
OWD=`pwd` OWD=`pwd`
cd /opt cd /opt
@ -79,9 +80,10 @@ fi
# Create image if it doesn't exist # Create image if it doesn't exist
if [ ! -r $RELEASE.$FORMAT ]; then if [ ! -r $RELEASE.$FORMAT ]; then
DIR=`dirname $0` DIR=`dirname $0`
echo "$RELEASE.$FORMAT not found, creating...must be root to do this:" echo "$RELEASE.$FORMAT not found, creating..."
$DIR/make_image.sh $RELEASE $FORMAT $DIR/make_image.sh $RELEASE $FORMAT
fi fi
# Upload the image # Upload the image
echo "Uploading image $RELEASE.$FORMAT to $HOST"
$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT $GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT