summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-07-23 16:43:08 +0300
committerLars Wirzenius <liw@liw.fi>2017-07-23 16:43:08 +0300
commit3dddd17127b117b7919f5f8fbed81c5b73e3b32e (patch)
treeba1127714efefa82e8a00e3fe6f38c613469d740 /create-vm
parent552538fa28915f5b4e2480682ea8e17faa24f95f (diff)
downloadansibleness-3dddd17127b117b7919f5f8fbed81c5b73e3b32e.tar.gz
Add: create-vm improvements
Allow any size images, not just 4G ones. Allow user to provide image via path (contains "/"), instead of only ones in a "base image directory".
Diffstat (limited to 'create-vm')
-rwxr-xr-xcreate-vm23
1 files changed, 16 insertions, 7 deletions
diff --git a/create-vm b/create-vm
index bb0f54b..519b019 100755
--- a/create-vm
+++ b/create-vm
@@ -31,6 +31,12 @@ for lease in leases:
}
+xz_uncompressed_size()
+{
+ xz --robot --verbose --list "$1" | awk '/^file/ { print $5 }'
+}
+
+
# Check parameters.
if [ "$#" != 2 ]
@@ -39,26 +45,29 @@ then
fi
-# Command line parameters: name of VM and base image (no .img.xz suffix).
-name="$1"
-base="$2"
# Config variables.
. "$HOME/.config/ansibleness/vm.conf"
+# Command line parameters: name of VM and base image (no .img.xz suffix).
+name="$1"
+case "$2" in
+ */*) basepath="$2" ;;
+ *) basepath="$imagedir/base-$2.img.xz" ;;
+esac
+
# Does the base image exist?
-basepath="$imagedir/base-$base.img.xz"
if [ ! -e "$basepath" ]
then
echo "$basepath does not exist" 1>&2
exit 1
fi
-# How large are the (uncompressed) images?
-size="4G"
+# How large is the (uncompressed) image? In bytes.
+size="$(xz_uncompressed_size "$basepath")"
# Create new LV.
-sudo lvcreate --name "$name" --size "$size" \
+sudo lvcreate --name "$name" --size "${size}b" \
--zero y --wipesignatures y --activate y "$vg"
lvpath="/dev/$vg/$name"