Skip to content

Proxmox: Templates with Cloud-init

Create template for Debian 12

Download image

wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2

Set variables:

# 
TMPID=9001
# Set name
TEMPLATE_NAME=deb12-cloudinit
# Image file name
DISKIMAGE=debian-12-genericcloud-amd64.qcow2
# SET YOUR VALUE !!!
STORAGE=local-lvm

Create new VM

# SET YOUR BRIDGE !!!
qm create $TMPID --name $TEMPLATE_NAME --net0 virtio,bridge=vmbr0
# 
qm set $TMPID --ostype l26
# 
qm importdisk $TMPID $DISKIMAGE $STORAGE
# 
qm set $TMPID --scsihw virtio-scsi-pci --scsi0 $STORAGE:9001/vm-$TMPID-disk-0.raw
# 
qm set $TMPID --boot c --bootdisk scsi0
# 
qm set $TMPID --ide2 $STORAGE:cloudinit
# 
qm set $TMPID --serial0 socket --vga serial0
# 
qm set $TMPID --agent enabled=1 
#
qm set $TMPID --onboot 0

Convert VM to the template

qm template $TMPID

Create VM from template

VM=201
VM_NAME=deb12-test01

#
qm clone 9001 $VM --name $VM_NAME --full
# 
qm set $VM --memory 2048
# 
qm set $VM --cores 2
# Disk
VM_BOOT=$(qm config $VM | grep bootdisk | awk '{print $2}')
qm disk resize $VM $VM_BOOT 8G

# Cloud-Init

# Static IP
# qm set $VM --ipconfig0 ip=192.168.1.201/24,gw=192.168.1.1
# DHCP
qm set $VM --ipconfig0 ip=dhcp
# 
qm set $VM --ciuser a
qm set $VM --cipassword a
# 
qm set $VM --sshkey ~/proxmox_cloud.pub
# Public SSH keys: list, one per line
#qm set $VM --sshkeys ~/proxmox_ssh_pub_keys

Boot new VM

qm start $VM 

Links https://pve.proxmox.com/wiki/Cloud-Init_Suppor


VM=200
VM_NAME=test01

qm clone 9001 $VM --name $VM_NAME --full
qm set $VM --memory 2048
qm set $VM --cores 2
VM_BOOT=$(qm config $VM | grep bootdisk | awk '{print $2}')
qm disk resize $VM $VM_BOOT 20G
qm set $VM --ipconfig0 ip=dhcp
qm set $VM --ciuser a
qm set $VM --cipassword a
# qm set $VM --sshkey ~/.ssh/demo-ssh-rsa.pub