Install Home Assistant OS with KVM on Ubuntu headless (CLI only)

@ha_steve: I was going to update the guide to include this part as soon as I’ve done it in practice. But I’ll throw in the notes I have for now (so no guarantees, I haven’t done this myself yet).

Guide taken mostly from here.

(Of course, adjust the ID’s and paths as needed for your system.)

Find the idVendor and idProduct of the USB device you want to attach.

lsusb -v

A few examples from my system, an Aeotec Z-wave:

  idVendor           0x0658 Sigma Designs, Inc.
  idProduct          0x0200 Aeotec Z-Stick Gen5 (ZW090) - UZB

And a ConBeeII stick:

  idVendor           0x1cf1 Dresden Elektronik
  idProduct          0x0030

[NOTE] Can also be attached using device address on host, though that might change if they are unplugged or host is rebooted.

EDIT I think you need one file per USB device. Below I have used the ConBeeII stick as an example.

With the above, create an xml file:

sudo nano /var/lib/libvirt/images/hassos-vm/conbeeii.xml

And insert

<hostdev mode='subsystem' type='usb' managed='yes'>
  <source>
    <vendor id='0x1cf1'/>
    <product id='0x0030'/>
  </source>
</hostdev>

[NOTE] - the “managed=‘yes’” makes it behave as if “nodedev-detach” and “nodedev-reattach” had been called at correct times, so you shouldn’t need to do anything else.

Then you can attach USB devices using virsh

virsh attach-device hassos --file /var/lib/libvirt/images/hassos-vm/conbeeii.xml --persistent

[Note] use “virsh detach-device [DOMAIN] [FILE]” to detach, where it will reattach again upon next boot. Add “–persistent” to this, to make the detach persistent.

4 Likes

@Aephir - thanks for this! I have it working now!

One additional question. Do you have a way of connecting to the console?

Good to hear, and thanks for being guinea pig before I had to test on my own! That gives me a little peace of mind before pulling the plug, and moving my old (unsupervised) Docker setup to a shiny new VM :slightly_smiling_face:

I use the “SSH and Web Terminal” add-on for what I need in HassOS, would that work for your needs?

I have followed all this tutorial step by step, and at the end I get an error:

Error: --boot uefi: Don't know how to setup UEFI for arch 'i686'

What can I do now? Im using an Asus Laptop (1201ha) and even if it has BIOS vt support, it’s a 32 bits machine… any workaround?

Update: I’m trying with: --archx86_64 but now i get:

Error validating install location: Distro 'rhel8.1' does not exist in our dictionary

I see with osinfo-query os many of them, rhel from 12.1 to 17.5, and doesn’t matter what i use, I got the same error over and over again :frowning:

By the way I’m using minimal ubuntu 18.4 for 32 bits, since my laptop is kinda old.

First off, I have no idea if it works on 32 bit, I guess I should specify that. But I’d be interested to see if it does!

Secondly, I might have made a typo in the guide (copied the wrong command after testing a few different ones). Try installing without specifying the os-type, so use the below instead of step 3 in guide:

cd /var/lib/libvirt/images/hassos-vm
virt-install --import --name hassos \
--memory 2048 --vcpus 4 --cpu host \
--disk hassos.qcow2,format=qcow2,bus=virtio \
--network bridge=br0,model=virtio \
--graphics none \
--noautoconsole \
--boot uefi

Note that I also decreased the amount of RAM. If you run 32 bit version, you have a maximum of 4GB, and the base OS (Ubuntu) says minimum requirements is 2GB (well, I think that was for the desktop variant, so likely lower minimum requirements for CLI only. But not zero.). So I’ve only allowed 2 GB to the HassOS VM in the above.

Also remember you might need to change the vcpus if needed (depending on your CPU).

And @mabusdogma, please let me know if this works so I can fix the guide :slight_smile:

Sadly it does not work, I’ve changed everything as you said on your last comment and now I get this:

this kernel requires an x86-64 CPU, but only detects an i686 CPU, unable to boot

:frowning:

Maybe a workaround is to virtualize a RbPi 3 or something 32bits… I’ll try, I hope it works

I found this guide that says

… choose either Other Linux 32-bit or 64-bit depending of your system…

This one uses the VDI image. I’m not sure KVM supports this (?), but you might try one of the other images? Or maybe ask in the Discord channel, there might be a workaround (and old image that can then be updated once installed, or something like that?)

Thanks for this guide!

When I applied the netplan my ip address changed and I thought I had botched the config. So as hint to others: either specify an IP or double check the host ip before you re-install the OS :smiley:

Home Assistant is now running but I’m not sure what the best way to access the VM is. Using virsh console hassos doesn’t seem to work. Am I missing something obvious or do I have to install the ssh addon to get proper access?

The only solution I’ve found to enable the virsh console requires that you have access to the vm already so I don’t see a way around the ssh addon. Is that the way to do it?

Glad it helped.

