Install Home Assistant on FreeBSD inside bhyve VM

August 24, 2022

Doing this on FreeBSD 13.1-p1 vm vm-bhyve 1.5.0 as bhyve vm manager and qemu-tools 7.0.0_1 is required to convert the image from qcow2 to raw I assume.

Requirements

Required pkgs

  • vm-bhyve
  • qemu-tools

Doing this requires you to setup vm-bhyve, which I'm not going to get into.

Centos8 OS template

Create a file named centos8.conf. Put this file in vm_dir path underneath ".templates".

loader="uefi"
cpu=1
memory=512M
network0_type="virtio-net"
network0_switch="public"
disk0_name="disk0"
disk0_dev="sparse-zvol"
disk0_type="virtio-blk"

Installation

Running vm img url will download and decompress the image and put it in the proper path. The path is vm_dir defined in /etc/rc.conf underneath sub directory ".img". At the time 8.4 was the latest image provided. However after install it instantly prompted me to upgrade to OS version 8.5.

Download image

vm img https://github.com/home-assistant/operating-system/releases/download/8.4/haos_ova-8.4.qcow2.xz

Create virtual machine

Now we create the virtual machine running vm create. The -t centos8 defines the template created earlier. The -c 2 refers to how many cores you want to assign to the virtual machine. The -m 8G is the amount of ram, 4G should be sufficient. Checkout the Home Assistant webpage for the required specifications. The -s 100G is the amount of disk space you want to assign to the virtual machine. First time I set this up I setup only 50G which should be more then sufficient. However I use sparse zfs since it's not going to use the 100G all at once I might as well define more.

vm create -t centos8 -c 2 -m 8G -s 100G -i haos_ova-8.4.qcow2 haos

Side note

For some reason the first time I run this command sometimes it gives me a disk busy error.

qemu-img: /dev/zvol/tank/bhyve/haos/disk0: error while creating output image: Protocol driver 'host_device' does not support image creation, and opening the image failed: Could not open '/dev/zvol/tank/bhyve/haos/disk0': Device busy
/usr/local/sbin/vm: ERROR: failed to write img file with qemu-img

Destroying the vm and doing it again creates the machine.

vm destroy haos

Then run the vm create command again and it creates. If this problem persists you could change the template to use disk images rather then zfs. Never had this error with disk images. There's also an option to provide a public key for authentication with -C -k your_key.pub. But there's no information on that in the current man page. And I'm not sure as how that works. At least can't seem to find it in the man page. With -n flag you should be able to parameterize a static IP. Also not in the man page checking the github vm-core source. I was able to find.

Example netconfig param: "ip=10.0.0.2/24;gateway=10.0.0.1;nameservers=1.1.1.1,8.8.8.8"

I wish they would able you to parameterize to select which network switch you'd want to use. But it seems that this is not in there.

Finalizing

Check the configuration

Finalize the configuration by running vm configure. In particular check if the VM is connected to the right vm switch

vm configure haos

Running the VM

Run the machine by running vm start

vm start haos

Monitor the startup by running vm console

vm console haos