3 min read
Creating a Proxmox template

This is how to create a VM template on Proxmox. Always prefer the cloud-init images for VMs since they are optimized for this kind of environments.

Step 1

Open shell in one of your Nodes of your Proxmox cluster (commonly pve).

Download your prefered linux distribution cloud-init image. Repository example: debian cloud-init images.

wget https://cloud.debian.org/images/cloud/bookworm/20260510-2474/debian-12-generic-amd64-20260510-2474.qcow2

Step 2

Now, using the qm create will allow us to create a new VM. Since templates are created from existing VMs, then this is necessary. Later, when the template is generated the VM will get deleted so it’s fine.

qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --cpu host \
    --net0 virtio,bridge=vmbr0 --agent enabled=1 \
    --serial0 socket --vga serial0

This is the common setup when creating a VM.

VM_ID: the id for your template. VM_NAME: your template name, prefer using the distro name and version. --agent: enable the QEMU agent for better integration.

Now we must import the disk (downloaded image) of that new VM into some available Proxmox storage (LVM is ok).

qm importdisk $VM_ID $DISK_NAME local-lvm

DISK_NAME: should be the name of the image, downloaded on your current directory.

Set the controller and attach the disk to the VM

qm set $VM_ID --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$VM_ID-disk-0

In this case, local-lvm:vm-$VM_ID-disk-0 disk was created previously.

Step 3

We set the cloud-init image so the VM can read the configuration from the image when it fires up. Also we use dhcp in this case, since we will be using that template multiple times and the ip will be asigned automatically.

qm set $VM_ID --ide2 local-lvm:cloudinit --boot c --bootdisk scsi0 \
    --ipconfig0 ip=dhcp

Finally just create the template.

qm template $VM_ID

This deletes the current VM with VM_ID and generates the template.

Script the process

Use the following script on your node if you understand all the process.

chmod +x generate_template.sh
./generate_template.sh
# generate_template.sh

VM_ID=304
VM_NAME="template-debian-12"

# Download on your current directory
DISK_NAME="debian-12-generic-amd64-20260510-2474.qcow2"

# Create new VM
qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --cpu host \
    --net0 virtio,bridge=vmbr0 --agent enabled=1 \
    --serial0 socket --vga serial0 # output through proxmox serial

# Import disk
qm importdisk $VM_ID $DISK_NAME local-lvm

# Attach disk
qm set $VM_ID --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$VM_ID-disk-0

# Start cloud init
qm set $VM_ID --ide2 local-lvm:cloudinit --boot c --bootdisk scsi0 \
    --ipconfig0 ip=dhcp

# Convert template and verify
qm template $VM_ID

# Print out the configuration
qm config $VM_ID