Handle the networking.

This commit is contained in:
Tom Alexander 2022-01-30 02:33:08 -05:00
parent 977c8a74e8
commit b0d8800b52
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

33
scripts/launch_bhyve.bash Normal file → Executable file
View File

@ -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