Home Assistant running natively on FreeBSD via bhyve

This is is mostly written after-the-fact without good notes.

Much of what I’m writing is pulled from a tweet and from things I did as I later copied this VM from one host to another.

In this post:

  • FreeBSD 13.1
  • vm-bhyve-1.5.
  • edk2-bhyve-g202202_1
  • qemu-7.2.0

Much of what I’m doing is based up David Reid’s blog post: Home Assistant on FreeBSD. I recommend reading his blog post and using updated values, perhaps from my post, for downloads etc.

install and config

I installed this:

sudo pkg install vm-bhyve edk2-bhyve qemu

I set these configuration items:

sudo sysrc vm_enable=”YES” vm_dir=”zfs:data02/vm” vm_list=”hass”

Which look like this:

[r730-01 dvl ~] % grep vm /etc/rc.conf
vm_enable="YES"
vm_dir="zfs:data02/vm"
vm_list="hass"

data02/vm is the ZFS dataset where I will be storing my VMs

For downloading the HA image, this is what I see I have:

[slocum dan ~/tmp] % sudo vm img
DATASTORE           FILENAME
default             haos_ova-9.3.qcow2
default             haos_ova-9.3.qcow2.xz

I think I issued this command: sudo vm create -t debian -c 4 -s 200G -m 4GB -i haos_ova-9.3.qcow2

This is what I have:

[slocum dan ~/tmp] % sudo vm list -v
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC  AUTO   %CPU       RSZ          UPTIME  STATE
hass            default    uefi       4    4GB     -    No      5.1      3.0G        19:38:17  Running (11263)
home-assistant  default    uefi       1    1GB     -    No        -         -               -  Stopped
myguest         default    bhyveload  1    768M    -    No        -         -               -  Stopped
[slocum dan /usr/local/vm/hass] % cat hass.conf
loader="uefi"
cpu="4"
memory="4GB"
network0_type="virtio-net"
network0_switch="public"
disk0_type="nvme"
disk0_name="disk0.img"
grub_run_partition="1"
grub_run_dir="/boot/grub"
uuid="9aae377a-6c06-[redacted]"
network0_mac="58:[redacted]"

EDIT: ON 2023-03-01 I changed disk0_type from ahci-hd to nvme (as shown above) because on FreeBSD, it’s faster. My thanks to Ben Woods for his suggestion.

After getting the VM started, I followed: https://www.home-assistant.io/getting-started/onboarding

Eventually, http://home-assistant.example.org:8123/ worked for me

Copying from one host to another

To copy this host over, I ran stopped the VM via sudo vm stop hass and then used syncoid to transfer the datasets.

On the new host, I tried to start the vm:

[r730-01 dvl ~] % sudo vm start hass
Starting hass
  * found guest in /usr/local/vm/hass
  ! guest appears to be running already

Eh?

[r730-01 dvl ~] % sudo vm list -v
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC  AUTO      %CPU       RSZ          UPTIME  STATE
hass            default    uefi       4    4GB     -    Yes [1]      -         -               -  Locked (slocum.int.unixathome.org)
home-assistant  default    uefi       1    1GB     -    No           -         -               -  Stopped
myguest         default    bhyveload  1    768M    -    No           -         -               -  Stopped

Ahah!

Run another syncoid.

Then:

[r730-01 dvl ~] % sudo vm list -v
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC  AUTO      %CPU       RSZ          UPTIME  STATE
hass            default    uefi       4    4GB     -    Yes [1]      -         -               -  Stopped
home-assistant  default    uefi       1    1GB     -    No           -         -               -  Stopped
myguest         default    bhyveload  1    768M    -    No           -         -               -  Stopped

Next time: wait for the stop to complete before copying over the dataset.

Getting it running

Let’s start this up:

[r730-01 dvl ~] % sudo vm start hass
Starting hass
  * found guest in /usr/local/vm/hass
  * booting...

Much better.

[r730-01 dvl ~] % sudo vm list -v
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC  AUTO      %CPU       RSZ          UPTIME  STATE
hass            default    uefi       4    4GB     -    Yes [1]      -         -               -  Stopped
home-assistant  default    uefi       1    1GB     -    No           -         -               -  Stopped
myguest         default    bhyveload  1    768M    -    No           -         -               -  Stopped

Not so better.

I thought a bit.

New host, never had VM enabled/started before. Let’s try starting the service:

[r730-01 dvl ~] % sudo service vm start
/usr/local/sbin/vm: ERROR: failed to add member ix2 to the virtual switch public

Ahh, a different NIC on this host. That should be igb0.

After searching for that string, I found it here:

[r730-01 dvl /usr/local/vm] % cat .config/system.conf
switch_list="public"
type_public="standard"
ports_public="ix2"

After changing that to the right value:

[r730-01 dvl /usr/local/vm] % sudo service vm start
[r730-01 dvl /usr/local/vm] % sudo vm list -v
NAME            DATASTORE  LOADER     CPU  MEMORY  VNC  AUTO      %CPU       RSZ          UPTIME  STATE
hass            default    uefi       4    4GB     -    Yes [1]    2.7      1.9G           04:29  Running (17386)
home-assistant  default    uefi       1    1GB     -    No           -         -               -  Stopped
myguest         default    bhyveload  1    768M    -    No           -         -               -  Stopped

I could not connect to the web interface. I found out why later.

I already have a bridge

I already have a bridge. It’s created by the pkg01 jail, which is a vnet jail:

igb0bridge: flags=8843 metric 0 mtu 1500
	ether 58:9c:fc:10:8c:57
	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: e0a_pkg01 flags=143
	        ifmaxaddr 0 port 15 priority 128 path cost 2000
	member: igb0 flags=143
	        ifmaxaddr 0 port 1 priority 128 path cost 20000
	groups: bridge
	nd6 options=9

The solution, mentioned in this issue: manual switches.

I did this, where igb0bridge is taken from the above output:

# vm stop hass

Wait until it is stopped.

Then:

# vm switch destroy public
# vm switch create -t manual -b igb0bridge  public
# ifconfig igb0bridge
igb0bridge: flags=8843 metric 0 mtu 1500
	ether 58:9c:fc:10:8c:57
	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: e0a_pkg01 flags=143
	        ifmaxaddr 0 port 15 priority 128 path cost 2000
	member: igb0 flags=143
	        ifmaxaddr 0 port 1 priority 128 path cost 20000
	groups: bridge vm-switch viid-4c918@
	nd6 options=9

See how the groups have changed.

Now my system.conf looks like this:

# cat system.conf 
switch_list="public"
type_public="manual"
bridge_public="igb0bridge"

Time will tell if this survives a reboot.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

6 thoughts on “Home Assistant running natively on FreeBSD via bhyve”

  1. Hi Dan.
    Any chance of passing a USB dongle to the VM?
    Been fighting with HA for hours to try running it on a Jail, and finally done the VM way
    But.. no USB passthrough. So things got more complicated.

  2. Thanks for the excellent writeup. Whenever I try this approach, I get the same error with any version of the image I download:

    # vm image create -d hass haos_ova-10.3.qcow2
    /usr/local/sbin/vm: ERROR: haos_ova-10.3.qcow2 does not appear to be a valid virtual machine

    Am I missing a step, or perhaps a versioning issue?

Leave a Comment

Scroll to Top