#!/bin/ksh -p IMAGES=/var/lib/libvirt/images LVS=Raid10 XML=/etc/libvirt/qemu lv=1 if [ "x$1" = "x-f" ] then lv=0 shift fi 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 tst2=vm.$machine.disk$a if [ ! -e $tst -a ! -e /dev/$LVS/$tst2 ] then disk_img=$tst disk_lv=$tst2 sd=vd$a fi done if [ -z "$disk_img" ] then echo Already 10 disks... aborted exit fi if [ $lv == 1 ] then echo Creating LV $disk_lv lvcreate -L ${size}M -n $disk_lv $LVS else echo Creating $disk_img dd if=/dev/zero of=$disk_img bs=1M count=$size ls -l $disk_img fi echo Updating VM t=$(mktemp) if [ $lv == 1 ] then to_add=" " else to_add=" " fi 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