work towards booting
This commit is contained in:
parent
8b3eb5ffe3
commit
228f246a83
1 changed files with 37 additions and 32 deletions
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Make sure that we have the proper version of ubuntu
|
# Ubuntu distro to install
|
||||||
|
DIST_NAME=${DIST_NAME:-oneiric}
|
||||||
|
|
||||||
|
# Make sure that we have the proper version of ubuntu (only works on natty/oneiric)
|
||||||
UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
|
UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
|
||||||
if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
|
if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
|
||||||
if [ ! "natty" = "$UBUNTU_VERSION" ]; then
|
if [ ! "natty" = "$UBUNTU_VERSION" ]; then
|
||||||
|
@ -9,13 +12,14 @@ if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# exit on error to stop unexpected errors
|
|
||||||
set -o errexit
|
|
||||||
|
|
||||||
# Keep track of the current directory
|
# Keep track of the current directory
|
||||||
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
|
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
|
||||||
TOP_DIR=`cd $TOOLS_DIR/..; pwd`
|
TOP_DIR=`cd $TOOLS_DIR/..; pwd`
|
||||||
|
|
||||||
|
# exit on error to stop unexpected errors
|
||||||
|
set -o errexit
|
||||||
|
set -o xtrace
|
||||||
|
|
||||||
# Abort if localrc is not set
|
# Abort if localrc is not set
|
||||||
if [ ! -e $TOP_DIR/localrc ]; then
|
if [ ! -e $TOP_DIR/localrc ]; then
|
||||||
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
|
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
|
||||||
WORK_DIR=${WORK_DIR:-/opt/kvmstack}
|
WORK_DIR=${WORK_DIR:-/opt/kvmstack}
|
||||||
|
|
||||||
# Where to store images
|
# Where to store images
|
||||||
IMAGES_DIR=$WORK_DIR/images
|
image_dir=$WORK_DIR/images/$DIST_NAME
|
||||||
|
mkdir -p $image_dir
|
||||||
|
|
||||||
# Original version of built image
|
# Original version of built image
|
||||||
DIST_NAME=${DIST_NAME:oneiric}
|
uec_url=http://uec-images.ubuntu.com/$DIST_NAME/current/$DIST_NAME-server-cloudimg-amd64.tar.gz
|
||||||
UEC_NAME=$DIST_NAME-server-cloudimg-amd64
|
tarball=$image_dir/$(basename $UEC_URL)
|
||||||
UEC_URL=http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img
|
|
||||||
BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw
|
|
||||||
|
|
||||||
# download the base uec image if we haven't already
|
# download the base uec image if we haven't already
|
||||||
if [ ! -e $BASE_IMAGE ]; then
|
if [ ! -f $tarball ]; then
|
||||||
mkdir -p $IMAGES_DIR
|
curl $uec_url -o $tarball
|
||||||
curl $UEC_URL -O $BASE_IMAGE
|
tar -Sxvzf $tarball $image_dir
|
||||||
|
cp $image_dir/*.img $image_dir/disk
|
||||||
|
cp $image_dir/*-vmlinuz-virtual $image_dir/kernel
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $TOP_DIR
|
cd $TOP_DIR
|
||||||
|
@ -59,14 +64,16 @@ GUEST_NAME=${GUEST_NAME:-devstack}
|
||||||
virsh destroy $GUEST_NAME || true
|
virsh destroy $GUEST_NAME || true
|
||||||
|
|
||||||
# Where this vm is stored
|
# Where this vm is stored
|
||||||
VM_DIR=$WORK_DIR/instances/$GUEST_NAME
|
vm_dir=$WORK_DIR/instances/$GUEST_NAME
|
||||||
|
|
||||||
# Create vm dir and remove old disk
|
# Create vm dir and remove old disk
|
||||||
mkdir -p $VM_DIR
|
mkdir -p $vm_dir
|
||||||
rm -f $VM_DIR/disk.img
|
rm -f $vm_dir/disk
|
||||||
|
|
||||||
# Create a copy of the base image
|
# Create a copy of the base image
|
||||||
qemu-img create -f qcow2 -b ${BASE_IMAGE} $VM_DIR/disk.img
|
# qemu-img create -f qcow2 -b ${BASE_IMAGE} $vm_dir/disk
|
||||||
|
cp $image_dir/disk $vm_dir/disk
|
||||||
|
cp $image_dir/kernel $vm_dir/kernel
|
||||||
|
|
||||||
# Back to devstack
|
# Back to devstack
|
||||||
cd $TOP_DIR
|
cd $TOP_DIR
|
||||||
|
@ -82,7 +89,7 @@ GUEST_RAM=${GUEST_RAM:-1524288}
|
||||||
GUEST_CORES=${GUEST_CORES:-1}
|
GUEST_CORES=${GUEST_CORES:-1}
|
||||||
|
|
||||||
# libvirt.xml configuration
|
# libvirt.xml configuration
|
||||||
NET_XML=$VM_DIR/net.xml
|
NET_XML=$vm_dir/net.xml
|
||||||
cat > $NET_XML <<EOF
|
cat > $NET_XML <<EOF
|
||||||
<network>
|
<network>
|
||||||
<name>devstack-$GUEST_NETWORK</name>
|
<name>devstack-$GUEST_NETWORK</name>
|
||||||
|
@ -94,20 +101,19 @@ EOF
|
||||||
|
|
||||||
if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then
|
if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then
|
||||||
virsh net-destroy devstack-$GUEST_NETWORK || true
|
virsh net-destroy devstack-$GUEST_NETWORK || true
|
||||||
virsh net-create $VM_DIR/net.xml
|
virsh net-create $vm_dir/net.xml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# libvirt.xml configuration
|
# libvirt.xml configuration
|
||||||
LIBVIRT_XML=$VM_DIR/libvirt.xml
|
LIBVIRT_XML=$vm_dir/libvirt.xml
|
||||||
cat > $LIBVIRT_XML <<EOF
|
cat > $LIBVIRT_XML <<EOF
|
||||||
<domain type='kvm'>
|
<domain type='kvm'>
|
||||||
<name>$GUEST_NAME</name>
|
<name>$GUEST_NAME</name>
|
||||||
<memory>$GUEST_RAM</memory>
|
<memory>$GUEST_RAM</memory>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc'>hvm</type>
|
<type>hvm</type>
|
||||||
<boot dev='hd'/>
|
<kernel>$vm_dir/kernel</kernel>
|
||||||
<kernel>$VM_DIR/kernel</kernel>
|
<cmdline>root=/dev/vda console=ttyS0 init=/usr/lib/cloud-init/uncloud-init ds=nocloud ubuntu-pass=ubuntu</cmdline>
|
||||||
<cmdline>root=/dev/vda ro init=/usr/lib/cloud-init/uncloud-init ds=nocloud ubuntu-pass=ubuntu</cmdline>
|
|
||||||
</os>
|
</os>
|
||||||
<features>
|
<features>
|
||||||
<acpi/>
|
<acpi/>
|
||||||
|
@ -117,7 +123,7 @@ cat > $LIBVIRT_XML <<EOF
|
||||||
<devices>
|
<devices>
|
||||||
<disk type='file'>
|
<disk type='file'>
|
||||||
<driver type='qcow2'/>
|
<driver type='qcow2'/>
|
||||||
<source file='$VM_DIR/disk.img'/>
|
<source file='$vm_dir/disk'/>
|
||||||
<target dev='vda' bus='virtio'/>
|
<target dev='vda' bus='virtio'/>
|
||||||
</disk>
|
</disk>
|
||||||
|
|
||||||
|
@ -127,7 +133,7 @@ cat > $LIBVIRT_XML <<EOF
|
||||||
|
|
||||||
<!-- The order is significant here. File must be defined first -->
|
<!-- The order is significant here. File must be defined first -->
|
||||||
<serial type="file">
|
<serial type="file">
|
||||||
<source path='$VM_DIR/console.log'/>
|
<source path='$vm_dir/console.log'/>
|
||||||
<target port='1'/>
|
<target port='1'/>
|
||||||
</serial>
|
</serial>
|
||||||
|
|
||||||
|
@ -147,11 +153,12 @@ cat > $LIBVIRT_XML <<EOF
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Create the instance
|
# Create the instance
|
||||||
cd $VM_DIR && virsh create libvirt.xml
|
cd $vm_dir && virsh create libvirt.xml
|
||||||
|
|
||||||
# Tail the console log till we are done
|
# Tail the console log till we are done
|
||||||
WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
|
WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
|
||||||
if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||||
|
set +o xtrace
|
||||||
# Done creating the container, let's tail the log
|
# Done creating the container, let's tail the log
|
||||||
echo
|
echo
|
||||||
echo "============================================================="
|
echo "============================================================="
|
||||||
|
@ -163,11 +170,11 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||||
echo
|
echo
|
||||||
echo "Just CTRL-C at any time to stop tailing."
|
echo "Just CTRL-C at any time to stop tailing."
|
||||||
|
|
||||||
while [ ! -e "$VM_DIR/console.log" ]; do
|
while [ ! -e "$vm_dir/console.log" ]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
tail -F $VM_DIR/console.log &
|
tail -F $vm_dir/console.log &
|
||||||
|
|
||||||
TAIL_PID=$!
|
TAIL_PID=$!
|
||||||
|
|
||||||
|
@ -179,10 +186,8 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||||
# Let Ctrl-c kill tail and exit
|
# Let Ctrl-c kill tail and exit
|
||||||
trap kill_tail SIGINT
|
trap kill_tail SIGINT
|
||||||
|
|
||||||
set +o xtrace
|
|
||||||
|
|
||||||
echo "Waiting stack.sh to finish..."
|
echo "Waiting stack.sh to finish..."
|
||||||
while ! cat $VM_DIR/console.log | grep -q 'All done' ; do
|
while ! cat $vm_dir/console.log | grep -q 'All done' ; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -190,7 +195,7 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||||
|
|
||||||
kill $TAIL_PID
|
kill $TAIL_PID
|
||||||
|
|
||||||
if ! grep -q "^stack.sh completed in" $VM_DIR/console.log; then
|
if ! grep -q "^stack.sh completed in" $vm_dir/console.log; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in a new issue