68 lines
1.6 KiB
Bash
Executable File
68 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
: ${DOCKERDIR:="$DIR/docker"}
|
|
|
|
mkdir -p "$DOCKERDIR"
|
|
|
|
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
|
|
# -w Ignore accesses to unimplemented Model Specific Registers. Maybe not needed? Man page says its for debug purposes
|
|
# -l for lpc devices
|
|
# -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
|
|
disk_image=$(readlink -f "$DIR/../scripts/build_image/dib.img")
|
|
bhyve \
|
|
-c 1 \
|
|
-m 1024M \
|
|
-H \
|
|
-w \
|
|
-P \
|
|
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
|
|
-u \
|
|
-s 0,hostbridge \
|
|
-s 31,lpc \
|
|
-s "4:0,virtio-blk,$disk_image" \
|
|
-s 5:0,virtio-net,tap1,mac=58:9c:fc:09:c3:ba \
|
|
-s 6:0,virtio-rnd \
|
|
-s "7:0,virtio-9p,docker=$DOCKERDIR" \
|
|
-l com1,stdio \
|
|
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
|