summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2014-02-19 17:43:02 +0100
committerDominique Martinet <asmadeus@codewreck.org>2015-07-02 18:26:37 +0200
commit3c93ca66769ffb711a23fcfe60622d42e4ea0e5e (patch)
tree3f604e9ffd66702b9719b674b4bfe81ebe59a17e
parent054752328b379f31be4eaeee105966bec78492ac (diff)
Create: allow to create a qcow disk if configured to
-rw-r--r--kvm-wrapper.conf.default1
-rwxr-xr-xkvm-wrapper.sh53
2 files changed, 24 insertions, 30 deletions
diff --git a/kvm-wrapper.conf.default b/kvm-wrapper.conf.default
index badc821..60a2be2 100644
--- a/kvm-wrapper.conf.default
+++ b/kvm-wrapper.conf.default
@@ -100,6 +100,7 @@ ROOT_SIZE="3072" #Do not edit once the disk has been created!! Incoherent data m
SWAP_SIZE="512"
#LVM_LV_NAME
#LVM_PV_NAME
+#BOOTSTRAP_DISK_DIR #do not use lvm, but create a qcow image there instead if set
#KVM_BIN
KVM_PREPEND_PARAMS=""
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh
index e5dc4fc..f8c0c50 100755
--- a/kvm-wrapper.sh
+++ b/kvm-wrapper.sh
@@ -288,6 +288,19 @@ function lvm_create_disk ()
desc_update_setting "KVM_DISK[0]" "/dev/$LVM_VG_NAME/$LVM_LV_NAME"
}
+function qcow_create_disk()
+{
+ local KVM_IMG_DISKNAME="$1"
+ local KVM_IMG_DISKSIZE="$2"
+ "$KVM_IMG_BIN" create -f "$KVM_IMG_FORMAT" "$KVM_IMG_DISKNAME" "$KVM_IMG_DISKSIZE"
+ if [[ "x$?" == "x0" ]]
+ then
+ desc_update_setting "KVM_DISK[0]" "$KVM_IMG_DISKNAME"
+ else
+ echo "Failed creating disk. Continuing anyway"
+ fi
+}
+
function map_disk()
{
local DISKDEV=$1
@@ -744,29 +757,6 @@ function kvm_edit_descriptor ()
function kvm_create_descriptor ()
{
- local DISK_CREATED=0
- if [[ -n $2 ]]
- then
- require_exec "$KVM_IMG_BIN"
- local KVM_IMG_DISKNAME="`canonpath \"$2\"`"
- fi
- if [[ -z $3 ]]
- then
- DISK_CREATED=1
- fi
- if [[ -n $3 ]]
- then
- echo "Calling kvm-img to create disk image"
- local KVM_IMG_DISKSIZE="$3"
- "$KVM_IMG_BIN" create -f "$KVM_IMG_FORMAT" "$KVM_IMG_DISKNAME" "$KVM_IMG_DISKSIZE"
- if [[ "xx$?" == "xx0" ]]
- then
- DISK_CREATED=1
- else
- echo "Failed creating disk. Creating vm anyway"
- fi
- fi
-
VM_NAME="$1"
VM_DESCRIPTOR="$VM_DIR/$VM_NAME-vm"
test_exist "$VM_DESCRIPTOR" && fail_exit "Error: $VM_NAME already exists ($VM_DESCRIPTOR found)"
@@ -780,15 +770,14 @@ function kvm_create_descriptor ()
awk '/#xxDEFAULTxx#/,0 { print "#" $0}' $CONFFILE|grep -v "#xxDEFAULTxx#" >> "$VM_DESCRIPTOR"
- if [[ "xx$DISK_CREATED" == "xx1" ]]
- then
- local HDA_LINE="KVM_DISK[0]=\"$KVM_IMG_DISKNAME\""
- sed -i "s,##KVM_DISK\[0\],$HDA_LINE,g" "$VM_DESCRIPTOR"
- fi
-
sed -i 's/#KVM_MACADDR\[0\]="`random_mac`/KVM_MACADDR[0]="'`random_mac`'/g' "$VM_DESCRIPTOR"
sed -i 's/#KVM_CLUSTER_NODE="`hostname -s`/KVM_CLUSTER_NODE="'`hostname -s`'/g' "$VM_DESCRIPTOR"
+ if [[ -n "$3" ]]; then
+ qcow_create_disk "$2" "$3"
+ elif [[ -n "$2" ]]; then
+ desc_update_setting "KVM_DISK[0]" "$2"
+ fi
echo "VM $VM_NAME created. Descriptor: $VM_DESCRIPTOR"
@@ -989,7 +978,11 @@ function kvm_build_vm ()
kvm_init_env "$VM_NAME"
- lvm_create_disk "$VM_NAME"
+ if [[ -n "$BOOTSTRAP_DISK_DIR" ]]; then
+ qcow_create_disk "$BOOTSTRAP_DISK_DIR/vm-$VM_NAME" "$ROOT_SIZE"
+ else
+ lvm_create_disk "$VM_NAME"
+ fi
if [[ -z "$DISABLE_BOOTSTRAP" ]]; then
kvm_bootstrap_vm "$VM_NAME"