How does QEMU shuts down a Guest OS.
Hi,
I am trying to understand the internals of the shutdown procedure in a virtual machine. The aim is to understand: 1) How does the QEMU process, shuts down the Guest OS gracefully. Any pointers in this regard would be useful Thanks, Alphonse |
It doesn't. The OS shuts down itself, like it would do on a physical machine.
|
It might be more of the way you pose the question.
If you shutdown qemu it would not allow the guest os time to shutdown properly. Depending on the VM you may have choices as to how that process happens also. Some allow you to choose. One choice may be to save state. One next start it resumes from where you left it. One one choice it is a hard power down. Other choices may exist too. If you shutdown the guest from the normal OS shutdown then the end would be that qemu shuts down. |
Ok. Let me rephrase my question to be specific.
* Assume that I do not have control over Guest OS, but still I would like to signal the OS to shutdown gracefully. Via QEMU-Monitor, I am able to issue a shutdown command to the VM. I would like to understand the execution steps in this case. Thanks for the information. -Alphonse |
Then I think this is the correct answer. If you shutdown qemu it would not allow the guest os time to shutdown properly. UNLESS this works but you'd have to test it.
"system_powerdown This has an effect similar to the physical power button on a modern PC. The VM will get an ACPI shutdown request and usually shutdown cleanly." If you had access to the qemu monitor you may be able to save or stop or take a snapshot. See this page for the commands in monitor that may help. (assumes some level and compile and arch too) http://en.wikibooks.org/wiki/QEMU/Monitor In no case that I know of can qemu send a shutdown command to the client os. ssh, vnc, telnet or such is used if acpi issue. |
in very simple terms, QEMU sends the VM an ACPI shutdown command, same as what would happen when you click the power button on a physical machine. If that fails, you can issue the "destroy" command which will act as if you've pulled the plug on the VM
---------- Post added 06-04-11 at 11:16 AM ---------- note that for this to work, the VM has to be running with ACPI enabled and using an ACPI enabled HAL |
Quote:
|
system_powerdown is the command to send to the VM's monitor of course, it has already been mentioned.
|
Quote:
|
you have it completely wrong.
Every VM running with QEMU maintains a socket, through which the host communicates with the QEMU process. This socket is called qemu monitor, and can be accessed. When you access it, you do not access the VM itself, but the actual process that keeps it running, so when you issue "system_powerdown" to that process, it will emulate an ACPI shutdown in the guest space. If the VM itself supports ACPI, it will detect the ACPI shutdown request, and that will trigger the normal init scripts and the rest of the typical sequence. |
Quote:
Quote:
|
I think it would boil down to a proper test on a test platform to be sure. ACPI has failed me before on qemu.
|
Quote:
|
Quote:
Server systems work in some cases (Slackware) and not at all in other (Ubuntu server just stays up). The real issue is getting that signal to the QEMU process at the time init is sending SIGTERM to other processes. If QEMU were to handle SIGTERM by doing the power button emulation, the issue would be gone. If it could make made to handle it on another signal like SIGHUP, that would be easy to work around. But, getting init to start a script that will hunt down the QEMU monitor sockets to feed in the command line, I have no clue where to start with that. |
@Skaperen
I have a script, which is called from rc.local_shutdown, on my slackware host which will issue a ACPI shutdown command to all running guests, then wait for 60 secs for them to cleanly shutdown. If all the guests cleanly shutdown before the timeout, the script will exit and the host will continue shutting down, if not, it will force shutdown to all running guests and the host will continue shutting down. I use libvirt, one of the available management tools you are not inspired to use ;) Code:
#!/bin/bash |
All times are GMT -5. The time now is 11:29 PM. |