Solved How reboot FreeBSD 10.1 as guest on bhyve?

When I try to reboot FreeBSD 10.1 as guest on bhyve, OS shutting down. How get state of guest OS on host to use it for cycle in start script for implement reboot function?
 
I think there are plans (possibly even implemented already) to allow guests to reboot normally. At the moment (as far as I'm aware), any shutdown or reboot process causes bhyve to exit.

If you use the /usr/share/examples/bhyve/vmrun.sh script to run the VM, it actually puts the bhyve command in a loop. When bhyve exits, if the exit code indicates that it was rebooted, it goes round the loop and re-runs the bhyve commands to boot to VM again.

Code:
        bhyve_exit=$?
        # bhyve returns the following status codes:
        #  0 - VM has been reset
        #  1 - VM has been powered off
        #  2 - VM has been halted
        #  3 - VM generated a triple fault
        #  all other non-zero status codes are errors
        #
        if [ $bhyve_exit -ne 0 ]; then
                break
        fi
(Basically if the exit code is 0, the VM wants to reboot, so go round again. Any other exit code is a shutdown/halt or error so quit the loop and finish)

If you want to write your own script to run VMs with working reboot, the while(1) loop in the above script is a good start.
 
Thank you very much, it's work!
Code:
#!/bin/sh
while [ 1 ]; do
/usr/sbin/bhyveload -m 4096 -d /usr/vm/tc_cache/tc_cache.img tc_cache
/usr/sbin/bhyve -c 4 -m 4096 -A -H -P \
-s 2:0,virtio-blk,/usr/vm/tc_cache/tc_cache.img \
-s 2:1,virtio-blk,/san/tc_cache/tc_cache.img \
-s 3:2,passthru,3/0/3 \
-s 31,lpc -l com1,stdio \
tc_cache
bhyve_exit=$?
if [ $bhyve_exit -ne 0 ]; then
        break
fi
done
/usr/sbin/bhyvectl --destroy --vm=tc_cache
 
Back
Top