2021-11-28 OpenBSD QEMU Gast Agent mit Herunterfahren

Prxomos VM Herunterfahren, Neustarten

Proxmox/KVM OpenBSD QUEM Guest Agent

Möchte man, das OpenBSD Gäste von Proxmox direkt heruntergefahren oder neugestartet werden können, führt kein weg am QUEM Gast Agent vorbei. Leider wird OpenBSD noch nicht ausreichend genug unterstützt, so das noch ein zusätzliches Hilfsscript nötig ist, was das tatsächliche herunterfahren auslöst.


Auf Proxmox:
In Optionen der entsprechenden Maschine, den QUEM Guest Agent aktivieren und bei Type ISA wählen. Gast neu starten.

Alternativ per Shell:
# qm set 101 --agent 1,type=isa
(Wobei 101 hier natürlich für die VM ID steht. Entsprechend anpassen.)


Auf OpenBSD-Gast:
Agent installieren
# pkg_add qemu-ga

Testlauf
$ dmesg | grep '^com'
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo

Sind mehrere serielle Schnittstellen vom Typ isa0 aufgeführt, muss man testen, welches /dev/cuo0? das Richtige ist. In diesem Fall gibt es nur eine, also ist es /dev/cua00.

# qemu-ga -m isa-serial -p /dev/cua00 -t /var/run -v
1638106473.536414: debug: disabling command: guest-suspend-disk
1638106473.536446: debug: disabling command: guest-suspend-ram
1638106473.536457: debug: disabling command: guest-suspend-hybrid
1638106473.536462: debug: disabling command: guest-network-get-interfaces
1638106473.536467: debug: disabling command: guest-get-vcpus
1638106473.536471: debug: disabling command: guest-set-vcpus
1638106473.536475: debug: disabling command: guest-get-memory-blocks
1638106473.536480: debug: disabling command: guest-set-memory-blocks
1638106473.536484: debug: disabling command: guest-get-memory-block-size
1638106473.536489: debug: disabling command: guest-get-memory-block-info
1638106473.536493: debug: disabling command: guest-get-fsinfo
1638106473.536497: debug: disabling command: guest-fsfreeze-status
1638106473.536501: debug: disabling command: guest-fsfreeze-freeze
1638106473.536505: debug: disabling command: guest-fsfreeze-freeze-list
1638106473.536508: debug: disabling command: guest-fsfreeze-thaw
1638106473.536512: debug: disabling command: guest-get-fsinfo
1638106473.536516: debug: disabling command: guest-get-disks
1638106473.536520: debug: disabling command: guest-fstrim
1638106473.536523: debug: disabling command: guest-get-devices
1638106513.16865: debug: read data, count: 105, data: {"execute":"guest-sync-delimited","arguments":{"id":1393224015}}
{"execute":"guest-ping","arguments":{}}

1638106513.16940: debug: process_event: called
1638106513.16945: debug: processing command
1638106513.16989: debug: sending data, count: 24
1638106513.17231: debug: process_event: called
1638106513.17242: debug: processing command
1638106513.17337: debug: sending data, count: 15
1638106513.20842: debug: read data, count: 123, data: {"execute":"guest-sync-delimited","arguments":{"id":1393224016}}
{"arguments":{},"execute":"guest-network-get-interfaces"}

1638106513.20884: debug: process_event: called
1638106513.20894: debug: processing command
1638106513.20920: debug: sending data, count: 24
1638106513.21174: debug: process_event: called
1638106513.21179: debug: processing command
1638106513.21214: debug: sending data, count: 106
^C1638106521.151183: debug: received signal num 2, quitting


Konfiguration speichern
# mkdir /etc/qemu
# $EDITOR /etc/qemu/qemu-ga.conf

[general]
method = isa-serial
path = /dev/cua00
statedir = /var/run
pidfile = /var/run/qemu-ga.pid


init-Script erzeugen
# $EDITOR /etc/rc.d/qemuga

#!/bin/ksh
daemon="/usr/local/bin/qemu-ga"
daemon_flags="-d"

. /etc/rc.d/rc.subr

rc_reload=NO

rc_cmd $1

# chmod 555 /etc/rc.d/qemuga


Hilfsscript zum empfangen und ausführen des Herunterfahren-Signals

Senden man im jetzigen Zustand, vom Host ein Shutdown- oder Reboot-Signal, so erscheinen lediglich folgende Syslog-Einträge:
qemu-ga: vfprintf %s NULL in "guest-shutdown called, mode: %s"
qemu-ga: info: guest-shutdown called, mode: (null)
qemu-ga: vfprintf %s NULL in "hypervisor initiated %s"

Ein Herunterfahren wird aber nicht ausgeführt! Bis eines Tages vielleicht diese Funktion vom Agenten für OpenBSD direkt unterstützt wird, kann man sich mit folgendem Script behelfen, welches auf obige Syslog-Meldung entsprechend reagiert.

# $EDITOR /etc/qemu/halt.sh

#!/bin/sh while read line; do case "$line" in *"info: guest-shutdown called"*) /usr/bin/doas /sbin/halt -p ;; esac done


# chmod 755 /etc/qemu/halt.sh
# $EDITOR /etc/syslog.conf
...

!qemu-ga *.* |/etc/qemu/halt.sh


# $EDITOR /etc/doas.conf
...

permit nopass _syslogd as root cmd /sbin/halt args -p


Setup aktivieren
# rcctl restart syslogd
# rcctl start qemuga
# rcctl enable qemuga

Anbei die Dateien zum herunterladen. Zusätzlich das Ganze als Ansible-Paket.
Download: Config und Scripte - qemu-ga.tar.gz
Download: Ansible - Ansible_QemuGuestAgent.tar.gz

⍈Homepage

#