Skip to content

Instantly share code, notes, and snippets.

@dsbaars
Last active January 4, 2024 15:40
Show Gist options
  • Select an option

  • Save dsbaars/82a31303f50da08edb422fdc15031257 to your computer and use it in GitHub Desktop.

Select an option

Save dsbaars/82a31303f50da08edb422fdc15031257 to your computer and use it in GitHub Desktop.
Home Assistant with Supervisor on KVM (Ubuntu 20.04 and libvirt)
# Install dependencies
sudo apt install --no-install-recommends qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils ovmf
# See netplan config below, apply with "sudo netplan apply"
# If you already have docker running, your bridge might not work as expected because it manages your iptables rules in a way which causes problems with forwarding, below command will fix that
sudo iptables -P FORWARD ACCEPT
# Install HassOS with the QCOW2 image from https://www.home-assistant.io/hassio/installation/#alternative-install-on-a-generic-linux-host
# The below command also allows you to log in using VNC, useful for debugging
sudo virt-install --name hassos --graphics vnc,listen=0.0.0.0 --memory=2048 --vcpus=2 --disk=/var/homeassistant/hassos_ova-4.11.qcow2,format=qcow2 --boot uefi --import --os-variant=debian9 --network=bridge=br0
# ------------
# ATTACH USB DEVICES (e.g. zwave)
# -----------
# See zwave.xml below for an example
virsh attach-device hassos --file zwave.xml --persistent
# ------------
# RESIZE IMAGE
# -----------
# The default disk size is only 5 GB, you can extend it with the commands below
# 1) Show all partitions in the QCOW2 image, you probably want /dev/sda8 but make sure you do
sudo virt-filesystems -l -h --all -a hassos_ova-4.11.qcow2
# 2) Resize image, below will increase with 5GB
sudo qemu-img resize hassos_ova-4.11.qcow2 +5G
# 3) Make a copy of the image (required for next step)
cp hassos_ova-4.11.qcow2 hassos_ova-4.11-orig.qcow2
# 4) Resize, this might take a while
sudo virt-resize --expand /dev/sda8 hassos_ova-4.11-orig.qcow2 hassos_ova-4.11.qcow2
# 5) Check if everything went as expected
sudo virt-filesystems -l -h --all -a hassos_ova-4.11.qcow2
# This is the network config written by 'subiquity'
network:
renderer: networkd
ethernets:
eth0:
dhcp4: no
version: 2
bridges:
br0:
dhcp4: yes
addresses:
- 192.168.24.189/24 # this allows you to have both a dynamic and static IP, omit if desired
interfaces:
- eth0
parameters:
forward-delay: 0
stp: true # I want this, but not everyone does
<hostdev mode='subsystem' type='usb' managed='yes'>
<source>
<vendor id='0x0658'/>
<product id='0x0200'/>
</source>
</hostdev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment