Import a qcow2 image to LXD

I recently learned how to make my own LXD VM image based on Home Assistant’s QCOW2 VM images. This blog post is a short write-up how to do that! This is of course useful for other qcow2 images as well.

Download a image

I downloaded the Home Assistant OS image in the qcow2 format, and uncompressed it. The image is intended for KVM, and LXD runs VM:s with Qemu/KVM so it’s a good fit for LXD VM:s.

1
2
$ wget https://github.com/home-assistant/operating-system/releases/download/7.1/haos_ova-7.1.qcow2.xz
$ xz -d haos_ova-7.1.qcow2.xz

Write a metadata.yaml file

LXD need some metadata, the format is documented here. A minimal example that I used for Home Assistant can be found below:

1
2
3
4
5
6
architecture: x86_64
creation_date: 1643062675
properties:
  description: Home Assistant OS 7.1
  os: HAOS
  release: 7

Save it as metadata.yaml, and make it a tarball with:

1
$ tar cf metadata.tar metadata.yaml

Import the image

Import the image as haos with an image import:

1
$ lxc image import metadata.tar haos_ova-7.1.qcow2 --alias haos

Launch it!

That’s all, now start it like any other VM with the --vm flag. LXD will only launch signed images with secure boot by default, to disable that add -c security.secureboot=false. The full command I used to launch this specific VM was:

1
2
3
4
$ lxc init haos homeassistant --vm \
  -c security.secureboot=false \
  -c limits.cpu=2 \
  -c limits.memory=4GiB

That’s all!