From 38307c1c0fc415ea6c81c473f9998b6c70af9002 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Fri, 20 Mar 2020 14:18:29 +0000 Subject: [PATCH] Refactor initial disk creation and boot order --- quickemu | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/quickemu b/quickemu index 344d4bf..fdcb154 100755 --- a/quickemu +++ b/quickemu @@ -61,6 +61,7 @@ function vm_boot() { fi readonly disk_min_size=395264 + local disk_curr_size=$(stat -c%s "${disk_img}") if [ -z "${disk}" ]; then disk="64G" fi @@ -81,24 +82,16 @@ function vm_boot() { fi 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 ${disk_min_size} ]; then - echo " Looks unused, recreating." - rm "${disk_img}" - fi - fi - - if [ ! -f "${disk_img}" ]; then + if [ -e ${disk_img} ] && [ ${disk_curr_size} -le ${disk_min_size} ]; then + echo " Looks unused, booting from ${iso}" + elif [ ! -f "${disk_img}" ]; then # If there is no disk image, create a new image. ${QEMU_IMG} create -q -f qcow2 "${disk_img}" "${disk}" + echo " Just created, booting from ${iso}" if [ $? -ne 0 ]; then echo "ERROR! Failed to create ${disk_img} of ${disk}. Stopping here." exit 1 fi - echo " - ISO: ${iso}" else # If there is a disk image, do not boot from the iso iso=""