[Ilugc] Question about shutting down Guest KVMs during HOST OS shutdown

  • From: knura@xxxxxxxxx (Arun Khan)
  • Date: Tue Nov 24 16:01:57 2009

Greetings,

I have been working on a script (kvminit) that starts and shuts down
Guest KVMs during HOST OS boot/shutdown.   The setup is in a small
network wherein HOST OS is openSUSE 11.1 and Guest KVMs is a bunch of
openSUSE and CentOS servers installation doing dedicated tasks (e.g.
openLDAP + Samba PDC/BDC, DNS, eGroupWare).

During HOST OS shutdown, the kvminit shuts down each Guest KVM using
the following mechanism:

 ssh root@<kvm_guest> "/sbin/poweroff"  (using ssh key-pair login mechanism)

Primary reason for choosing the above was to ensure that the file
systems on each Guest KVM  is closed properly i.e. avoid FS
corruption.

This method also assumes that key-pair prep between HOST OS "user" and
the "root" user on each Guest OS has been done a priori.
Additionally, the script waits 30-50 secs per KVM (depending on the
services) until each Guest OS halts itself.

Then I came across a script (link below) which shuts down Guest KVM a
bit differently:

<http://www.linux-kvm.org/page/Simple_shell_script_to_manage_your_virtual_machine_with_bridged_networking>

relevant excerpt:

send_cmd() {
       QEMU_MONITOR_COMMAND=$1
       echo "${QEMU_MONITOR_COMMAND}" | socat - UNIX-CONNECT:${FILE_MONITOR}
}

which sends the "exit" command to the qemu process via a socket file.

I have experimented with the above technique and noticed that it is
the equivalent of doing a "hard" power off on the guest KVM.  In other
words the qemu process exits immediately without giving the Guest OS
any chance shutdown it's services and to umount the file systems.  I
have read the qemu-kvm man page and did not come across any

Is there any other way to ensure that guest KVM shuts down cleanly?

TIA,
-- Arun Khan

Other related posts: