Will `sudo reboot` on KVM host gracefully poweroff guest VMs?

17,846

Yes, this is done automatically, according to this fixed bug: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/350936

See also: https://serverfault.com/questions/200751/can-kvm-suspend-or-shutdown-guests-automatically-on-host-shutdown

Share:
17,846

Related videos on Youtube

HDave
Author by

HDave

Architect, developer, and most importantly, user.

Updated on September 18, 2022

Comments

  • HDave
    HDave over 1 year

    Currently I manually poweroff each KVM guest before rebooting the host. However, this is getting old and now I am up to about 20 guest machines.

    Can I trust Ubuntu Server 12.04 to do the Right Thing and hold off on completing a shutdown until the last KVM client is off?

    Alternatively is there an easier way to shut all the guests off gracefully?

    • Admin
      Admin about 11 years
      Something to think about: a shutdown script that would send some sort of "shutdown all VMs" signal to KVM. The idea needs some fleshing out, but if KVM supports command-line control, it wouldn't be too hard to create a simple shutdown script to do that.
    • Admin
      Admin about 11 years
      Yes - this could be done via the virsh command, I'm looking for something more out-of-the-box. According to this launchpad bug, it may already Just Work: bugs.launchpad.net/ubuntu/+source/kvm/+bug/350936
    • Admin
      Admin about 11 years
      On RedHat they have a script called libvirt-guests which takes care of this automatically, but for whatever reason, Ubuntu doesn't include this script in their package. launchpad.net/ubuntu/+source/libvirt/0.9.8-2ubuntu1
    • Admin
      Admin about 11 years
      ok - looking /etc/init/libvirt-bin it appears that the necessary code is in there to do this. I just completed a test run and it did work, but I needed to increase the timeout that was in that file from 30 seconds to 2 minutes.
    • Admin
      Admin about 10 years
      As a system admin I'm shocked to see the timeout in /etc/init/libvirt-bin.conf is ONLY 30 seconds. Checking the code I see this isn't even per VM, it is total. I've seen a physical (non-VM) production server that take 15min to shutdown on new fast hardware after a fresh install and databases restored. My Work's current main VM server takes nearly 10mins to shutdown due to the 30VMs with multiple databases etc.
    • Admin
      Admin about 10 years
      I just learned you are supposed to put changes into a new /etc/init/libvirt-bin.override file instead of changing the .conf file. According to upstart.ubuntu.com/cookbook/#override-files and sebastian.marsching.com/wiki/Linux/KVM
  • James Hancock
    James Hancock over 4 years
    Ubuntu 19.04 does not actually do this.