From b0d8800b52948f075d36f4b1c3c8e4c5f883ca09 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 30 Jan 2022 02:33:08 -0500 Subject: [PATCH] Handle the networking. --- scripts/launch_bhyve.bash | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) mode change 100644 => 100755 scripts/launch_bhyve.bash diff --git a/scripts/launch_bhyve.bash b/scripts/launch_bhyve.bash old mode 100644 new mode 100755 index 0cb51ea..01e3af3 --- a/scripts/launch_bhyve.bash +++ b/scripts/launch_bhyve.bash @@ -4,6 +4,22 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +function cleanup { + for dev in "${devices[@]}"; do + echo "Deleting $dev" + ifconfig "$dev" destroy + done +} +devices=() +for sig in EXIT INT QUIT HUP TERM; do + trap "set +e; cleanup" "$sig" +done + +ifconfig tap1 create +devices+=("tap1") +ifconfig tap1 up +ifconfig bridge0 addm tap1 + # 1 core # 1GB ram # -H yield the virtual CPU when HLT instruction is detected, otherwise bhyve eats the entire core @@ -12,11 +28,14 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # -U for specifying uuid, going to omit and see if the generated one works # -u RTC is in UTC # -s virtual PCI slots +# -P force guest CPU to exit when PAUSE instruction detected +set +e bhyve \ -c 1 \ -m 1024M \ -H \ -w \ + -P \ -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \ -u \ -s 0,hostbridge \ @@ -29,3 +48,17 @@ bhyve \ -s 3:0,ahci-cd,/vm/.config/null.iso \ -l com1,/dev/nmdm-docker.1A \ docker +bhyve_status=$? +set -e + +if [ "$bhyve_status" == "0" ]; then + echo "rebooted" +elif [ "$bhyve_status" == "1" ]; then + echo "powered off" +elif [ "$bhyve_status" == "2" ]; then + echo "halted" +elif [ "$bhyve_status" == "3" ]; then + echo "triple fault" +elif [ "$bhyve_status" == "4" ]; then + echo "exited due to an error" +fi