Earlier we looked at how we could use Ubuntu cloud images with KVM. Now we will use the libvirt cli virsh and virt-install to do the same process. virt-install is a part of the virt-manager supporting tools.
Fetch the Ubuntu Cloud image
This only need to be done once, or when you want to update the cloud image.
- Download a Ubuntu Focal image from Ubuntu Cloud Images.
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img - Create an empty image in the default storage pool. This is a storage space where we upload the cloud image. Note that we use the correct postfix on the name here.
virsh vol-create-as default focal-server-cloudimg-amd64.qcow2 20G - Upload the downloaded cloud image to the storage pool in the reserved spaced.
virsh vol-upload focal-server-cloudimg-amd64.qcow2 focal-server-cloudimg-amd64.img --sparse --pool default
Create the VM
Now we use the cloud image as a template for all our new VMs. Change the size and virt-install parameters to make it your own.