0

I have a Debian 12 VM with QEMU/KVM as hypervisor and Virt-Manager as a frontend and SPICE for graphical output.

The purpose of this VM is to be used interactively and so I'd like not to leave it opened in background. Is it possible to make it so that closing the graphical console will make the guest shut down?

0

2 Answers 2

1

Well, seems like you should "Power Off" it when finishing all work in this VM. Surely this button is available in Debian system menu (GUI) or you can send Ctrl+Alt+Del to this VM and then select appropriate option.

Treat the VM as standard OS, it should be powered off.

Eventually you could issue sudo poweroff -f from the terminal.

-1

Not sure of the details of how your VM is initiated, but assuming you can call on a different script instead:

#!/bin/bash

function cleanup () {
    sudo shutdown --now
}

trap cleanup HUP INT TERM QUIT

original-vm-startup-command

cleanup

Then when the controlling terminal is closed, "sudo shutdown --now" will run. Whether or not it is closed by the application itself or otherwise (like ctrl-C ctrl-D) it should still shutdown. The trap statement will make sure this happens in the latter case, the last line for the former.

You probably want sudo to run for just shutdown without prompting for password: In /etc/sudoers

%admin ALL=NOPASSWD: /sbin/shutdown

replace 'admin' with the appropriate username.

If this solution doesn't work, would need more details on how you are starting things up.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .