machine_setup/ansible/roles/bhyve/files/bhyve_netgraph_bridge.bash
Tom Alexander 9fcc955d13
Starting to write my own script to manage bhyve VMs.
vm-bhyve isn't going to allow me enough control to detect open netgraph hooks on bridges so I will manage the virtual machines myself.
2023-04-27 17:05:32 -04:00

48 lines
1.1 KiB
Bash

#!/usr/local/bin/bash
#
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function main {
if [ "$1" = "create-disk" ]; then
shift 1
create_disk "${@}"
elif [ "$1" = "start" ]; then
shift 1
start_vm "${@}"
else
>&2 echo "Unrecognized command"
exit 1
fi
}
function create_disk {
zfs_path="$1"
gigabytes="$2"
zfs create "-V${gigabytes}G" -o volmode=dev "$zfs_path"
}
function start_vm {
name="$1"
zfs_path="$2"
CPU_CORES=1
MEMORY=1G
# -H release the CPU when guest issues HLT instruction. Otherwise 100% of core will be consumed.
bhyve \
-c $CPU_CORES \
-m $MEMORY \
-H \
-s 0,hostbridge \
-s 3,ahci-cd,/vm/.iso/archlinux-2023.04.01-x86_64.iso \
-s 4,virtio-blk,/dev/zvol/${zfs_path} \
-s 2:0,virtio-net,netgraph,path=bridge_jail_nat:,peerhook=link90 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1920,h=1080,wait \
-s 30,xhci,tablet \
-s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
"$name"
}
main "${@}"