feat: add disk integrity checking

This commit is contained in:
Martin Wimpress 2024-05-11 12:39:52 +01:00 committed by Martin Wimpress
parent 9dc669b44e
commit d2b5ee4b18
1 changed files with 26 additions and 16 deletions

View File

@ -662,27 +662,37 @@ function vm_boot() {
fi fi
echo " Just created, booting from ${iso}${img}" echo " Just created, booting from ${iso}${img}"
DISK_USED="no" DISK_USED="no"
elif [ -e "${disk_img}" ] && [ -z "${VM_PID}" ]; then elif [ -e "${disk_img}" ]; then
# Check there isn't already a process attached to the disk image. # If the VM is not running, check for disk related issues.
if ! ${QEMU_IMG} info "${disk_img}" >/dev/null; then if [ -z "${VM_PID}" ]; then
echo " Failed to get \"write\" lock. Is another process using the disk?" # Check there isn't already a process attached to the disk image.
exit 1 if ! ${QEMU_IMG} info "${disk_img}" >/dev/null; then
echo " Failed to get \"write\" lock. Is another process using the disk?"
exit 1
fi
else else
# Only check disk image size if preallocation is off if ! ${QEMU_IMG} check -q "${disk_img}"; then
if [ "${preallocation}" == "off" ]; then echo " Disk integrity check failed. Please run qemu-img check --help."
DISK_CURR_SIZE=$(stat -c%s "${disk_img}") echo
if [ "${DISK_CURR_SIZE}" -le "${DISK_MIN_SIZE}" ]; then "${QEMU_IMG}" check "${disk_img}"
echo " Looks unused, booting from ${iso}${img}" exit 1
if [ -z "${iso}" ] && [ -z "${img}" ]; then fi
echo "ERROR! You haven't specified a .iso or .img image to boot from." fi
exit 1
fi # Only check disk image size if preallocation is off
else if [ "${preallocation}" == "off" ]; then
DISK_USED="yes" DISK_CURR_SIZE=$(stat -c%s "${disk_img}")
if [ "${DISK_CURR_SIZE}" -le "${DISK_MIN_SIZE}" ]; then
echo " Looks unused, booting from ${iso}${img}"
if [ -z "${iso}" ] && [ -z "${img}" ]; then
echo "ERROR! You haven't specified a .iso or .img image to boot from."
exit 1
fi fi
else else
DISK_USED="yes" DISK_USED="yes"
fi fi
else
DISK_USED="yes"
fi fi
fi fi