====== FreeBSD Bhyve ====== ===== Initial Setup ===== ==== loader.conf ==== kern.ipc.semmni=40 kern.ipc.semmns=300 vmm_load="YES" nmdm_load="YES" if_bridge_load="YES" if_tap_load="YES" ==== rc.conf ==== * add tap1, tap2, etc for more virtual machines cloned_interfaces="bridge0 tap0" ifconfig_bridge0="addm re0 addm tap0" ==== sysctl.conf ==== net.link.tap.up_on_open=1 ==== Install grub-bhyve and screen ==== pkg install grub2-bhyve pkg install screen ==== Reboot ==== * You should have a ifconfig bridge0 something like this. * The important thing is that you have a physical interface and a tapX device as members of the bridge bridge0: flags=8843 metric 0 mtu 1500 ether 02:b1:2b:2e:66:00 nd6 options=9 groups: bridge id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15 maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200 root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0 member: tap0 flags=143 ifmaxaddr 0 port 4 priority 128 path cost 2000000 member: re0 flags=143 ifmaxaddr 0 port 1 priority 128 path cost 55 * Your kldstat should have the following entries. I removed the entries that didn't apply to Bhyve 1 44 0xffffffff80200000 1fa7c38 kernel 4 1 0xffffffff824bf000 aaa0 if_tap.ko 5 1 0xffffffff824ca000 11c38 if_bridge.ko 6 2 0xffffffff824dc000 8f58 bridgestp.ko 12 1 0xffffffff82681000 3571f0 vmm.ko 13 1 0xffffffff829d9000 5010 nmdm.ko ===== Installing Linux ===== ==== You will need the following in order to install Linux ==== - Install ISO - device.map file - raw drive image === Example device.map file === (hd0) ./ubuntu-16.04.img (cd0) ./ubuntu-16.04.1-server-amd64.iso === Create drive image with: === truncate -s 16G ubuntu-16.04.img === Load Kernel and startvm === screen grub-bhyve -m device.map -r cd0 -M 1024M ubuntu-16.04 bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc -s 2:0,virtio-net,tap0 -s 3:0,virtio-blk,./ubuntu-16.04.img -s 4:0,ahci-cd,./ubuntu-16.04.1-server-amd64.iso -l com1,stdio -c 4 -m 1024M ubuntu-16.04 * As long as the Linux iso has a text mode installer it should install normally === Destroy VM === bhyvectl --destroy --vm=ubuntu-16.04 ===== Running VMs ===== ==== run.sh ==== * The following script loads the kernel, starts the VM, and kills the VM after a ACPI shutdown ==== Linux Version ==== #!/bin/sh CONSOLE="-l com1,stdio" VMNAME="ubuntu16_04" DISKIMAGE="-s 3:0,virtio-blk,./ubuntu-16.04.img" RAM="1024M" CPUS="4" TAPDEV="tap0" NETWORK="-s 2:0,virtio-net,${TAPDEV}" grub-bhyve -m device.map -r hd0,msdos1 -M ${RAM} ${VMNAME} bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc ${NETWORK} ${DISKIMAGE} ${CONSOLE} -c ${CPUS} -m ${RAM} ${VMNAME} bhyvectl --destroy --vm=${VMNAME} ==== FreeBSD Version ==== #!/bin/sh CONSOLE="-l com1,stdio" VMNAME="bsd_emby" DISKFILE="./emby.img" DISKIMAGE="-s 3:0,virtio-blk,./emby.img" RAM="1024M" CPUS="4" TAPDEV="tap1" NETWORK="-s 2:0,virtio-net,${TAPDEV}" cd /vol4/byhve/bsd_emby bhyveload -m ${RAM} -d ${DISKFILE} ${VMNAME} bhyve -A -H -P -s 0:0,hostbridge -s 1:0,lpc ${NETWORK} ${DISKIMAGE} ${CONSOLE} bhyvectl --destroy --vm=${VMNAME}