Home Assistant with VirtualBox or Proxmox or Ubuntu KVM ???

After testing Home Assistant (HA) for a while, I’ve realised it could improve my home automation, despite that I'm using Apple HomeKit.

When I tested HA with Node-RED and some other "Add-ons", on a Raspberry Pi 3 (RPi), I found that its resources wasn’t enough.

The following setup could be any computer but I recently bought an Apple Mac Mini M4, replacing my 2018 (M18) model, so the M18 was really a great candidate for my HA setup.

The preferred method running HA is through the HA Operating System (HAOS), which makes your "life" easier. 😉

Intro
If you are new to HA here you find some of my thoughts to start up.

So how to run HAOS on your hardware ?

My first consideration was that I didn't want to allocate all the M18 resources running just HA so I started checking how Virtual Machines(VM) work. There are VM:s for Mac OS but if you want to optimize the resources there is other ways. I have already installed Ubuntu Desktop on an old Mac and there a learned a lot.

After extensive research I believe that ChatGPT provided a comprehensive and insightful conclusion to this matter.

Option Verdict Notes
Ubuntu + VirtualBox ⚠️ OK, but not ideal Easy to set up but adds overhead and complexity. Not designed for 24/7 VM hosting.
Ubuntu + KVM/QEMU  Better Much more efficient and stable. Keep Ubuntu and get near-Proxmox performance.
Proxmox VE directly ✅✅ Best Maximum performance, ideal for always-on services, no desktop bloat. Most professional setup.

Proxmox seems to be the best variant but then the Host OS will be their own.(A Debian variant)

So my choice was erasing the M18:s, could also be any standard Intel hardware, hard disc and then installing Ubuntu Desktop 24.04 LTS with Linux KVM(KVM).

The M18 will run headless and I will use RDP for remote access.

Installation
Check HW
After the Ubuntu installation, running something else than a M18, check if your hardware can handle KVM. In a terminal use "egrep -c '(vmx|svm)' /proc/cpuinfo". If the result is >= 1 it's OK to proceed.

Ethernet interface
Use command "ip addr" to get the ethernet interface info and, among other interfaces, something like this will show
:
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 68:fe:f7:0c:ae:f9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.68.124/24 brd 192.168.68.255 scope global dynamic noprefixroute enp4s0
:

write down the interface name matching your info. (In my case "enp4s0")

Install KVM and Virtual manager
Start with an update "sudo apt update" and then install
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
Add logged-in user to KVM and libvirt
sudo adduser $USER libvirt && sudo adduser $USER kvm

Download image
Download the HAOS KVM image, "*.qcow2" and extract it.
The default location for KVM images is "/var/lib/libvirt/images" so it could be a good place to move it to. Check with "virsh pool-list --all" and then with "virsh pool-dumpxml default
get the path.

From the "Download" folder use something like "sudo mv haos_ova-16.1.qcow2 /var/lib/libvirt/images/"

The VM
In the "Applications menu", search for "Virtual Machine Manager", start the application and then; 
  • Click "Create a new virtual machine".
  • Select "Import existing disk image", click on "Forward"
  • Provide the path to the "qcow2" image above
  • Chose OS typing "Generic...." and pick "Generic or unknown OS. Usage is not recommended.", click on "Forward"
  • Add "Memory => 4096", "CPUs => 2", click on "Forward"
  • Add "Name => HA
  • Check the box for "Customize configuration before install", click on "Finish"
  • Under "Overview =>Firmware" Select; 
    • "UEFI x86_64:/usr/share/OVMF/OVMF_CODE_4M.fd"
Make sure to select a non-secureboot version of OVMF (does not contain the word secure, secboot, etc.)
  • Under "NIC...." => "Network source => Macvtap"
  • "Device name" => The interface name retrieved above.(In my case "enp4s0"), "Device model => e1000" + "Apply"
With this approach you don't have to bridge the network interface !!!! But if you want to communicate, ssh or other commands, between the host and the guest you have to create an isolated network. Se below.
  • Under "Boot options" check the box "Start virtual machine on.....", click on "Apply"
  • Click "Add Hardware" (bottom left) 
    • Size the disk image.
    • Under "Channel" select "Name => org.qemu.guest_agent.0."
    • Device type => UNIX socket (unix)", click on "Finish" and then "Apply"
  • Finally, select "Begin Installation"(upper left corner).
This shall startup HA and after a while it can be accessed at "http://homeassistant.local:8123"

2025-09. Remark regarding "Choose OS" above. With the HA file "haos_ova-16.1.qcow2" it also works with "Generic Linux 2022" and "Generic Linux 2024". But if you choose one of these you must check if the channel "Channel(qemu-ga)" already exist. If it does skip the creation above, otherwise you vill get an error "virtio-serial-bus: A port already exists by name org.qemu.guest_agent.0".

Bluetooth
In the mentioned M18 the Bluetooth receiver is a PCIe, not an USB, connected one. 
PCI passthrough is complex, risky, and would passthrough both Wi-Fi and Bluetooth, possibly breaking network on your host. The recommended solution is to use a Bluetooth Proxy 
or 
buying a USB Bluetooth adapter approved by HA and then using a USB passthrough to the guest.

Isolated network
Using the "Macvtype" network source makes the setup very simple compared to the "Bridged" type but, as said, to communicate between host and guests, and vice versa, the best is to create a isolated network.

