Automatically saves the state of all running KVM guests when the system is shut down put into /etc/init.d and reference from /etc/rc0.d and name it with a prefix which makes it execute before any of the other scripts (for instance K01)
#! /bin/sh
suspend_vms () {
for output in $(virsh list --state-running --uuid)
do
exec virsh managedsave $output --bypass-cache
done
}
case "$1" in
start)
# No-op
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
suspend_vms
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
: