Refactor initial disk creation and boot order

This commit is contained in:
Martin Wimpress 2020-03-20 14:18:29 +00:00
parent 510c2e0525
commit 38307c1c0f
No known key found for this signature in database
GPG Key ID: 61DF940515E06DA3
1 changed files with 5 additions and 12 deletions

View File

@ -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=""