Create Proxmox cloud-init template
In this article, I’ll demonstrate how to create a cloud-init enabled Ubuntu 20.04 LTS base image to use on Proxmox VE.
Cloud Native Image
The tradition packer builder to build a base image from an ISO file. Modern Linux distributions are increasingly moving away from this install method and preseed files. Rather, disk images are provided with the OS pre-installed, and configuration is performed via cloud-init. We will create a Proxmox KVM base image using Ubuntu’s KVM cloud image.
The Proxmox API doesn’t appear to offer the full functionality provided by the native shell commands to create a template, so we will run a script via SSH or Proxmox node’s GUI shell.
The Script you can found on my GitHub. There is the Link.
The below sections, I will explain this Script step by steps.
Step 1: Download the image
We are downloading the kvm disk image.
Note: This is a qcow2 image format with an extension of .img, Promxox doesn’t like this so we rename the disk image to .qcow2
Step 2: Add QEMU Guest Agent
The Ubuntu 20.04 image we are going to use does not include the qemu-guest-agent package which is needed for the Guest VM to report its IP details back to Proxmox. This is required for Packer to communicate with the VM after cloning. The template. libguestfs-tools will allow us to embed qemu-guest-agent into the image. You can also add any additional packages you’d like in your base image. Personally, I prefer to customize this base image later with packer so that the packages can live in source control.
Step 3: Create a VM in Proxmox with required settings and convert to template
For best performance, virtio “hardware” should be used. Additionally, cloud-init requires a serial console and cloudinit IDE (CDROM) drive. We will set the network config to DHCP so that we get an IP address. Lastly, we will expand the template disk image size so we have space to install items later. It appears packer doesn’t support doing this later.
you will need to change the user name, password, and add the ssh public key so we can connect to the VM later using Ansible and terraform. update the variables and click on Regenerate Image