Shutdown Windows KVM Virtual Machine

All my servers usually are Ubuntu Linux boxes. But sometimes I have to manage some Windows servers (2003, 2008, …) running in a KVM setup.

Every time that the host KVM server needs to be restarted, my Windows instances aren’t shutdown cleanly. If I open the virt-manager and open the Console, the screen is resumed(As when it is sleeping) and if I shutdown the host it will show that the Windows is shutting down and everything is perfect, but, there is always a but, if I do the shutdown by ssh without interacting with the Windows machine, it doesn’t “accept” the ACPI Shutdown command and just stand still.

Just for information, I already setup all the ACPI stuff in the KVM and in the Windows boxes.

To avoid this behavior I changed my libvirt script to send a mouse movement before the shutdown command, awaking the Windows before, so it can shutdown properly. 

Edit the upstart-job script:

vim /etc/init/libvirt-bin.conf

Add these 2 lines:

run_virsh -c "$uri" qemu-monitor-command "$domain" mouse_move 100 100 --hmp > /dev/null
sleep 2

Between the log message and the shutdown command:

log_msg "libvirt-bin: attempting clean shutdown of $domain at $(date)"
run_virsh -c "$uri" shutdown "$domain" > /dev/null

This will “awake” the Windows machine and shutdown it cleanly.

Hope it helps!

— Update June, 19 2013 —

Also you need to disable some dialogs in the Windows GPO and Registry to enable your machine shutdown unattended.

— Update September, 12 2013 —

As noted by user infernix, the link I provided in the last update is offline. So I’ll write here what need to be done instead link to another page.

We need to disable a policy that in Windows Server machines will disallow shutdown if the administrator(Or other authorized user) is not logged in.

First, open the Group Policy Editor, press “Win + R” or open “Run” in the Start Menu, write “gpedit.msc”, hit Enter:


This will open the GP Editor, navigate to:

Local Computer Policy -> Computer Configuration -> Windows Settings -> Security Settings -> Local Policies -> Security Options

In the right panel, will be a option that says: “Shutdown: Allow system to be shut down without having to log on”. Double click it and select “Enabled”.


Secondly, we need to disable the “Shutdown Event Tracker”, which is the dialog that will be presented to the user when a shutdown is requested.

Navigate to:

Local Computer Policy -> Computer Configuration -> Administrative Templates -> System

In the right panel, disable the option “Display Shutdown Event Tracker”, the same way you did in the last step, but this time, “Disabled”.


An optional step is to disable monitor sleep, which will not change the power consumption as this is a virtual machine, with a virtual console and will avoid any other issues with shutdown.

Open Control Panel and select Power Options. I use “High performance” option, but you need to click on “Change plan settings” to disable monitor sleep, see images above.



Well, this is all folks.