Browse code

Merge branch 'libvirt'

Jesse Andrews authored on 2011/10/31 14:48:42
Showing 2 changed files
... ...
@@ -20,7 +20,7 @@ TOOLS_DIR=$(cd $(dirname "$0") && pwd)
20 20
 TOP_DIR=`cd $TOOLS_DIR/..; pwd`
21 21
 
22 22
 # Where to store files and instances
23
-WORK_DIR=${WORK_DIR:-$TOP_DIR/work}
23
+WORK_DIR=${WORK_DIR:-/opt/kvmstack}
24 24
 
25 25
 # Where to store images
26 26
 IMAGES_DIR=$WORK_DIR/images
... ...
@@ -51,7 +51,7 @@ IMAGE_FNAME=$DIST_NAME.raw
51 51
 GUEST_NAME=${GUEST_NAME:-devstack}
52 52
 
53 53
 # Original version of built image
54
-BASE_IMAGE=$WORK_DIR/images/$DIST_NAME.raw
54
+BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw
55 55
 
56 56
 # Copy of base image, which we pre-install with tasty treats
57 57
 VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw
... ...
@@ -69,12 +69,9 @@ mkdir -p $VM_DIR
69 69
 COPY_DIR=$VM_DIR/copy
70 70
 mkdir -p $COPY_DIR
71 71
 
72
-# Create the base image if it does not yet exist
73
-if [ ! -e $IMAGES_DIR/$IMAGE_FNAME ]; then
74
-    cd $TOOLS_DIR
75
-    ./make_image.sh -m -r 5000  $DIST_NAME raw
76
-    mv $DIST_NAME.raw $BASE_IMAGE
77
-    cd $TOP_DIR
72
+# Get the base image if it does not yet exist
73
+if [ ! -e $BASE_IMAGE ]; then
74
+    $TOOLS_DIR/get_uec_image.sh -f raw -r 5000 $DIST_NAME $BASE_IMAGE
78 75
 fi
79 76
 
80 77
 # Create a copy of the base image
... ...
@@ -110,7 +107,8 @@ trap kill_unmount SIGINT
110 110
 DEST=${DEST:-/opt/stack}
111 111
 
112 112
 # Mount the file system
113
-mount -o loop,offset=32256 $VM_IMAGE  $COPY_DIR
113
+# For some reason, UEC-based images want 255 heads * 63 sectors * 512 byte sectors = 8225280
114
+mount -t ext4 -o loop,offset=8225280 $VM_IMAGE $COPY_DIR
114 115
 
115 116
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
116 117
 # be owned by the installation user, we create the directory and change the
... ...
@@ -250,14 +248,13 @@ qemu-img create -f qcow2 -b $VM_IMAGE disk
250 250
 
251 251
 # Connect our nbd and wait till it is mountable
252 252
 qemu-nbd -c $NBD disk
253
-NBD_DEV=`basename $NBD`
254
-if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
253
+if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
255 254
     echo "Couldn't connect $NBD"
256 255
     exit 1
257 256
 fi
258 257
 
259 258
 # Mount the instance
260
-mount $NBD $ROOTFS -o offset=32256 -t ext4
259
+mount ${NBD}p1 $ROOTFS
261 260
 
262 261
 # Configure instance network
263 262
 INTERFACES=$ROOTFS/etc/network/interfaces
... ...
@@ -275,7 +272,7 @@ EOF
275 275
 # User configuration for the instance
276 276
 chroot $ROOTFS groupadd libvirtd || true
277 277
 chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
278
-rsync -av --exclude=work $TOP_DIR $ROOTFS/$DEST/devstack
278
+cp -pr $TOP_DIR $ROOTFS/$DEST/devstack
279 279
 echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd
280 280
 echo "stack:pass" | chroot $ROOTFS chpasswd
281 281
 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
... ...
@@ -329,7 +326,7 @@ EOF
329 329
 chmod 755 $RUN_SH
330 330
 
331 331
 # Make runner launch on boot
332
-RC_LOCAL=$ROOTFS/etc/init.d/local
332
+RC_LOCAL=$ROOTFS/etc/init.d/zlocal
333 333
 cat > $RC_LOCAL <<EOF
334 334
 #!/bin/sh -e
335 335
 # Reboot if this is our first run to enable console log on $DIST_NAME :(
... ...
@@ -338,10 +335,13 @@ if [ ! -e /root/firstlaunch ]; then
338 338
     reboot -f
339 339
     exit 0
340 340
 fi
341
+# cloud-init overwrites the hostname with ubuntuhost
342
+echo $GUEST_NAME > /etc/hostname
343
+hostname $GUEST_NAME
341 344
 su -c "$DEST/run.sh" stack
342 345
 EOF
343 346
 chmod +x $RC_LOCAL
344
-chroot $ROOTFS sudo update-rc.d local defaults 80
347
+chroot $ROOTFS sudo update-rc.d zlocal defaults 99
345 348
 
346 349
 # Make our ip address hostnames look nice at the command prompt
347 350
 echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc
... ...
@@ -350,6 +350,9 @@ echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS
350 350
 # Give stack ownership over $DEST so it may do the work needed
351 351
 chroot $ROOTFS chown -R stack $DEST
352 352
 
353
+# GRUB 2 wants to see /dev
354
+mount -o bind /dev $ROOTFS/dev
355
+
353 356
 # Change boot params so that we get a console log
354 357
 sudo sed -e "s/quiet splash/splash console=ttyS0 console=ttyS1,19200n8/g" -i $ROOTFS/boot/grub/menu.lst
355 358
 sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst
... ...
@@ -362,6 +365,22 @@ if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then
362 362
     echo "$GUEST_IP $GUEST_NAME" >> $ROOTFS/etc/hosts
363 363
 fi
364 364
 
365
+# Change boot params so that we get a console log
366
+G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1`
367
+sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub
368
+sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub
369
+sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub
370
+echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub
371
+echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub
372
+echo "GRUB_DEVICE_UUID=$G_DEV_UUID" >>$ROOTFS/etc/default/grub
373
+
374
+chroot $ROOTFS update-grub
375
+umount $ROOTFS/dev
376
+
377
+# Pre-generate ssh host keys and allow password login
378
+chroot $ROOTFS dpkg-reconfigure openssh-server
379
+sed -e 's/^PasswordAuthentication.*$/PasswordAuthentication yes/' -i $ROOTFS/etc/ssh/sshd_config
380
+
365 381
 # Unmount
366 382
 umount $ROOTFS || echo 'ok'
367 383
 qemu-nbd -d $NBD
... ...
@@ -94,7 +94,7 @@ NBD_DEV=`basename $NBD`
94 94
 # Get the UEC image
95 95
 UEC_NAME=$DIST_NAME-server-cloudimg-amd64
96 96
 if [ ! -e $CACHEDIR/$UEC_NAME-disk1.img ]; then
97
-    (cd $CACHEDIR; wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img)
97
+    (cd $CACHEDIR && wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img)
98 98
 
99 99
 
100 100
     # Connect to nbd and wait till it is ready