How to prepare a Cloud-Init Templates with Proxmox

This is an article about the preparation of Cloud-Init images for a Proxmox server to ease the deployment and setup of Virtual Machines. It coverts a few common operating system environments such as Ubuntu, Debian, and CentOS.

The article was updated 8 November 2021 to provide a link to updating the Cloud-Init images with ‘qemu-guest-agent’ which is an essential tool when you’re running these services for your clients.

Normally Cloud-Init is installed like so:

apt-get install cloud-init

However, many distributions offered read-to-use Cloud-Init images as .qcow2 files. For Ubuntu, go here:

The one we’re after is `focal-server-cloudimg-amd64.img`

We’ve included scripts for Ubuntu, CentOS 7, and Debian. There are 8 steps per distribution. All that changes is the VM ID 9xxx and the download file.

Instructions for Ubuntu Focal 20.04 (9000)

virt-customize -a focal-server-cloudimg-amd64.img --install qemu-guest-agent
[optional for Virtualmin quotas] virt-customize -a focal-server-cloudimg-amd64.img --install linux-image-generic
qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9000 focal-server-cloudimg-amd64.img local-lvm
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0
qm template 9000



Instructions for CentOS 7 (9001)

qm create 9001 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9001 CentOS-7-x86_64-GenericCloud-2009.qcow2c local-lvm
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 template 9001

Instructions for Debian 11 – Bullseye (9002) – Released 14 August 2021


qm create 9002 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9002 debian-11-generic-amd64-20210814-734.qcow2 local-lvm
qm set 9002 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9002-disk-0
qm set 9002 --ide2 local-lvm:cloudinit
qm set 9002 --boot c --bootdisk scsi0
qm set 9002 --serial0 socket --vga serial0
qm template 9002

Instructions for Ubuntu 21.04

qm create 9003 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9003 hirsute-server-cloudimg-amd64.img local-lvm
qm set 9003 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9003-disk-0
qm set 9003 --ide2 local-lvm:cloudinit
qm set 9003 --boot c --bootdisk scsi0
qm set 9003 --serial0 socket --vga serial0
qm template 9003

Instructions for Ubuntu 22.04 (9101)

In the example below, bold indicates extra customization. The customizations are:

  • Install the QEMU Guest Agent
  • Allow SSH PasswordAuthentication by using SED find and replace. Please note, this is a security risk so be careful.
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a bionic-server-cloudimg-amd64.img --run-command "sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
qm create 9101 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9101 jammy-server-cloudimg-amd64.img local-lvm
qm set 9101 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9101-disk-0
qm set 9101 --ide2 local-lvm:cloudinit
qm set 9101 --boot c --bootdisk scsi0
qm set 9101 --serial0 socket --vga serial0 
qm template 9101


Share this article

2 thoughts on “How to prepare a Cloud-Init Templates with Proxmox”

Leave a Reply

Your email address will not be published.

Scroll to Top