Steps to import qemu VM in LXD

Hi All,

I have a pipeline where I use packer to build VM templates. I like this because I can have the same provisioning (where I usually use Ansible) to create VMs for multiple hypervisors. I saw that there is an LXD builder for packer but it is really tight on LXD and it seems I would miss a lot of the common stuff that I’m used to setup (like the CD settings).

The main area is to create VM for Windows and I already have a working pipeline where I build Windows using the qemu builder and I was wondering if there was some steps that I could automate in order to create a post-processor for packer to export a qemu VM as a LXD image.

I saw Running virtual machines with LXD 4.0 where there is a section for creating Windows images but it starts from an empty VM and then it installs the OS directly in LXD.

From some other posts it seems possible to import such VM but I’m not able to find the documentation for the procedure or the metadata.yaml to use.

Can someone give some pointers?

First thing you’ll need to make sure that those VM images are using GPT and UEFI, then you’ll need to make sure that all the VirtIO drivers are integrated inside of them.

Once that’s all good, you’ll need a qcow2 version of that resulting image.
And you can feed that to LXD with lxc image import <tarball> <qcow2> --alias some-name

The tarball will likely just contain one file, metadata.yaml which is covered here Image handling - LXD documentation

In your case, you’d just need something like:

architecture: x86_64
creation_date: 1424284563
properties:
  description: Windows XYZ
  os: Windows
  release: XYZ
1 Like

I’ve never thanked you for. It indeed worked as expected!

Are there solutions going the other direction? Publish/Export lxd virtual machines for use with other systems (virt-manager/vmware)