Guest restarting after issuing a shutdown

Hello everyone, I create kvm machines using a bash script. As expected from the script, the resulting virtual machines are performing as they should be. The aspect that I do not get is at the end of the creation, when issuing a 'shutdown now' in the guest and expecting that it will shut down. Instead it does shut down, but it is restarted immediately. The machines are created using an Arch Linux ISO file. The bash script runs in three stages, the first stage is on the host. virt-install will show the regular Arch Linux installation interface. The bash script is copied to the machine and its second stage is ran. After that a chroot is done and the third phase of the script is executed. When everything is configured and installed, here is what happens, commands are prefixed '%', text output is as is, and comments in '()' : guest : % shutdown now host : Domain creation completed. host : Restarting guest. (virt-manager shows the guest restarting) host : % virsh shutdown test02 (nothing happens, guest still shown) host : % virsh destroy test02 host : Domain test02 destroyed (guest display closes) What I'm expecting is that, when the 'shutdown now' is issued in the guest, that it will effectively terminate the guest, 'virsh list --all' will not show it running, and there'll be no need to issue a 'virsh destroy'. I have no clue at the moment why virsh is restarting the guest after a shutdown was issued in the guest. Looks like virsh did not get that it should terminate the guest and considers the shutdown as an error. Here are the versions involved : host : xubuntu 20.04 LTS libvirt 6.0.0-0ubuntu8.15 virt-manager 1:2.2.1-3ubuntu2.1 guest : archlinux 2022.03.01-x86_64 Thanks !

virt-install is expecting the installation process to need a reboot partway through, so carefully restarts the guest on its first shutdown. Then it gets out of the way. Either change what virt-install thinks it's installing (not sure how, never done it), or write and enable a service during installation that removes itself then shuts down the guest. First install doesn't run the service, so restarts normally. Next boot starts the service, which removes itself and forces a shutdown. Job done. Cheers, Peter On Fri, 1 Apr 2022, 16:14 jonetsu, <jonetsu@teksavvy.com> wrote:
Hello everyone,
I create kvm machines using a bash script. As expected from the script, the resulting virtual machines are performing as they should be. The aspect that I do not get is at the end of the creation, when issuing a 'shutdown now' in the guest and expecting that it will shut down. Instead it does shut down, but it is restarted immediately.
The machines are created using an Arch Linux ISO file. The bash script runs in three stages, the first stage is on the host. virt-install will show the regular Arch Linux installation interface. The bash script is copied to the machine and its second stage is ran. After that a chroot is done and the third phase of the script is executed. When everything is configured and installed, here is what happens, commands are prefixed '%', text output is as is, and comments in '()' :
guest : % shutdown now host : Domain creation completed. host : Restarting guest. (virt-manager shows the guest restarting)
host : % virsh shutdown test02 (nothing happens, guest still shown)
host : % virsh destroy test02 host : Domain test02 destroyed (guest display closes)
What I'm expecting is that, when the 'shutdown now' is issued in the guest, that it will effectively terminate the guest, 'virsh list --all' will not show it running, and there'll be no need to issue a 'virsh destroy'. I have no clue at the moment why virsh is restarting the guest after a shutdown was issued in the guest. Looks like virsh did not get that it should terminate the guest and considers the shutdown as an error.
Here are the versions involved :
host : xubuntu 20.04 LTS libvirt 6.0.0-0ubuntu8.15 virt-manager 1:2.2.1-3ubuntu2.1 guest : archlinux 2022.03.01-x86_64
Thanks !

On Fri, Apr 01, 2022 at 11:12:50AM -0400, jonetsu wrote:
guest : % shutdown now host : Domain creation completed. host : Restarting guest. (virt-manager shows the guest restarting)
Try passing --no-reboot to virt-install.
host : % virsh shutdown test02 (nothing happens, guest still shown)
If the guest OS is fully booted up at this point, you should be able to initiate a clean shutdown from the host. If that doesn't work, make sure your VM configuration contains <domain> ... <features> <acpi/> </features> ... <on_poweroff>destroy</on_poweroff> ... </domain> and that there is some software running in the guest that will process the ACPI event appropriately. systemd will usually take care of that part. -- Andrea Bolognani / Red Hat / Virtualization
participants (3)
-
Andrea Bolognani
-
jonetsu
-
Peter Crowther