Archive for the ‘XEN’ Category
Create XEN virtual server script (includes configuration file fix). January 6th, 2009
Here is a simple Linux bash script that I wrote in other to save time when creating and configuring virtual servers in my XEN server. You just have to provide it with the basic configuration information and you will be good to go.
xen_createvm.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #!/bin/sh echo "XEN CREATEVM SCRIPT v1.00" echo "by www.programmoholicsanonymous.org.\n" echo "Usage: xen_createvm hostname ipaddress RAMMB\n" echo "Where:" echo " hostname = Hostname without domain." echo " ipaddress = IP address Last octect alone." echo " RAMMB = RAM memory amount in MB." echo " Notes:" echo " - SWAP gets calculated automatically assuming that SWAP=RAM*2." echo " - Network mask and domain are stored in .source files.\n" # VARIABLEDECLARATIONS RAMSIZE=$3"Mb" SWAPSIZE=$(($3*2))"Mb" DOMAIN=`cat xen_createvm.domain.source` NETWORK=`cat xen_createvm.network.source` HSTNAME=$1.$DOMAIN HDDSIZE="5Gb" IPADDRESS=$NETWORK.$2 CNFFILE="/etc/xen/"$HSTNAME".cfg" CNFTEMP="/etc/xen/"$HSTNAME".new" KERNELIMAGE="vmlinuz-2.6.24-19-xen" IMAGE="initrd.img-2.6.24-19-xen" DOMAINPATH="/home/xen" VMARCH="i386" DISTRO="hardy" DISTROMIRROR="http://archive.ubuntu.com/ubuntu/" echo "(!) Creating vm $HSTNAME ($IPADDRESS)..." # CREATE VM xen-create-image --hostname=$HSTNAME --size=$HDDSIZE --swap=$SWAPSIZE --ide --ip=$IPADDRESS --netmask=255.255.255.0 --gateway=$NETWORK.1 --force \ --dir=$DOMAINPATH --memory=$3 --arch=$VMARCH --kernel=/boot/$KERNELIMAGE --initrd=/boot/$IMAGE --install-method=debootstrap --dist=$DISTRO \ --mirror=$DISTROMIRROR --passwd echo "\n" echo "(!) Fixing Config File Paramters...\n" # FIX WRONG HDD COMMAND "FILE:" "IO:TAP" sed 's/file:/tap:aio:/' $CNFFILE > $CNFTEMP rm $CNFFILE mv $CNFTEMP $CNFFILE echo "(!) Starting vm $HSTNAME ($IPADDRESS)..." # START VM xm create $CNFFILE |
For some unknown reason the config file gets generated with a wrong statement that needs to be fixed in order for the vm to work properly. I took care of it (Line 45) so you do not have to do it manually but bear that in mind in case you will not use this script when creating your vms.
In order for it to work you should create two files xen_createvm.domain.source and xen_createvm.network.source. These files will contain the common configuration information for all your vms.
xen_createvm.domain.source (Example)
yourDomain.local
xen_createvm.network.source (Example)
192.168.1.
Well that’s it. Feel free to modify it and make it better. If you do so, please post the new version and share it with others.
Enjoy it.
Tags: Linux, Shell Scripts, Ubuntu, Virtualization, XEN
Posted in Linux, Ubuntu, Virtualization, XEN | Comments (0)