#!/usr/local/bin/bash # set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Share a host directory to the guest via 9pfs. # # Inside the VM run: # mount -t virtfs -o trans=virtio sharename /some/vm/path # mount -t 9p -o cache=mmap -o msize=512000 sharename /mnt/9p # mount -t 9p -o trans=virtio,cache=mmap,msize=512000 sharename /path/to/mountpoint # bhyve_options="-s 28,virtio-9p,sharename=/" # Enable Sound # bhyve_options="-s 16,hda,play=/dev/dsp,rec=/dev/dsp" # Example usage: # # doas bhyve_netgraph_bridge create-disk zdata/vm/poudriere /vm/poudriere 10 # doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere jail_nat 10.215.1.1/24 /vm/iso/FreeBSD-13.2-RELEASE-amd64-bootonly.iso # doas bhyve_netgraph_bridge start poudriere zdata/vm/poudriere /vm/poudriere jail_nat 10.215.1.1/24 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 die { local status_code="$1" shift (>&2 echo "${@}") exit "$status_code" } function create_disk { zfs_path="$1" mount_path="$2" gigabytes="$3" zfs create -o "mountpoint=$mount_path" "$zfs_path" cp /usr/local/share/edk2-bhyve/BHYVE_UEFI_VARS.fd "${mount_path}/" tee "${mount_path}/settings" <&2 echo "No available links on bridge $bridge_name") exit 1 fi done } function assert_bridge { host_interface_name="$1" bridge_name="$2" ip_range="$3" if ! ng_exists "${bridge_name}:"; then ngctl -d -f - </dev/null 2>&1 } function calculate_mac_address { name="$1" source=$(md5 -r -s "$name" | awk '{print $1}') echo "06:${source:0:2}:${source:2:2}:${source:4:2}:${source:6:2}:${source:8:2}" } function find_available_port { start_port="$1" port="$start_port" while true; do sockstat -P tcp -p 443 port=$((port + 1)) done } main "${@}"