Browse code

work towards booting

Jesse Andrews authored on 2011/11/06 09:36:14
Showing 1 changed files
... ...
@@ -1,6 +1,9 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-# Make sure that we have the proper version of ubuntu
3
+# Ubuntu distro to install
4
+DIST_NAME=${DIST_NAME:-oneiric}
5
+
6
+# Make sure that we have the proper version of ubuntu (only works on natty/oneiric)
4 7
 UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
5 8
 if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
6 9
     if [ ! "natty" = "$UBUNTU_VERSION" ]; then
... ...
@@ -9,13 +12,14 @@ if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
9 9
     fi
10 10
 fi
11 11
 
12
-# exit on error to stop unexpected errors
13
-set -o errexit
14
-
15 12
 # Keep track of the current directory
16 13
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
17 14
 TOP_DIR=`cd $TOOLS_DIR/..; pwd`
18 15
 
16
+# exit on error to stop unexpected errors
17
+set -o errexit
18
+set -o xtrace
19
+
19 20
 # Abort if localrc is not set
20 21
 if [ ! -e $TOP_DIR/localrc ]; then
21 22
     echo "You must have a localrc with ALL necessary passwords defined before proceeding."
... ...
@@ -30,18 +34,19 @@ dpkg -l kvm libvirt-bin kpartx || apt-get install -y --force-yes kvm libvirt-bin
30 30
 WORK_DIR=${WORK_DIR:-/opt/kvmstack}
31 31
 
32 32
 # Where to store images
33
-IMAGES_DIR=$WORK_DIR/images
33
+image_dir=$WORK_DIR/images/$DIST_NAME
34
+mkdir -p $image_dir
34 35
 
35 36
 # Original version of built image
36
-DIST_NAME=${DIST_NAME:oneiric}
37
-UEC_NAME=$DIST_NAME-server-cloudimg-amd64
38
-UEC_URL=http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img
39
-BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw
37
+uec_url=http://uec-images.ubuntu.com/$DIST_NAME/current/$DIST_NAME-server-cloudimg-amd64.tar.gz
38
+tarball=$image_dir/$(basename $UEC_URL)
40 39
 
41 40
 # download the base uec image if we haven't already
