blob: 28b2eac23d82153b0aae6baee0ba474f70e6537f [file] [log] [blame]
Dean Troyer65cf6082011-09-16 12:22:21 -05001#!/bin/bash
2# make_image.sh - Create Ubuntu images in various formats
3#
4# make_image.sh release format
5#
6# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
7#
8# Requires sudo to root
9
10ROOTSIZE=${ROOTSIZE:-8192}
11SWAPSIZE=${SWAPSIZE:-1024}
12
13usage() {
14 echo "$0 - Create Ubuntu images"
15 echo ""
16 echo "$0 [-r rootsize] [-s swapsize] release format"
17 exit 1
18}
19
20while getopts hm:r:s: c; do
21 case $c in
Dean Troyer4dd420e2011-09-16 16:16:34 -050022 h) usage
23 ;;
24 m) MIRROR=$OPTARG
25 ;;
26 r) ROOTSIZE=$OPTARG
27 ;;
28 s) SWAPSIZE=$OPTARG
29 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050030 esac
31done
32shift `expr $OPTIND - 1`
33
34RELEASE=$1
35FORMAT=$2
36
Dean Troyer4dd420e2011-09-16 16:16:34 -050037case $FORMAT in
38 kvm|qcow2) FORMAT=qcow2
39 TARGET=kvm
40 ;;
41 vmserver|vmdk)
42 FORMAT=vmdk
43 TARGET=vmserver
44 ;;
45 vbox|vdi) FORMAT=qcow2
46 TARGET=kvm
47 FINAL_FORMAT=vdi
48 ;;
49 vhd|vpc) FORMAT=qcow2
50 TARGET=kvm
51 FINAL_FORMAT=vhd
52 ;;
53 xen) FORMAT=raw
54 TARGET=xen
55 ;;
56 *) echo "Unknown format: $FORMAT"
57 usage
Dean Troyer65cf6082011-09-16 12:22:21 -050058esac
59
Dean Troyer4dd420e2011-09-16 16:16:34 -050060case $RELEASE in
61 natty) ;;
62 maverick) ;;
63 lucid) ;;
64 karmic) ;;
65 jaunty) ;;
66 *) echo "Unknown release: $RELEASE"
67 usage
68 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050069esac
70
71# Install stuff if necessary
72if [ -z `which vmbuilder` ]; then
Dean Troyer4dd420e2011-09-16 16:16:34 -050073 sudo apt-get install ubuntu-vm-builder
Dean Troyer65cf6082011-09-16 12:22:21 -050074fi
75
76# Build the image
77sudo vmbuilder $TARGET ubuntu --suite $RELEASE \
78 -o \
79 --rootsize=$ROOTSIZE \
80 --swapsize=$SWAPSIZE \
81 --tmpfs - \
82 --addpkg=openssh-server \
83
84# --mirror=$MIRROR \
85
86if [ -z "$FINAL_FORMAT" ]; then
87 # Get image
88 mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT
89else
90 # Convert image
Dean Troyer4dd420e2011-09-16 16:16:34 -050091 tgt=$FINAL_FORMAT
92 if [ "$tgt" = "vhd" ]; then
93 tgt=vpc
94 fi
95 qemu-img convert -O $tgt ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT
Dean Troyer65cf6082011-09-16 12:22:21 -050096fi
97rm -rf ubuntu-$TARGET