Here is how to create a cloud-init disk image and OS disk image suitable for configuring into a libvirt domain file.
In my case I am naming my domain (a.k.a. virtual machine or VM) xenial
with a static IP address of 192.168.0.101
.
The filenames "network-config" and "user-data" files are arbitrary, so they can be named with a prefix for the domain, etc.
First, get the cloud image and convert into QCOW2 format:
qemu-img convert -O qcow2 xenial-server-cloudimg-amd64-disk1.img xenial-server-cloudimg-amd64-disk1.qcow2
and extend the image size, which will become the root volume:
qemu-img resize xenial-server-cloudimg-amd64-disk1.qcow2 +8G
QCOW is a copy-on-write, differential image structure, so create an image relative to the base distribution image:
qemu-img create -f qcow2 -b xenial-server-cloudimg-amd64-disk1.qcow2 xenial.qcow2
Create the cloud-init datasource (DS) image:
cloud-localds -N network-config.yml xenial-user-data.img user-data.yml
Place all of those images in /var/lib/libvirt/images
and create the domain:
virsh create domain.xml
Now you can attach to the console of the domain and log in with the pass configured in user-data
:
virsh console xenial