On the host create a file with "nano /tmp/isolated.xml" and add

<network>
  <name>isolated</name>
  <ip address='192.168.254.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.254.2' end='192.168.254.254'/>
    </dhcp>
  </ip>
</network>

then 

virsh net-define /tmp/isolated.xml && virsh net-autostart isolated && virsh net-start isolated

Edit the HA guest with "virsh edit HA" and add, in the "<devices>" section, just below the "direct" interface

<interface type='network'>
  <source network='isolated'/>
  <model type='virtio'/>
</interface>

Restart the guest with "virsh shutdown HA && virsh start HA" and verify that HA have 2 active interfaces with "virsh domiflist HA". Check the IP adress with "virsh net-dhcp-leases isolated" or in a HA ssh session "ha network info"

Disk handling
Disk space HA guest
To minimize the disk space used by HA you can do an image conversion. The empty sectors are detected and suppressed from the destination image.

Check your case, after "sudo virsh shutdown HA", with something like 
sudo qemu-img info /var/lib/libvirt/images/haos_ova-15.2.qcow2
Before the conversion I renamed the file with
sudo mv /var/lib/libvirt/images/haos_ova-15.2.qcow2 /var/lib/libvirt/images/haos_ova-15.2.qcow2.bup
Then the actual conversion with 
sudo qemu-img convert -O qcow2 /var/lib/libvirt/images/haos_ova-15.2.qcow2.bup /var/lib/libvirt/images/haos_ova-15.2.qcow2
then start the guest with virsh start HA

In my case the "disk size" went from 18 GB to 11GB

If you would like to decrease the "virtual size" I really would recommend to take a HA backup, create a new HA guest with the correct size and then make a restore. There are other ways but they are much more complicated and take longer time, trust me I have tried ....... 😅

Disk space Ubuntu guest
On the same hardware I also have an Ubuntu guest and when doing an update I got "You don't have enough free space in /var/cache/apt/archives/". Using command, on the guest, "df -h /home" confirmed that there was no space and it also showed the name of the filesystem "/dev/mapper/ubuntu--vg-ubuntu--lv".

Get rid of old stuff using "sudo apt autoremove && sudo apt clean" and check if this solves the problem. Otherwise use commands "lsblk" or "sudo pvs" checking if there is any available space left.

Add 2 GB with command
sudo lvextend -L+2G /dev/mapper/ubuntu--vg-ubuntu--lv -r
and check with "df -h /home".

Adding virtual disk
If there isn't any space left you have to increase the KVM disk image and here is additional info.

Backup
With the command "virsh list" you will list the KVM guests. To be sure which source file corresponds to respective guest use the command "virsh dumpxml guest_from_list" and then find the line " <source file=" which points to the location. Default location is "/var/lib/libvirt/images/" so confirm with "sudo ls -l /var/lib/libvirt/images/".
Shutdown the guest and copy the file to the backup server. With an established "ssh" session, to the backup server, it could be "scp /var/lib/libvirt/images/guest_from_list user@backupserver:"

The XML settings can be saved using "virsh dumpxml guest_from_list > guest_from_list.xml" and then moved to the backup server.

Then start the server again.

Additional KVM commands
List storage pools
virsh pool-list --all
Delete storage pool "example"
virsh pool-destroy example && virsh pool-undefine example
Save, backup, guest XML to file
virsh dumpxml guest1 > guest1.xml
Edit the XML configuration
virsh edit guest1
If the guest really "hangs" use 
sudo virsh destroy guest1

Remarks
Autostart after power failure
If running a standard Intel hardware this setup is probably made in the BIOS.

I'm running the M18 standalone and it's important that it autostarts after a power failure. Here is one article and I checked method 2 and 3. A way to start is checking, method 2, with command 

lspci | grep LPC
00:1f.0 ISA bridge: Intel Corporation Cannon Lake LPC Controller (rev 10)
sudo setpci -v -s 00:1f.0 0xa4.b
[sudo] password for "user":
0000:00:1f.0 @a4 = 00 => Set for autorestart

Or in Mac OS, method 3, check with 

pmset -g

System-wide power settings:

Currently in use:

 standby              0

 Sleep On Power Button 1

 autorestart          0   =>  Not set for autorestart 

 powernap             1

 networkoversleep     0

 disksleep            10

 sleep                1 (sleep prevented by powerd, bluetoothd)

 ttyskeepawake        1

 displaysleep         10

 tcpkeepalive         1

 lowpowermode         0

 womp                 1


and then change with "pmset autorestart 1"

If you are still on MacOS it's just "System Settings => Energy => Start up automatically after power failure".

Raspberry Pi
If running KVM on a Pi maybe this could help ?

HA releases

Comments

Popular posts, last 30 days

Raspberry Pi OS Lite with GUI, RDP, VNC, Chromium

iCloud drive sync, or mount, with a Linux, Ubuntu, device

Raspberry Pi 2, 3, 4, 5 USB SSD or USB drive boot

NetworkManager UI and access point, hotspot

Installing Ubuntu 24.04 or 24.10/25.04 on an old MacBook Air(2011)

Clone the Raspberry boot disk

Waveshare CAN hat with Signal K & OpenPlotter

Signal K charts, offline & online

Raspberry, restart network, or reboot, at ping failure