2011-09-16 17:22:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# make_image.sh - Create Ubuntu images in various formats
|
|
|
|
#
|
|
|
|
# make_image.sh release format
|
|
|
|
#
|
2011-09-16 22:22:23 +00:00
|
|
|
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
|
2011-09-16 17:22:21 +00:00
|
|
|
#
|
|
|
|
# Requires sudo to root
|
|
|
|
|
|
|
|
ROOTSIZE=${ROOTSIZE:-8192}
|
|
|
|
SWAPSIZE=${SWAPSIZE:-1024}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "$0 - Create Ubuntu images"
|
|
|
|
echo ""
|
|
|
|
echo "$0 [-r rootsize] [-s swapsize] release format"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts hm:r:s: c; do
|
|
|
|
case $c in
|
2011-09-16 21:16:34 +00:00
|
|
|
h) usage
|
|
|
|
;;
|
|
|
|
m) MIRROR=$OPTARG
|
|
|
|
;;
|
|
|
|
r) ROOTSIZE=$OPTARG
|
|
|
|
;;
|
|
|
|
s) SWAPSIZE=$OPTARG
|
|
|
|
;;
|
2011-09-16 17:22:21 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift `expr $OPTIND - 1`
|
|
|
|
|
|
|
|
RELEASE=$1
|
|
|
|
FORMAT=$2
|
|
|
|
|
2011-09-16 21:16:34 +00:00
|
|
|
case $FORMAT in
|
|
|
|
kvm|qcow2) FORMAT=qcow2
|
2011-09-16 22:22:23 +00:00
|
|
|
QFORMAT=qcow2
|
|
|
|
HYPER=kvm
|
2011-09-16 21:16:34 +00:00
|
|
|
;;
|
|
|
|
vmserver|vmdk)
|
|
|
|
FORMAT=vmdk
|
2011-09-16 22:22:23 +00:00
|
|
|
QFORMAT=vmdk
|
|
|
|
HYPER=vmserver
|
2011-09-16 21:16:34 +00:00
|
|
|
;;
|
2011-09-16 22:22:23 +00:00
|
|
|
vbox|vdi) FORMAT=vdi
|
|
|
|
QFORMAT=vdi
|
|
|
|
HYPER=kvm
|
2011-09-16 21:16:34 +00:00
|
|
|
;;
|
2011-09-16 22:22:23 +00:00
|
|
|
vhd|vpc) FORMAT=vhd
|
|
|
|
QFORMAT=vpc
|
|
|
|
HYPER=kvm
|
2011-09-16 21:16:34 +00:00
|
|
|
;;
|
|
|
|
xen) FORMAT=raw
|
2011-09-16 22:22:23 +00:00
|
|
|
QFORMAT=raw
|
|
|
|
HYPER=xen
|
|
|
|
;;
|
|
|
|
raw) FORMAT=raw
|
|
|
|
QFORMAT=raw
|
|
|
|
HYPER=kvm
|
2011-09-16 21:16:34 +00:00
|
|
|
;;
|
|
|
|
*) echo "Unknown format: $FORMAT"
|
|
|
|
usage
|
2011-09-16 17:22:21 +00:00
|
|
|
esac
|
|
|
|
|
2011-09-16 21:16:34 +00:00
|
|
|
case $RELEASE in
|
|
|
|
natty) ;;
|
|
|
|
maverick) ;;
|
|
|
|
lucid) ;;
|
|
|
|
karmic) ;;
|
|
|
|
jaunty) ;;
|
|
|
|
*) echo "Unknown release: $RELEASE"
|
|
|
|
usage
|
|
|
|
;;
|
2011-09-16 17:22:21 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Install stuff if necessary
|
|
|
|
if [ -z `which vmbuilder` ]; then
|
2011-09-16 21:16:34 +00:00
|
|
|
sudo apt-get install ubuntu-vm-builder
|
2011-09-16 17:22:21 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build the image
|
2011-09-16 22:22:23 +00:00
|
|
|
TMPDISK=`mktemp imgXXXXXXXX`
|
|
|
|
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
|
|
|
|
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE
|
|
|
|
sudo vmbuilder $HYPER ubuntu --suite $RELEASE \
|
2011-09-16 17:22:21 +00:00
|
|
|
-o \
|
|
|
|
--rootsize=$ROOTSIZE \
|
|
|
|
--swapsize=$SWAPSIZE \
|
|
|
|
--tmpfs - \
|
|
|
|
--addpkg=openssh-server \
|
2011-09-16 22:22:23 +00:00
|
|
|
--raw=$TMPDISK \
|
2011-09-16 17:22:21 +00:00
|
|
|
|
2011-09-16 22:22:23 +00:00
|
|
|
if [ "$FORMAT" = "raw" ]; then
|
2011-09-16 17:22:21 +00:00
|
|
|
# Get image
|
2011-09-16 22:22:23 +00:00
|
|
|
mv $TMPDISK $RELEASE.$FORMAT
|
2011-09-16 17:22:21 +00:00
|
|
|
else
|
|
|
|
# Convert image
|
2011-09-16 22:22:23 +00:00
|
|
|
qemu-img convert -O $QFORMAT $TMPDISK $RELEASE.$FORMAT
|
|
|
|
rm $TMPDISK
|
2011-09-16 17:22:21 +00:00
|
|
|
fi
|
2011-09-16 22:22:23 +00:00
|
|
|
rm -rf ubuntu-$HYPER
|