[Slackbuilds-users] Libvirt package - small change to /etc/rc.d/rc.libvirt

Sebastian Arcus s.arcus at open-t.co.uk
Thu May 4 11:55:03 UTC 2017


I have a small change to suggest for the /etc/rc.d/rc.libvirt script. 
The script at the moment does a 'virsh shutdown <vm-name>' on all 
running guests, and then, after waiting only 40 seconds, it destroys all 
guests which are still running. I think in most circumstances this is 
very likely to lead to corrupted guests because:

1. Many guests will take longer than 40 seconds to shutdown, specially 
if they are Windows guests.
2. Some Windows guests might be trying to install updates on shutdown, 
which can take 10, 20 or even 60 minutes.
3. If there are a number of guests running and the host is busy trying 
to shut them all down at the same time, even Linux guests will still be 
in the process of shutting down after 40 seconds.
4. If it is a setup where users connect to guests remotely, it is 
possible that people are in the middle of doing work which would be lost.

Would it maybe be safer to do a 'virsh managedsave <vm-name>' on every 
running guest instead? I can see many advantages to this option, including:

1. It is much less likely for users who might use the guests remotely to 
loose work, as the machine state is suspended.

2. Guests stopped with 'managedsave' will start fine with the 'start' 
command - so no need to change any settings anywhere else, and the 
'autostart' feature of libvirt will continue to work fine.

2. On my server, the 'managedsave' operation takes around 20 seconds per 
guest, and it is more predictable in duration than a 'shutdown', which 
depends on the OS in the guest, if it is installing updates etc.

4. The 'managedsave' command doesn't return immediately, so we can wait 
for each guest in turn and know when it is done. Or ampersand could be 
used on the command, and then just do a looped check on 'virsh list' 
lower down, waiting for the 'managedsave' on all guests to finish.

5. If my understanding is correct, the 'shutdown' command depends on the 
guest implementing correctly and acting on ACPI commands, while a 
'managedsave' seems to be under the complete control of libvirt - which 
means the script would work correctly out of the box with a much wider 
variety of OS's and configurations on the guest side.

If necessary, I suppose the script could also implement a 
'reboot_guests' separate command, for people to use it to reboot all 
running guests - as the "stop" command wouldn't be performing a full 
shutdown any more.

Just a suggestion in case it helps. I'm already very happy with the 
current script, as I used to have to write my own to shutdown kvm/qemu 
guests :-)


More information about the SlackBuilds-users mailing list