From 34147ab2027e18a3ab41fe8159c77c8bdec89071 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Thu, 19 Mar 2020 23:20:46 +0000 Subject: [PATCH] Detect if a disk has (most likely) not been installed to and handle accordingly The default qcow2 is 197632, so double that and anything smaller is considered unsed. Makes booting to a live session many times easier. --- quickemu.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/quickemu.sh b/quickemu.sh index e6ea0e6..dde01a1 100755 --- a/quickemu.sh +++ b/quickemu.sh @@ -83,11 +83,20 @@ function vm_boot() { echo " - BIOS: Legacy" fi - echo " - Disk: ${disk_img}" - echo " - Size: ${disk}" + echo " - Disk: ${disk_img} (${disk})" + # If the disk is present but doesn't appear to have an install, then + # remove it. + if [ -e ${disk_img} ]; then + local disk_curr_size=$(stat -c%s "${disk_img}") + if [ ${disk_curr_size} -le 395264 ]; then + echo " Looks unused, recreating." + rm "${disk_img}" + fi + fi + if [ ! -f "${disk_img}" ]; then # If there is no disk image, create a new image. - qemu-img create -q -f qcow2 "${disk_img}" "${disk}" + ${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}" if [ $? -ne 0 ]; then echo "ERROR! Failed to create ${disk_img} of ${disk}. Stopping here." exit 1