I need to make one change to the above approach of editing /etc/ufw/before.rules… This works but the ip address for the virtual machine must be set inside Home Assistant. When the router’s dhcp server assigned the ip address, I couldn’t access the virtual machine from the network. The reason seemed to be that the host’s ufw is an enabled on start up and prevented the guest from getting an ip address. This rendered the edits to /etc/ufw/before.rules ineffective. The solution was to assign a static ip address inside Home Assistant.
I like this solution better than disabling netfilter on the bridge. I’m no networking expert, but that sounds like an invitation to all sorts of security problems.
Damn, make sure you downloaded the ova image, I spent whole night dealing with UEFI unable to boot from drive and figured this morning that I downloaded the aarch64 image as I am migrating from rpi4…
Hello,
just build HAOS on kvm (I am newbie to kvm). Thanks. Great work.
In the article a storage pool is created and - as far as I can see - not used.
My idea is to have a storage for all config data that will stay when the image is updated.
So does anybody has done this?
Any recipes?
As I understood it, making a storage pool of type dir means you can host image files, like the *.qcow2 file that is the HAOS image (but I might be wrong).
The guide makes the storage pool at /var/lib/libvirt/images/hassos-vm, then extracts the haos_ova-6.6-qcow2 image in that location before virt-install. Again, as I understood it, this is needed in order to “run” the image from that location.
I’m not sure exactly what “config data” you mean (just what’s in the old config directory?). You typically don’t “update the image” as such, you just update from within HA UI with a click (both core and OS), and here all “config data” stays anyway.
If you really want to re-install the image following this guide (the only situation where you would need the “config data” outside of the image itself), the easiest way is just to do that, and then “restore from backup” (assuming you do routine backups from HA UI, which you really should!).
I can live very well with the idea having a VM which I can upgrade from within.
Looking at /var/lib/libvirt/images/hassos-vm I only can see the qcow2 image I downloaded.
So my idea is that kvm uses this image as the disc space for the VM.
Which is OK for me.
My thought was that the (docker-like) idea was to have
an image with HAOS + storage for config stuff. Upgrading via change of HAOS image.
If “pure” Docker is your preferred approach, then it’s easy enough to do that without the VM.
HAOS basically just gives you less flexibility (slightly less control and fewer things you can do) in exchange for slightly less hands-on maintenance and less chance to screw something up if you don’t know what you’re doing. It’s up to you what works best for you, but I have found very few things (but a few, to be fair!) I wanted that the OS could not provide. And after having kids, I just have less time to stay on top of things, so the convenience is worth it for me these days.
If it’s because you’d want to automate updates (e.g., at night or when the home is empty and HA downtime is acceptable), you can do that from Home Assistant in a VM as easy as (probably easier than) setting a cron for docker image update.
An example automation (can be built in UI, no need for yaml):
description: "Update HA Core at night"
mode: single
trigger:
- platform: state
entity_id:
- update.home_assistant_core_update
to: "on"
action:
- wait_for_trigger:
- platform: time
at: "01:11:00"
- service: update.install
target:
entity_id: update.home_assistant_core_update
data:
backup: false
This will update core at 01:11:00 if an update is available. Replace update.home_assistant_core_update with update.home_assistant_operating_system_update to update the OS and with update.home_assistant_supervisor_update to update the supervisor.
Thanks for an awesome guide, I found it yesterday evening after a full day of struggling with other ways to install HA. But now in morning time after less than 3h I have HA installed and running but not yet “onboarded”.
My hardware is a Mac Mini (Mid 2011), that I had on the shelf, with a freshly installed Ubuntu Server 22.04.4 LTS. I used the latest HA KVM file to date called haos_ova-12.1.qcow2.xz. This will be my second instance of HA that will located in a summerhouse.
What I did on my Mac/Ubuntu server before starting on this guide:
Installed drivers for wifi, not configured yet as I run on ethernet currently - probably it will stay that way too. I guess this is due to the hw being a bit outdated…
Installed bluez/bluetooth and set it up.
Installed docker, according to this guide. To me unclear if it is needed but I see some docker commands in step 2.1, so I guess so.
Later I plan to buy a Zigbee controller (most likely a Sonoff) and add it to this HA instance.
So far - the only observed annoyance is that it seems to a bit longer (2-4 min) to boot the Ubuntu server due to a wait for Network to be Configured. This wait was not there before completing this guide.
i was also having same issues while passing the internal Bluetooth adapter of host pc to homeassistant vm instance and like you did i had detach and reattach Bluetooth adapter like you did.
to avoid doing it manually every often i used systemd-run to run the commands every six hours. this seems to have solved the adapter becoming unavailable for the time being. Granted the solution is a cheeky one.
Thank you for this brilliant post. This worked quite well for me on my Arch server, with some minor modifications.
One strong suggestion is to not run HAOS as root. While the VM should contain the guest in theory, bugs do sometimes exist, and there is no strong reason for the host to need root access. As a point of comparison, I installed several other services on my server (as bare metal), and on installation, the package manager would automatically create a new user to run the programs. These include nextcloud, tt-rss, airsonic, navidrome, nagios, prosody. For HassOS, I created a new user (hass), added it to the libvirt and kvm groups, installed the image to /home/hass/hassos-vm, and ran everything like sudo /usr/bin/runuser -u hass -- virsh start hass. This worked perfectly fine.
FWIW I also found I didn’t need to do turn off the firewall in docker. I’m not really sure why this would be necessary, since HAOS/KVM doesn’t work in a docker instance.
Also, I connect to the network with systemd-networkd, so I used the instructions on the Arch wiki to create the bridge. This also worked well.
In response to this question:
NOTE: I assigned a DHCP of 192.168.1.115, the same IP I set for the br0. I’m not certain that it is required to do both. If anyone tries this, could you please report back so I can update?
I used different IPs, and this worked. The br0 IP will connect to the host. You can also set a different static IP for the HAOS guest. You probably want two different IPs here anyway.
Not needed, the steps that mention Docker in the guide are just needed in case you do have Docker installed as I, and many others do (the main reason to do a VM on Ubuntu is that the server can the also be used for other things).
The vm started nicely with console output. Pro tip for “Escape character is ^]” for european layouts: On my swedish apple keyboard this corresponds to ctrl+å.
I started off trying to make a snapshot of the vm but got this error:
sudo virsh snapshot-create-as haos snapshot_1 --description "Initial snapshot"
error: Operation not supported: internal snapshots of a VM with pflash based firmware are not supported
After a quick search it seems this is due to the UEFI firmware…? Okay… but how do you guys take snapshots?
Actually, I never set up snapshots. I’ve just set up automatic backup from within HA, and hooked that up to my Nextcloud (using this addon). I also tried restoring a newly installed VM from that backup, and it was very painless.
So sorry, no help other than that I’d set up automatic backups from within HA if you can’t do VM snapshots.
Newb, anyone know if this bridge instruction works with Ubuntu 24.04? kvm is installed with virtual manager, things look a little different in /etc/netplan, but similar. Mines eno1, i can do the haos install with the GUI, after the bridge is setup. So many guides out there. Already failed using NAT with haos and not knowing any better.
I haven’t tried 24.04, so no real insight here. But I don’t know of any specific reason why it shouldn’t work. If you try, please let us know how it does.