bhyve Proper way for bhyve host to shut down guest?

What is the best way for the host system to shut down a guest? My machine is on a ups and when power is lost it shuts down. Several times now the guest VM has been corrupted because it wasn't cleanly shutdown. This seems like a solved problem but no one seems to have mentioned how they do it. Say you have a dozen VMs running, how does the host tell them all to shutdown before it does?
 
This seems like a solved problem but no one seems to have mentioned how they do it. Say you have a dozen VMs running, how does the host tell them all to shutdown before it does?
Install sysutils/vm-bhyve (take note of the post-install message or pkg info -D vm-bhyve), set vm_enable="YES" and vm_dir= in /etc/rc.conf (which enables /usr/local/etc/rc.d/vm script. Description: "Start and stop vm-bhyve guests on boot/shutdown").

Rich (BB code):
#!/bin/sh
#
# $FreeBSD$

# PROVIDE: vm
# REQUIRE: NETWORKING SERVERS dmesg
# BEFORE: dnsmasq ipfw pf
# KEYWORD: shutdown nojailvnet

. /etc/rc.subr

: ${vm_enable="NO"}

name=vm
desc="Start and stop vm-bhyve guests on boot/shutdown"
rcvar=vm_enable

load_rc_config $name

command="/usr/local/sbin/${name}"
start_cmd="${name}_start"
stop_cmd="${command} stopall -f"

vm_start()
{
    env rc_force="$rc_force" ${command} init
    env rc_force="$rc_force" ${command} startall >/dev/null &
}

run_rc_command "$1"

Note stop_cmd="${command} [B]stopall[/B] -f":

vm(8)
Code:
     stopall
             Stop all running virtual machines.  This sends a stop command to
             all bhyve(8) instances, regardless of whether they were starting
             using vm or not.
 
Thanks everyone I'll give vm-bhyve a try. The guest is Debian for the sole purpose of running pihole. When I say corrupted it means the guest fails to boot for some reason and it's faster and easier to do a quick reinstall instead of troubleshooting.
 
My only problem is PCI Passthrough. If I must restart any instance with PCI Passthrough I cannot restart it. I must restart whole machine.

I think it has to do with Wired Memory required for PCI pasthru. Maybe it is not being released correctly. I dunno.
 
Back
Top