This article will describe suspending guest machine automatically on host machine's shutdown and resuming guest machine automatically on host machine's boot.
Table of Contents
1 Install libvirt-client
Install libvirt-client which includes libvirt-guest.
$ sudo yum install -y libvirt-client
2 Edit /etc/sysconfig/libvirt-guest
Edit /etc/sysconfig/libvirt-guest as below.
$ diff -uprN /etc/sysconfig/libvirt-guest{.org,} --- /etc/sysconfig/libvirt-guest.org 2016-10-18 19:39:11.046386785 +0900 +++ /etc/sysconfig/libvirt-guest 2016-10-18 19:40:30.674745950 +0900 @@ -8,7 +8,7 @@ # - ignore libvirt-guest init script won't start any guest on boot, however, # guest marked as autostart will still be automatically started by # libvirtd -#ON_BOOT=start +ON_BOOT=start # Number of seconds to wait between each guest start. Set to 0 to allow # parallel startup. @@ -22,7 +22,7 @@ # which just needs a long time to shutdown. When setting # ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a # value suitable for your guest. -#ON_SHUTDOWN=suspend +ON_SHUTDOWN=suspend # If set to non-zero, shutdown will suspend guest concurrently. Number of # guest on shutdown at any time will not exceed number set in this variable.
3 Enable libvirt-guest
Enable libvirt-guest and reboot host machine.
$ sudo systemctl enable libvirt-guest $ sudo reboot
After reboot, when shutdowning host machine with runnning guest machine, guest machine will be suspended automatically. When booting host machine, suspended guest machine will be resumed automatically.