Create cloud-init templates in Proxmox
Quickly deploy VMs in Proxmox VE with automated cloud-init templates. This guide covers creating, configuring, and using templates for fast, consistent provisioning.
Creating the template
Download an OpenStack compatible cloud image. For example Fedora Cloud Base 36.
wget https://download.fedoraproject.org/pub/fedora/linux/releases/37/Cloud/x86_64/images/Fedora-Cloud-Base-37-1.7.x86_64.qcow2Set variables for STORAGE, IMAGE_FILE, TEMPLATE_ID, TEMPLATE_NAME, VM_ID, VM_NAME. Make sure these names and identifiers are unique.
STORAGE='local-lvm'IMAGE_FILE='Fedora-Cloud-Base-37-1.7.x86_64.qcow2'TEMPLATE_ID='1000'TEMPLATE_NAME='fedora-template'VM_ID='100'VM_NAME='fedora-server'Create a new VM to act as a template. Note: —ostype can be l26 for Linux kernel 2.6 or newer or win11 for Windows 11
qm create $TEMPLATE_ID --name $TEMPLATE_NAME --machine q35 --cpu cputype=host --core 2 --memory 2048 --net0 virtio,bridge=vmbr0 --bios ovmf --ostype l26Add EFI disk.
qm set $TEMPLATE_ID -efidisk0 $STORAGE:0,format=raw,efitype=4m,pre-enrolled-keys=1Add TPM Module (Only required for Windows 11.)
qm set $TEMPLATE_ID -tpmstate0 $STORAGE:1,version=v2.0Import the downloaded image to local-lvm storage.
qm importdisk $TEMPLATE_ID $IMAGE_FILE $STORAGEAttach our cloud-init image as a storage device.
qm set $TEMPLATE_ID --scsihw virtio-scsi-pci --scsi0 $STORAGE:vm-$TEMPLATE_ID-disk-1Attach a drive for the cloud-init configuration.
qm set $TEMPLATE_ID --ide2 $STORAGE:cloudinitConfigure the VM to boot from our cloud-init image.
qm set $TEMPLATE_ID --boot c --bootdisk scsi0Add a serial console for remote management with OpenStack.
qm set $TEMPLATE_ID --serial0 socket --vga serial0Convert the VM into a VM template.
qm template $TEMPLATE_IDUsing the template
Clone the template into a new VM.
qm clone $TEMPLATE_ID $VM_ID --name $VM_NAME --full trueResize the storage to your liking. New size can be new absolute size or prepend a + before the amount to add that amount storage in addition to current size.
qm resize $VM_ID scsi0 +20GAdd our public SSH key to the VM’s authorized_keys.
qm set $VM_ID --sshkey ~/.ssh/name_ed25519.pubConfigure the the username for the default user.
qm set $VM_ID --ciuser 'fedora'Configure the the password for the default user.
qm set $VM_ID --cipassword 'SuperSecretPassword'Start the newly created VM.
qm start $VM_ID