Hi,
I have some updates to those instructions and more details why CPU usage may be higher and how to prevent that.
- First of all, the newest HassOS images (I use Hassos 15.2 image) have instructions to install headless and also the login with console works. So if you enter
virsh console <vmname>
, you can successfully connect to console and login as root without password. It shows nothing after connection, just press return one time to show the login prompt.
- If you follow the steps on the installation page of HASS and/or this howto, the VM has no soundcard with Ubuntu 24.04, so removing it is not required. Still the VM has high CPU usage as soon as you add zigbee devices by passing the stick as USB device. Actually I found out why this happens and what you can do!
Basically the problem is that the above instructions and also the ones from HASS installation manual create a VM with a very outdated hardware version using the Intel 440FX chipset. This has no PCI express and old USB 1.1/2 controllers that have large virtualization overhead.
To get an updated machine with modern hardware, you should pass “q35” as machine type when creating the machine (add --machine q35
to virt-install command line). You can change it later but it requires manual XML editing (removing all pci devices and addresses and waiting for libvirt to add them back). So it is better to add “pc-q35” as type from beginning. After you have done this, all is fast from beginning.
I still have another recommenadation: Instead of adding the USB sticks for zigbee as an USB device, it is better (and again faster) to just add a COM2 port to the VM instead of a USB device by passing the unqie device path to the config:
<serial type='dev'>
<source path='/dev/serial/by-id/usb-Itead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_V2_d00c11e35312ef1180786db8bf9df066-if00-port0'/>
<target type='isa-serial' port='1'>
<model name='isa-serial'/>
</target>
</serial>
Just replace the path and unique identifier of your device with the correct path for the host system; port=1 is the the port number (starting at 0, the console is 0).
I strongly recommend to not add a path like /dev/ttyS...
to the XML file, because the enumeration of COM ports changes depending on how fast the Linux kernel find the devices during booting the hypervisor! So check /dev/serial/by-id/
dircetory and copypaste the correct device file names and insert those as <source>
into the libvirt XML! This is different from the hardcoded ISA serial port slots, they are hardcoded, so inside the VM static names are fine (see below).
After that the VM sees a 2nd serial port that directly points to the zigbee stick. This has much less virtualization overhead especially for this heavy used device. After rebooting the VM, the current HassOS does not find the device anymore (because the USB device is going away). To fix this in ZHA, go to the Zigbee ZHA settings and it will automatically ask you to update the device path. Choose /dev/ttyS1
in popup window (this is the second com port, possibly adapt to the XML config if you have more devices).
Keep in mind, you can do this with all USB sticks that expose a serial interface. If you have more than 3, you can add more as “pci-serial” instead of “ide-serial”. The default IDE bus only supports up to 4 serial ports. The first one is for the console (virsh console <vm>
).
This last trick was inspired by Alternative KVM HAOS USB zigbee adapter config, but using “pci-serial” is not needed unless you have too many devices. This spares resources even more by using the default ISA serial controller on the emulated mainboard.
Basically you can implement both options (q35 machine OR isa-serial to pass zigbee), but it is enough to use one of the two options. I recomment to start with q35 machine type from the beginning and use the direct serial pass-through as extra non-mandatory optimization. IMHO, I like it more that the HassOS VM just uses hardcoded COM ports and the setup of WHICH device is added to which virtual COM port is done in the hypervisor outside of HASS. This makes it easier when you replace hardware. You just need to adapt the path to the serial port on the hypervisior’s XML file.
Uwe