add vmdisk-cleanup, to remove VM root disk if needed
authorDinar Valeev <dvaleev@suse.de>
Tue, 24 Jul 2012 10:24:23 +0000 (12:24 +0200)
committerDinar Valeev <dvaleev@suse.de>
Tue, 24 Jul 2012 12:50:57 +0000 (14:50 +0200)
build

diff --git a/build b/build
index 8850b11..f5e0c86 100755 (executable)
--- a/build
+++ b/build
@@ -72,6 +72,7 @@ VMDISK_SWAPSIZE=1024
 VMDISK_FILESYSTEM=ext3
 # settings are for speed and not data safety, we format anyway on next run
 VMDISK_MOUNT_OPTIONS=__default
+VMDISK_ROOT_CLEAN=no
 HUGETLBFSPATH=
 MEMSIZE=
 RUNNING_IN_VM=
@@ -979,6 +980,11 @@ while test -n "$1"; do
        VMDISK_MOUNT_OPTIONS=$(echo $ARG | sed 's/^\"\(.*\)\"$/\1/g')
        shift
       ;;
+      *-vmdisk-cleanup)
+        needarg
+        VMDISK_ROOT_CLEAN="$ARG"
+        shift
+      ;;
       *-rpmlist)
        needarg
        RPMLIST="--rpmlist $ARG"
@@ -1309,6 +1315,11 @@ if test -z "$RUNNING_IN_VM" ; then
            XENID="${XENID#root_}"
            xm destroy "build_$XENID" >/dev/null 2>&1
        fi
+       if [ "$VMDISK_ROOT_CLEAN" = "yes" ]; then
+           #delete VM image so later we can recreate a new one
+           echo "Deleting $VM_IMAGE"
+           rm -rf "$VM_IMAGE"
+       fi
        if test ! -e "$VM_IMAGE"; then
            echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
            mkdir -p "${VM_IMAGE%/*}"