Can you use a qemu disk image to boot an lxd vm?

I have been trying to figure out how or even if it’s possible to use a qemu disk image that I created with packer to boot an lxd vm.

I did read on another forum post that a method to try is to create init a vm with the --epmty option and possibly switch out the drives and boot the vm. I’m not sure on how to even make that work.

So If I create a raw qemu image with packer of ubuntu 18.04. Could I some how boot that with lxd and if so how?

Probably take a look at this topic:

So if you have the raw image, first create an empty container and then copy it to that location (adjust the path according to your setup).
Note: I did not try this.

1 Like

When I do this and try to boot the vm… I get this

lxc init consul-server --empty --vm -c limits.cpu=2 -c limits.memory=4GB
Creating consul-server

I move the image to the virtual machine location :
/var/snap/lxd/common/lxd/storage-pools/lxd_storage/virtual-machines/consul-server# ls
consul-server-1591076437.img

Error: Failed to run: zfs mount lxd_storage/virtual-machines/consul-server: cannot mount ‘/var/snap/lxd/common/lxd/storage-pools/lxd_storage/virtual-machines/consul-server’: directory is not empty

If your image is a compressed qcow2, you could also just import it as an image with lxc image import META IMAGE --alias NAME.

You’ll need to create a small metadata tarball though which contains the metadata.yaml file that LXD expects for all images.

That was it. I did have a compressed qemu image and was able to import the image after tarballing the metadata.yaml and boot it. Thank you!

How would I set the image type for the imported image? The import works for me but the image is of type container and I can’t use it for a VM. I tried with type: virtual-machine in the metadata.yaml file to no avail.

For lxc image import, the server bases it on whether the multipart stream had a rootfs.img member in it. On the CLI front, this gets set if the image file has a .qcow2 extension.

1 Like