Thursday, July 11, 2013

Installing Ubuntu Precise Server On A Xen Server Hypervisor

Recently, I had to install a vm on a xenserver hypervisor which I had locally. I intended to use this vm as a platform for my devstack setup with xenserver.

Along the way, I had to tweak lot of parameters in the VM to get this working. So, I thought of scripting this entire process out. Here is the script I used.

#!/bin/bash
if [ $# -ne 2 ]; then
   echo "Usage: $0 <vm-name-label> <ram-size-in-bytes>"
   exit
fi

#Create ubuntu precise template if does not exist

TEMPLATE_EXISTS=`xe template-list name-label="Ubuntu Precise (64-bit)" params=uuid --minimal`

if [ "$TEMPLATE_EXISTS" == "" ]; then

    TEMPLATE_UUID=`xe template-list \
            name-label="Ubuntu Lucid Lynx 10.04 (64-bit)" params=uuid --minimal`
    NEW_TEMPLATE_UUID=`xe vm-clone uuid=$TEMPLATE_UUID \
            new-name-label="Ubuntu Precise (64-bit)"`
    xe template-param-set other-config:default_template=true \
            other-config:debian-release=precise uuid=$NEW_TEMPLATE_UUID

fi

#Create a VM with the new template

VM_UUID=`xe vm-install new-name-label="$1" template="Ubuntu Precise (64-bit)"`

#Create network interfaces for this VM

XEN_NET_UUID=`xe network-list params=uuid bridge=xenbr0 --minimal`
xe vif-create network-uuid=${XEN_NET_UUID} vm-uuid=${VM_UUID} device=0
xe vm-param-set other-config:install-repository="http://archive.ubuntu.com/ubuntu/ubuntu/" uuid=${VM_UUID}
xe vm-param-set other-config:disable_pv_vnc=true uuid=${VM_UUID}
xe vm-memory-limits-set dynamic-max=$2 dynamic-min=$2 static-max=$2 static-min=$2 uuid=${VM_UUID}

echo "Starting VM with uuid ${VM_UUID}"
xe vm-start uuid=${VM_UUID}

No comments:

Post a Comment