I have a Windows 8 installation on a KVM virtual machine, runing on my Ubuntu 15.04 host. When I issue the shutdown option in virt-manager, or virsh shutdown windows, the virtual machine cleanly shuts down as expected.

Supposedly, the VM should be allowed to cleanly shut down when I shut down or reboot the host. However, this is not the case, and the virtual machine is abruptly stopped.

1 Answer 1


Update upon suggestion:

According to the blog/wiki author:

However, there is the problem that each VM will only receive one shutdown request. For Linux VMs this is usually fine, but Windows VMs sometimes do not react to the first request, resulting in the VM being killed forcibly after the timeout. The only way to fix this problem is modifying the shutdown script so that it sends shutdown requests again and again until a VM has shutdown or the timeout has been reached.

So the solution is to patch /usr/lib/libvirt/libvirt-guests.sh in Ubuntu 16.04 LTS (Xenial Xerus) (credit to the wiki author: Sebastian Marsching):

--- /usr/lib/libvirt/libvirt-guests.sh  2016-10-10 09:33:38.000000000 +0200
+++ /usr/local/lib/libvirt/libvirt-guests.sh    2016-11-08 11:58:33.000000000 +0100
@@ -339,6 +339,19 @@
     retval run_virsh "$uri" shutdown "$guest" > /dev/null
+# shutdown_guest_retry URI GUEST
+# Start a ACPI shutdown of GUEST on URI. This function returns after the command
+# was issued to libvirt to allow parallel shutdown.
+# This command does the same as shutdown_guest_async, but does not print a
+# message.
+    uri=$1
+    guest=$2
+    retval run_virsh "$uri" shutdown "$guest" > /dev/null
 # guest_count GUEST_LIST
 # Returns number of guests in GUEST_LIST
@@ -407,6 +420,14 @@
         format=$(eval_gettext "Waiting for %d guests to shut down\n")
     while [ -n "$on_shutdown" ] || [ -n "$guests" ]; do
+        guests_retry=$on_shutdown
+        while [ -n "$guests_retry" ]; do
+            set -- $guests_retry
+            guest=$1
+            shift
+            guests_retry=$*
+            shutdown_guest_retry "$uri" "$guest"
+        done
         while [ -n "$guests" ] &&
               [ $(guest_count "$on_shutdown") -lt "$PARALLEL_SHUTDOWN" ]; do
             set -- $guests

However, when I checked the same code for Ubuntu 20.04, the similar logic is already there. So this is no longer a problem.

It is late as an answer, but it is useful for documenting:

This post gives a solution for Ubuntu.

  • 1
    A link only answer is not sufficient. Please write the essential steps and keep the link as reference. Links break all the time.
    – user68186
    Sep 1, 2020 at 21:51
  • 1
    @user68186 Thank you for your suggestion! I have fixed my answer.
    – ivzhh
    Sep 4, 2020 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.