diff --git a/quickemu b/quickemu index 35a6a3f69d..b36e0d9195 100755 --- a/quickemu +++ b/quickemu @@ -662,27 +662,37 @@ function vm_boot() { fi echo " Just created, booting from ${iso}${img}" DISK_USED="no" - elif [ -e "${disk_img}" ] && [ -z "${VM_PID}" ]; then - # Check there isn't already a process attached to the disk image. - if ! ${QEMU_IMG} info "${disk_img}" >/dev/null; then - echo " Failed to get \"write\" lock. Is another process using the disk?" - exit 1 + elif [ -e "${disk_img}" ]; then + # If the VM is not running, check for disk related issues. + if [ -z "${VM_PID}" ]; then + # Check there isn't already a process attached to the disk image. + 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 - # Only check disk image size if preallocation is off - if [ "${preallocation}" == "off" ]; then - 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 - else - DISK_USED="yes" + if ! ${QEMU_IMG} check -q "${disk_img}"; then + echo " Disk integrity check failed. Please run qemu-img check --help." + echo + "${QEMU_IMG}" check "${disk_img}" + exit 1 + fi + fi + + # Only check disk image size if preallocation is off + if [ "${preallocation}" == "off" ]; then + 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 else DISK_USED="yes" fi + else + DISK_USED="yes" fi fi