#!/bin/ksh -p IMAGES=/var/lib/libvirt/images XML=/etc/libvirt/qemu machine=$1 size=$2 if [ -z "$size" ] then echo "Syntax: ${0##*/} machine_name size" echo " Size must be numeric, and is in Megabytes" exit fi case $size in +([0-9])) # All numeric, fine ;; *) echo Size must be numeric, and is in Megabytes exit esac if [ ! -r $XML/$machine.xml ] then echo $XML/$machine.xml does not exist echo aborted exit fi disk_img= for a in k j i h g f e d c b do tst=$IMAGES/$machine.disk$a.img if [ ! -f $tst ] then disk_img=$tst sd=vd$a fi done if [ -z "$disk_img" ] then echo Already 10 disks... aborted exit fi echo Creating $disk_img dd if=/dev/zero of=$disk_img bs=1M count=$size ls -l $disk_img echo Updating VM t=$(mktemp) to_add=" " if [ -n "$(virsh list | awk '$2 =="'$machine'" { print $0}')" ] then echo Hot adding echo "$to_add" > $t virsh attach-device $machine $t fi echo Adding to permanent config cp $XML/$machine.xml $t print "/<.devices i $to_add . w q" | ed -s $t virsh define $t echo Done rm $t