libvirtd – part of libvirt – is a daemon that manages virtual machines in Linux – including those running under KVM. I recently made the move from controlling my virtual machines with scripts in /etc/init.d to libvirtd. libvirt has a number of advantages over using KVM directly, including:
- Definition of VMs via an XML file (easier to read than the lengthy kvm command line commands)
- Supporting scripts that ease creating VMs (although for this task, I still prefer kvm command line)
- Ability to control VMs remotely via Virtual Machine Manager
- Cleaner network configuration
- Ability to gracefully shutdown VMs
Issuing a shutdown command to a VM under libvirt is essentially like pushing the power button on a regular PC. ACPI capability within your guest OS can then process the button press accordingly, for instance, shutting down or suspending the VM. I’ve used this successfully on several OSs, including:
- Ubuntu 9.10 Server – you must install ACPI support – apt-get install acpid
- Ubuntu 9.10 Desktop – ACPI support is already installed, but you must set the behavior, i.e., shutdown on button press. The default is to ask the user what they want to do.
- Windows 7 – Everything works out of the box. I suspect that this is standard for the more recent Windows releases
To ensure that your VM can process ACPI, make sure that you include the following lines in the configuration XML file:
<features>
<acpi/>
</features>