Photo by CHUTTERSNAP / Unsplash

Creating an Ubuntu Cloud Template on Proxmox for Cloud-Init

Jul 24, 2022

Creating many Ubuntu VMs can be tedious is you're just looking to get a basic install to work off of. Cloud-Init allows you to specify certain aspects of a VM and apply them to a VM template.

To get started grab the latest cloud-init .img template from Ubuntu, I'll be using 20.04 for this guide

First, you can download the latest 20.04 KVM image from here: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img

wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img

Next we'll install the tooling needed

sudo apt update && sudo apt install libguestfs-tools -y

Once the install is done we can add the QEMU guest agent to the image

virt-customize -a jammy-server-cloudimg-amd64-disk-kvm.img --install qemu-guest-agent

Now that the guest agent is installed we can import the .img as a VM

qm create 9001 --name "Ubuntu-Focal-Cloud-Init" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
qm importdisk 9001 jammy-server-cloudimg-amd64-disk-kvm.img local-lvm

Now we need to set the VM's settings and convert it to a template

qm set 9001 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9001-disk-0
qm set 9001 --ide2 local-lvm:cloudinit
qm set 9001 --boot c --bootdisk scsi0
qm set 9001 --serial0 socket --vga serial0
qm set 9001 --agent enabled=1
qm template 9001

Now we can see that the template is configured:

If you want to adjust the cloud-init defaults click to the tab

I saw these options

  • User: Ubuntu
  • Password: your choice
  • DNS Domain: dev.themaw.tech
  • DNS Servers: 1.1.1.1
  • SSH Public key can be loaded
  • IP config set to DHCP

Now you can right click on the template and clone it to a VM. If you set the disk to be larger it will auto-expand to the set size.