Search code examples
virtualizationkvmacpi

How virtualization technology shutdown the OS?


I search something about this question just like KVM, ACPI etc.
I guess that OS implement some interface (like ACPI?), it can receive some kind of signal or command and shutdown itself.
And the host through virtualization technology send a signal or command to OS of instance.

My understanding is right? Can someone give me a direction, thx.


Solution

  • It happens approximately as this.

    1. The VMM (virtual machine monitor) supplies a guest BIOS/UEFI image which, when run inside a virtual machine, populates in-memory ACPI descriptions.
    2. The guest OS reads these ACPI tables and among others finds a description of a button device that corresponds to a power button. It reads which resources are assigned to that button, in particular, how the button is supposed to signal its state. Most commonly, it will be an interrupt with a certain numer and addresses of register(s) used to tell multiple buttons apart.
    3. When a VMM user/admin decides to press a virtual power button, it uses a VMM-specific interface (GUI, CMD-line, script etc.) to command the VMM to do that. The VMM then sets up registers and injects the previously negotiated interrupt number to the guest OS.
    4. It is now the target OS responsibility to react to the signal. From its standpoint, it looked like a real power button was pressed. The guest OS then shuts down individual processes, flushes disk caches and finally uses a platform-specific device access to command the virtual hardware to shut down the power (alternatively, go to hibernate, S5 state, HLT state, reboot etc.) The target OS may well ignore the button press if there is no guest software installed to propagate it to the OS, i.e. Ubuntu without acpi-tools package.