42
-if [ ! -e $BASE_IMAGE ]; then
43
-    mkdir -p $IMAGES_DIR
44
-    curl $UEC_URL -O $BASE_IMAGE
41
+if [ ! -f $tarball ]; then
42
+    curl $uec_url -o $tarball
43
+    tar -Sxvzf $tarball $image_dir
44
+    cp $image_dir/*.img $image_dir/disk
45
+    cp $image_dir/*-vmlinuz-virtual $image_dir/kernel
45 46
 fi
46 47
 
47 48
 cd $TOP_DIR
... ...
@@ -59,14 +64,16 @@ GUEST_NAME=${GUEST_NAME:-devstack}
59 59
 virsh destroy $GUEST_NAME || true
60 60
 
61 61
 # Where this vm is stored
62
-VM_DIR=$WORK_DIR/instances/$GUEST_NAME
62
+vm_dir=$WORK_DIR/instances/$GUEST_NAME
63 63
 
64 64
 # Create vm dir and remove old disk
65
-mkdir -p $VM_DIR
66
-rm -f $VM_DIR/disk.img
65
+mkdir -p $vm_dir
66
+rm -f $vm_dir/disk
67 67
 
68 68
 # Create a copy of the base image
69
-qemu-img create -f qcow2 -b ${BASE_IMAGE} $VM_DIR/disk.img
69
+# qemu-img create -f qcow2 -b ${BASE_IMAGE} $vm_dir/disk
70
+cp $image_dir/disk $vm_dir/disk
71
+cp $image_dir/kernel $vm_dir/kernel
70 72
 
71 73
 # Back to devstack
72 74
 cd $TOP_DIR
... ...
@@ -82,7 +89,7 @@ GUEST_RAM=${GUEST_RAM:-1524288}
82 82
 GUEST_CORES=${GUEST_CORES:-1}
83 83
 
84 84
 # libvirt.xml configuration
85
-NET_XML=$VM_DIR/net.xml
85
+NET_XML=$vm_dir/net.xml
86 86
 cat > $NET_XML <<EOF
87 87
 <network>
88 88
   <name>devstack-$GUEST_NETWORK</name>
... ...
@@ -94,20 +101,19 @@ EOF
94 94
 
95 95
 if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then
96 96
     virsh net-destroy devstack-$GUEST_NETWORK || true
97
-    virsh net-create $VM_DIR/net.xml
97
+    virsh net-create $vm_dir/net.xml
98 98
 fi
99 99
 
100 100
 # libvirt.xml configuration
101
-LIBVIRT_XML=$VM_DIR/libvirt.xml
101
+LIBVIRT_XML=$vm_dir/libvirt.xml
102 102
 cat > $LIBVIRT_XML <<EOF
103 103
 <domain type='kvm'>
104 104
   <name>$GUEST_NAME</name>
105 105
   <memory>$GUEST_RAM</memory>
106 106
   <os>
107
-    <type arch='i686' machine='pc'>hvm</type>
108
-    <boot dev='hd'/>
109
-    <kernel>$VM_DIR/kernel</kernel>
110
-    <cmdline>root=/dev/vda ro init=/usr/lib/cloud-init/uncloud-init ds=nocloud ubuntu-pass=ubuntu</cmdline>
107
+    <type>hvm</type>
108
+    <kernel>$vm_dir/kernel</kernel>
109
+    <cmdline>root=/dev/vda console=ttyS0 init=/usr/lib/cloud-init/uncloud-init ds=nocloud ubuntu-pass=ubuntu</cmdline>
111 110
   </os>
112 111
   <features>
113 112
     <acpi/>
... ...
@@ -117,7 +123,7 @@ cat > $LIBVIRT_XML <<EOF
117 117
   <devices>
118 118
     <disk type='file'>
119 119
       <driver type='qcow2'/>
120
-      <source file='$VM_DIR/disk.img'/>
120
+      <source file='$vm_dir/disk'/>
121 121
       <target dev='vda' bus='virtio'/>
122 122
     </disk>
123 123
 
... ...
@@ -127,7 +133,7 @@ cat > $LIBVIRT_XML <<EOF
127 127
         
128 128
     <!-- The order is significant here.  File must be defined first -->
129 129
     <serial type="file">
130
-      <source path='$VM_DIR/console.log'/>
130
+      <source path='$vm_dir/console.log'/>
131 131
       <target port='1'/>
132 132
     </serial>
133 133
 
... ...
@@ -147,11 +153,12 @@ cat > $LIBVIRT_XML <<EOF
147 147
 EOF
148 148
 
149 149
 # Create the instance
150
-cd $VM_DIR && virsh create libvirt.xml
150
+cd $vm_dir && virsh create libvirt.xml
151 151
 
152 152
 # Tail the console log till we are done
153 153
 WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
154 154
 if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
155
+    set +o xtrace
155 156
     # Done creating the container, let's tail the log
156 157
     echo
157 158
     echo "============================================================="
... ...
@@ -163,11 +170,11 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
163 163
     echo
164 164
     echo "Just CTRL-C at any time to stop tailing."
165 165
 
166
-    while [ ! -e "$VM_DIR/console.log" ]; do
166
+    while [ ! -e "$vm_dir/console.log" ]; do
167 167
       sleep 1
168 168
     done
169 169
 
170
-    tail -F $VM_DIR/console.log &
170
+    tail -F $vm_dir/console.log &
171 171
 
172 172
     TAIL_PID=$!
173 173
 
... ...
@@ -179,10 +186,8 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
179 179
     # Let Ctrl-c kill tail and exit
180 180
     trap kill_tail SIGINT
181 181
 
182
-    set +o xtrace
183
-
184 182
     echo "Waiting stack.sh to finish..."
185
-    while ! cat $VM_DIR/console.log | grep -q 'All done' ; do
183
+    while ! cat $vm_dir/console.log | grep -q 'All done' ; do
186 184
         sleep 1
187 185
     done
188 186
 
... ...
@@ -190,7 +195,7 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
190 190
 
191 191
     kill $TAIL_PID
192 192
 
193
-    if ! grep -q "^stack.sh completed in" $VM_DIR/console.log; then
193
+    if ! grep -q "^stack.sh completed in" $vm_dir/console.log; then
194 194
         exit 1
195 195
     fi
196 196
     echo ""