Xen - Disk based Dom-U Cloning
Heres a quick little script for automating the creation of Dom-U’s and there corresponding configuration files. Nothing to fancy, but it helps for users who may be unfamiliar with the process or just need to fire up a new Dom-U quickly without going thru an installation process.
This script assumes that when you first build a Dom-U either by d’bootstrapping or windows installation or whatever it may be, you shut the Dom-U down and move the “template” to /home/xen/templates and that your running Dom-U’s are running from /home/xen/domains . Lastly make sure the template configuration file has the <> strings so sed can replace them with your intended variables. This can be extended as you see fit, if you need to change values for networking, kernel, etc… Happy cloning.
./clone.sh
#!/bin/bash function syntax { echo "Syntax: ./clone.sh source_image destination_image memory(mb)" echo " where source_image is the name of the directory in this folder " echo " destination_image is the name of your new DomU " echo " and memory(mb) is the ammount of memory you want to provision ." echo "" echo "Example: ./clone.sh debian_etch_x86 v-debian-etch-x 512" echo "Example: ./clone.sh winxp_pro_x86 v-winxp-pro-x 512" } if [ $1 ]; then if [ $2 ]; then if [ $3 ]; then echo "Cloning Template $1 to DomU $2 with $3 MB of memor y." echo "Copyig Disk Images... This will take a few minutes ..." cp -R /home/xen/templates/$1 /home/xen/domains/$2 echo "Creating Configuration file." sed 's/<domU>/'"$2"'/' /home/xen/templates/$1/$1.cfg > / home/xen/domains/$2/$2.cfg.tmp sed 's/<domU-mem>/'"$3"'/' /home/xen/domains/$2/$2.cfg.t mp > /home/xen/domains/$2/$2.cfg echo "Cleaning up temporary files..." rm /home/xen/domains/$2/$2.cfg.tmp rm /home/xen/domains/$2/$1.cfg echo "All Done." else syntax fi else syntax fi else syntax fi
./template.cfg
kernel = ‘/boot/vmlinuz-2.6.18-5-xen-vserver-amd64′
ramdisk = ‘/boot/initrd.img-2.6.18-5-xen-vserver-amd64′
memory = ‘<domU-mem>’
root = ‘/dev/sda1 ro’
disk = [ ‘file:/home/xen/domains/<domU>/disk.img,sda1,w’,
‘file:/home/xen/domains/<domU>/swap.img,sda2,w’ ]
name = ‘<domU>’
dhcp = ‘dhcp’
vif = [ ” ]
on_poweroff = ‘destroy’
on_reboot = ‘restart’
on_crash = ‘restart’
Tags: bash, linux, opensource, scripting, virtualization, xen
April 10th, 2008 at 10:35 pm
Your blog is very informative, I have learned so much from it. It is like daily newspaper :). Added to fav