17

I'm using virtualisation solely to install OpenBSD onto the bare hardware, and during the installation, the redirection to the serial port didn't get configured, so, I ended up with the system running, but no way to login and do a clean shutdown.

kvm -m 6144 -smp 4 -drive file=/dev/sda,if=ide \
    -drive file=/dev/sdb,if=scsi -drive file=/dev/sdc,if=scsi \
    -cdrom install52.iso -boot d -nographic

How can I send a shutdown event to this session? AFAIK, Ctrl-a x as shown here or a pkill kvm would not do a clean shutdown yet.

Alternatively, how can I switch from the -nographic mode into the -curses mode ?

mtk
  • 26,802
  • 35
  • 91
  • 130
cnst
  • 3,223
  • 2
  • 23
  • 44
  • As for “clean”, I _think_ that if it's a fresh install that doesn't have much running on it yet, as long as you wait like 20 minutes the filesystem should have all its changes synced and wouldn't experience any particularly nasty problems from a hard-shutdown – JamesTheAwesomeDude Apr 08 '20 at 12:20

4 Answers4

15

Perhaps Ctrl-a c and system_powerdown ?

Supposed to work, although it didn't seem to work in my case; perhaps OpenBSD and QEMU ACPI don't interact well enough.

mtk
  • 26,802
  • 35
  • 91
  • 130
cnst
  • 3,223
  • 2
  • 23
  • 44
  • note that if you've started qemu with `-monitor stdio`, you can just type `system_powerdown` right at the `(qemu) ` prompt – JamesTheAwesomeDude Apr 08 '20 at 11:51
  • 1
    `system_powerdown` for an android-x86 iso installed to a disk img caused the poweroff/restart side panel to appear for me. – duanev Oct 03 '21 at 08:37
7

In principle: Sending "system_powerdown" to the QEMU monitor (see other answers) will signal the guest OS to power off (like if you pushed the power button). You will need to set powerdown=YES in /etc/rc.shutdown to really shut down the machine completely.

Unfortunately in my actual setup here, while this works quite well for real hardware machines, the VM's freeze on receiving a powerdown event. (This is with QEMU-KVM 1.1.2 on Debian Wheezy/amd64 and OpenBSD 5.5 amd64 GENERIC.SP) So what you may do instead is sending a shutdown -h now or halt -p to the (OpenBSD) console.

Kevdog777
  • 3,194
  • 18
  • 43
  • 64
user81513
  • 71
  • 1
  • 1
7

libvirt knows how to handle this. If you don't mind installing libvirtd and virsh, then you can use:

virsh list

to show the name(s) of the guest(s). And, to shutdown gracefully the guest with name guest_001, use the command:

virsh shutdown guest_001
rbrito
  • 412
  • 3
  • 13
Angel Genchev
  • 79
  • 1
  • 2
0

qemu sends an acpi shutdown event to the VM, if it cannot interpret this call, it will not shutdown. In Linux this means you need acpid running, as for BSD, I suppose something similar must exist

dyasny
  • 1,136
  • 6
  • 8
  • Are there no options to send non-ACPI shutdown events to the guest OS? – cnst Dec 08 '12 at 06:44
  • 1
    define "non acpi shutdown event" – dyasny Dec 08 '12 at 07:16
  • 1
    `Ctrl-Alt-Del`, APM etc. – cnst Dec 08 '12 at 07:59
  • 2
    none of these is a shutdown. system stop with no poweroff and a reboot are not shutdown. Maybe Alt+SysRQ+o will work (it's APM, so I doubt the VM with terminate after stopping everything, but...) the key combination can be sent via the qemu-monitor sendkey routine – dyasny Dec 08 '12 at 08:26
  • How do I send any of these in a snap? I don't care what the VM does; it only matters that the guest gets one of these, and does a sync with proper umount and stuff. – cnst Dec 10 '12 at 20:13
  • You need to read through http://en.wikibooks.org/wiki/QEMU/Monitor – dyasny Dec 10 '12 at 20:26
  • @cnst `Ctrl-Alt-Del` is just a key sequence: `sendkey ctrl-alt-delete` at the monitor will do that (without your host OS snatching it up). – JamesTheAwesomeDude Apr 08 '20 at 11:52
  • Sounds like an ACPI shutdown (“power button”) event is _exactly_ what you need, @cnst: >it only matters that the guest gets one of these, and does a sync with proper umount and stuff< —if your guest isn't shutting down on receiving these, that's a bug. The next-best option would be something like sending shutdown _Linux commands_ or whatever to the console or CtrlAltDel to the keyboard, but that's even more unreliable because you'll have to deal with stuff like making sure that that console's logged in, something's _listening_ for CtrlAltDel, etc. – JamesTheAwesomeDude Apr 08 '20 at 12:07