diff options
Diffstat (limited to 'create-guest-with-cloudinit')
-rwxr-xr-x | create-guest-with-cloudinit | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/create-guest-with-cloudinit b/create-guest-with-cloudinit index 8b64fd8..030022f 100755 --- a/create-guest-with-cloudinit +++ b/create-guest-with-cloudinit @@ -1,7 +1,7 @@ #!/bin/bash # depends on following packages: -# apt-get install virtinst libvirt-bin dosfstools mtools kvm +# apt-get install virtinst libvirt-bin dosfstools mtools kvm xmlstarlet # For resizing the root partition we tried two ways: @@ -41,8 +41,10 @@ ROOT_PARTITION_BEGINNING='4096s' # unconfigurable variables MIN_ROOTSIZE=2 DEFAULT_SWAPSIZE=512 +DEFAULT_MEM=512 rootsize=$MIN_ROOTSIZE swapsize=$DEFAULT_SWAPSIZE +memsize=$DEFAULT_MEM # overwrite defaults @@ -66,6 +68,7 @@ Usage: ${0##*/} -r <gb> -s <mb> -n guest_name -h show usage -r size root size in GB. Defaults to minimal value of $MIN_ROOTSIZE GB. -s size swap size in MB. Defaults to $DEFAULT_SWAPSIZE MB. + -m size memory size in kibibytes. Defaults to $DEFAULT_MEM KiB. -n name guestname EOF } @@ -73,7 +76,7 @@ EOF # Parse cmdline options -while getopts "hr:s:n:" OPTION +while getopts "hr:s:n:m:" OPTION do #echo $OPTION $OPTARG case $OPTION in @@ -82,11 +85,12 @@ do r) rootsize=$OPTARG;; s) swapsize=$OPTARG;; n) vmname=$OPTARG;; + m) memsize=$OPTARG;; esac done [ -z $vmname ] && bad_usage "must provide guest name" -[ $# -gt 6 ] && bad_usage "too many arguments" +[ $# -gt 8 ] && bad_usage "too many arguments" [ $rootsize -lt $MIN_ROOTSIZE ] && bad_usage "Minimal root size is $MIN_ROOTSIZE GB !" @@ -106,6 +110,8 @@ echo echo "Creating guest VM $vmname:" echo "Root size: $rootsize GB, using $rootdev" echo "Swap size: $swapsize MB, using $swapdev" +echo "Memory size: $memsize KiB" +echo "" echo "using $cfg for cloud-init" echo echo "OK ? <Ctrl-C> to abort, <enter> to resume." @@ -123,6 +129,13 @@ mkswap -U $SWAPUUID $swapdev sleep 4 virt-clone --connect $KVM_URI -o $BASEIMAGE -n $vmname -f $rootdev --force +# Set memory +tmpxml=`mktemp` +virsh dumpxml ${vmname} > $tmpxml +xmlstarlet edit -L -u "/domain[@type='kvm']/memory[@unit='KiB']" -v "${memsize}" $tmpxml +virsh define $tmpxml +rm -f $tmpxml + # resize root partition # echo ",+," | sfdisk -q -N2 /dev/$VG/$vmname > /dev/null 2>&1 @@ -149,12 +162,13 @@ echo echo 'Starting new guest, attaching to console. Exit with Ctrl+]' echo -virsh start $vmname +virsh start $vmname sleep 2 # create seed- and swapdisk definition and attach them virsh attach-disk $vmname --source $swapdev --target vdb --config virsh attach-disk $vmname --source $VARDIR/$vmname-$SEED --target vdc --sourcetype file --type disk --driver qemu --subdriver raw --config +virsh setmem $vmname $memsize --live --config virsh console $vmname |