From 2b7d221e6c7707a9973c8d32dd72f66fe7bb7ab7 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 19:37:56 -0700 Subject: [PATCH 01/10] switch to uec --- tools/build_libvirt.sh | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 07fd102..9860760 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -51,7 +51,7 @@ IMAGE_FNAME=$DIST_NAME.raw GUEST_NAME=${GUEST_NAME:-devstack} # Original version of built image -BASE_IMAGE=$WORK_DIR/images/$DIST_NAME.raw +BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw # Copy of base image, which we pre-install with tasty treats VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw @@ -69,12 +69,9 @@ mkdir -p $VM_DIR COPY_DIR=$VM_DIR/copy mkdir -p $COPY_DIR -# Create the base image if it does not yet exist -if [ ! -e $IMAGES_DIR/$IMAGE_FNAME ]; then - cd $TOOLS_DIR - ./make_image.sh -m -r 5000 $DIST_NAME raw - mv $DIST_NAME.raw $BASE_IMAGE - cd $TOP_DIR +# Get the base image if it does not yet exist +if [ ! -e $BASE_IMAGE ]; then + $TOOLS_DIR/get_uec_image.sh -f raw -r 5000 $DIST_NAME $BASE_IMAGE fi # Create a copy of the base image @@ -110,7 +107,8 @@ trap kill_unmount SIGINT DEST=${DEST:-/opt/stack} # Mount the file system -mount -o loop,offset=32256 $VM_IMAGE $COPY_DIR +# For some reason, UEC-based images want 255 heads * 63 sectors * 512 byte sectors = 8225280 +mount -t ext4 -o loop,offset=8225280 $VM_IMAGE $COPY_DIR # git clone only if directory doesn't exist already. Since ``DEST`` might not # 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 # Connect our nbd and wait till it is mountable qemu-nbd -c $NBD disk -NBD_DEV=`basename $NBD` -if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then +if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then echo "Couldn't connect $NBD" exit 1 fi # Mount the instance -mount $NBD $ROOTFS -o offset=32256 -t ext4 +mount ${NBD}p1 $ROOTFS # Configure instance network INTERFACES=$ROOTFS/etc/network/interfaces @@ -329,7 +326,7 @@ EOF chmod 755 $RUN_SH # Make runner launch on boot -RC_LOCAL=$ROOTFS/etc/init.d/local +RC_LOCAL=$ROOTFS/etc/init.d/zlocal cat > $RC_LOCAL <> $ROOTFS/$DEST/.bashrc @@ -350,6 +347,9 @@ echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS # Give stack ownership over $DEST so it may do the work needed chroot $ROOTFS chown -R stack $DEST +# GRUB 2 wants to see /dev +mount -o bind /dev $ROOTFS/dev + # Change boot params so that we get a console log sudo sed -e "s/quiet splash/splash console=ttyS0 console=ttyS1,19200n8/g" -i $ROOTFS/boot/grub/menu.lst sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst @@ -362,6 +362,22 @@ if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then echo "$GUEST_IP $GUEST_NAME" >> $ROOTFS/etc/hosts fi +# Change boot params so that we get a console log +G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` +sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub +sed -e 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass"/' -i $ROOTFS/etc/default/grub +sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub +echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub +echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub +echo "GRUB_DEVICE_UUID=$G_DEV_UUID" >>$ROOTFS/etc/default/grub + +chroot $ROOTFS update-grub +umount $ROOTFS/dev + +# Pre-generate ssh host keys and allow password login +chroot $ROOTFS dpkg-reconfigure openssh-server +sed -e 's/^PasswordAuthentication.*$/PasswordAuthentication yes/' -i $ROOTFS/etc/ssh/sshd_config + # Unmount umount $ROOTFS || echo 'ok' qemu-nbd -d $NBD From d6ee73f94ff7c83c900acf9a12507df5be3a2b82 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 19:40:38 -0700 Subject: [PATCH 02/10] blow up if CACHEDIR doesn't exist --- tools/get_uec_image.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/get_uec_image.sh b/tools/get_uec_image.sh index b903ad7..526fb44 100755 --- a/tools/get_uec_image.sh +++ b/tools/get_uec_image.sh @@ -94,7 +94,7 @@ NBD_DEV=`basename $NBD` # Get the UEC image UEC_NAME=$DIST_NAME-server-cloudimg-amd64 if [ ! -e $CACHEDIR/$UEC_NAME-disk1.img ]; then - (cd $CACHEDIR; wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img) + (cd $CACHEDIR && wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img) # Connect to nbd and wait till it is ready From b0559b2e4ded3015ee3267b39e2f55d5ac90bf01 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 19:46:54 -0700 Subject: [PATCH 03/10] having work_dir in here complicates jenkins --- tools/build_libvirt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 9860760..560e98f 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -20,7 +20,7 @@ TOOLS_DIR=$(cd $(dirname "$0") && pwd) TOP_DIR=`cd $TOOLS_DIR/..; pwd` # Where to store files and instances -WORK_DIR=${WORK_DIR:-$TOP_DIR/work} +WORK_DIR=${WORK_DIR:-/opt/kvmstack} # Where to store images IMAGES_DIR=$WORK_DIR/images @@ -272,7 +272,7 @@ EOF # User configuration for the instance chroot $ROOTFS groupadd libvirtd || true chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd -rsync -av --exclude=work $TOP_DIR $ROOTFS/$DEST/devstack +cp -pr $TOPDIR $ROOTFS/$DEST/devstack echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd echo "stack:pass" | chroot $ROOTFS chpasswd echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers From 5f894cd346f2339a47b43962e431a22c6b671980 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 19:52:50 -0700 Subject: [PATCH 04/10] typo --- tools/build_libvirt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 560e98f..f640957 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -272,7 +272,7 @@ EOF # User configuration for the instance chroot $ROOTFS groupadd libvirtd || true chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd -cp -pr $TOPDIR $ROOTFS/$DEST/devstack +cp -pr $TOP_DIR $ROOTFS/$DEST/devstack echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd echo "stack:pass" | chroot $ROOTFS chpasswd echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers From fd584eb6bbe55a173e50646598304598c5e0efc5 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 19:58:16 -0700 Subject: [PATCH 05/10] set hostname using uec kernel options --- tools/build_libvirt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index f640957..385edd1 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -365,7 +365,7 @@ fi # Change boot params so that we get a console log G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub -sed -e 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass"/' -i $ROOTFS/etc/default/grub +sed -e 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass h=$GUEST_NAME"/' -i $ROOTFS/etc/default/grub sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub From 7e4a33bc6bd87988ccd2bb936e374516050565ee Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 20:02:03 -0700 Subject: [PATCH 06/10] another attemp at setting guest name --- tools/build_libvirt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 385edd1..a90504c 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -365,7 +365,7 @@ fi # Change boot params so that we get a console log G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub -sed -e 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass h=$GUEST_NAME"/' -i $ROOTFS/etc/default/grub +sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass h=$GUEST_NAME\",g" -i $ROOTFS/etc/default/grub sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub From 932649fac38186c3673833272b7e78cd37467a6a Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 20:30:39 -0700 Subject: [PATCH 07/10] proper way of setting hostname using uec kernel params --- tools/build_libvirt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index a90504c..39b759f 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -365,7 +365,7 @@ fi # Change boot params so that we get a console log G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub -sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass h=$GUEST_NAME\",g" -i $ROOTFS/etc/default/grub +sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud;h=$GUEST_NAME ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub From ed8aa54909ffd7295d58bbe9072c3d657e03b956 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 20:34:44 -0700 Subject: [PATCH 08/10] try ds=nocloud-net;h=foo --- tools/build_libvirt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 39b759f..e75f874 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -365,7 +365,7 @@ fi # Change boot params so that we get a console log G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub -sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud;h=$GUEST_NAME ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub +sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud-net;h=$GUEST_NAME ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub From 2c5201b461229d199846a6af3b12c5ae5de62f01 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 20:44:26 -0700 Subject: [PATCH 09/10] can't figure out cloudinit --- tools/build_libvirt.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index e75f874..91b15ab 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -356,6 +356,7 @@ sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst # Set the hostname echo $GUEST_NAME > $ROOTFS/etc/hostname +echo $GUEST_NAME > $ROOTFS/etc/hostname1 # We need the hostname to resolve for rabbit to launch if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then @@ -365,7 +366,7 @@ fi # Change boot params so that we get a console log G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub -sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud-net;h=$GUEST_NAME ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub +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 sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub From ddcc36d445c1dafecd6e752554e7112df8b1a9f6 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sun, 30 Oct 2011 22:41:23 -0700 Subject: [PATCH 10/10] try to overwrite the overwrite --- tools/build_libvirt.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/build_libvirt.sh b/tools/build_libvirt.sh index 91b15ab..0564584 100755 --- a/tools/build_libvirt.sh +++ b/tools/build_libvirt.sh @@ -335,6 +335,9 @@ if [ ! -e /root/firstlaunch ]; then reboot -f exit 0 fi +# cloud-init overwrites the hostname with ubuntuhost +echo $GUEST_NAME > /etc/hostname +hostname $GUEST_NAME su -c "$DEST/run.sh" stack EOF chmod +x $RC_LOCAL @@ -356,7 +359,6 @@ sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst # Set the hostname echo $GUEST_NAME > $ROOTFS/etc/hostname -echo $GUEST_NAME > $ROOTFS/etc/hostname1 # We need the hostname to resolve for rabbit to launch if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then