I use the “SSH and Web Terminal" add on. It’s a "community add-on, that allows a bit more access than the default “Terminal & SSH”. I haven’t found (or indeed looked for) an alternative way to access. And to be honest, I haven’t been using supervised all that much. Is there a native way to access? I mean, if you flash HassOS on a RPi and plug in a monitor and keyboard, do you have shell access directly? If not, there might not be a way to do this in KVM.

And yes, I guess I should specify/recommend that a DHCP reservation is made for both the host machine and VM, to avoid any scares :slight_smile:

If the VM supports it you can run virsh console hassos to open a console into the image without having to configure SSH. It seems that hassos doesn’t have this activated and you need access to configure it. https://serverfault.com/questions/364895/virsh-vm-console-does-not-show-any-output

Either way, I guess I’ll use the addon.

edit:
Lessons learned for me:

  1. Executing netplan apply can cause you to lose your connection if you are doing it remotely. You may get a new ip address. I didn’t notice and thought I had botched the config.
  2. The hassio vm ip apparently can’t be configured via netplan. It should come from the vm itself (I think home assistant has it in settings menu) or from your dhcp server.
  3. The hassio image does not have a console you can use with virsh. If you want to enter the vm your best option is probably the home assistant ssh addon. From there you can potentially configure the kvm/quemu/virsh console.

What is the correct --os-variant ? is it really rhel8.1?

Oops, good catch. I think that was from an older copy-paste when testing, I can see I didn’t specify os-variant. Corrected in first post, thanks!

i think it makes sense to define the variant. the only thing you would need to know is which distribution the VM is based on.

Shouldn’t it be dhcp4: true instead of dhcp4: yes?

@broken.pipe As I understood, HassOS is not based on a single recognizable OS, but is made in some different (mashup?) way. If you know the OS version that would make sense, please let me know, and I’ll add it.

@revolter Either is fine, you can use true/false, y/n, yes/no, on/off interchangeably. Either all lower case, or with an initial capital or with all caps. It’s pretty forgiving (in that regard, at least) :slight_smile:

Thanks a lot for this nice guide!

With a few modifications i got this running in arch linux, however i got a question regarding the step where you add users to the libvirt and kvm groups.
Since i never saw this user mentioned outside of this step it looks to me that everything runs as root. In fact i just tried skipping this step and everything seems to run fine. Is this step really needed?

Another thing i noticed is that this guide was posted the same day home assistant 2020-12 got released. In this release the possibility to set up a static IP address from the UI was added. So you could change the IP by navigating to supervisor > system > host and click on change next to the IP Address.

I’m actually not sure about the adding user to groups; I’ve never tried without. It might be an Ubuntu-specific thing, but I added it to the guide (and did it when testing) because I read here (step 2) that

Only members of the libvirt and kvm user groups can run virtual machines.

Good point about the Hass UI config of IP. I’ll add that as an option in the guide (though I personally don’t like giving my machines static IPs, I’ve had too many issues when making changes to my network).

If you describe the modifications to use on arch, I’ll add a link to your post in the main guide. Otherwise I’d recommend doing a write up (feel free to copy anything of use from this guide) and post your own community guide.

Unfortunately i can’t boot the virtual machine. i opened a bug report here: HA not booting in KVM · Issue #1339 · home-assistant/operating-system · GitHub

virsh console home-assistant
Connected to domain 'home-assistant'
Escape character is ^] (Ctrl + ])
BdsDxe: loading Boot0001 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x0)
BdsDxe: starting Boot0001 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x0)


barebox 2020.04.0 #1 Thu Apr 1 15:58:01 UTC 2021


Board: barebox EFI payload
EFI v2.70 by EDK II v65536
EFI Event timer too slow freq = 100 Hz
acpi2: Found XSDT (OEM: BOCHS BX) with 4 entries
efi-fs handle-000000007e9cbb98: mounted on /boot
malloc space: 0x30000000 -> 0x3fffffff (size 256 MiB)
state: New state registered 'state'
state: Using bucket 0@0x00000000
description: UEFI Misc Device
path: pci_root(0)/Pci(0x1,0x2)/Pci(0x0,0x0)
description: EFI Internal Shell
path: Path(132,7,0xc9bdb87cebf8344faaea3ee4af6516a10000000084061800)/Path(132,6,0x83a5047c3e9e1c4fad65e05268d0b4d100000000ffff0800)
environment load /efivars/barebox-env-5b91f69c-8b88-4a2b-9269-5f1d802b5175: No such file or directory
Maybe you have to create the partition.
running /env/bin/init...
- Hit m for menu or wait for autoboot -
Booting entry 'bootchooser'
Booting entry 'system0'
ext4 ext40: EXT2 rev 1, inode_size 128, descriptor size 32

Loading MS-DOS executable '/mnt/system/bzImage'

Ok, i recreated everything in Cockpit and it’s working now … strange. I only virsh edited the loader line and added the ovmf firmware for uefi loading

Good to hear! And sorry, but I don’t have any good ideas why it didn’t. You did try without specifying the OS, right?

In any case, if you find out what the issue is, please let me know so I can change the guide, or add a disclaimer for specific circumstances.