Get the cloud-init image.
wget https://cdimage.debian.org/cdimage/cloud/bookworm/latest/debian-12-generic-amd64.qcow2The downloaded image does not include quemu-guest-agent which I want to have in order for Proxmox to show details about the VM.
SSH into the Proxmox node and run:
apt update
apt install -y libguestfs-toolsThis needs to only be done once for the life of the pve host.
Then for the cloud image run:
virt-customize --install qemu-guest-agent -a debian-12-generic-amd64.qcow2This will install libguestfs-tools and install quemu-guest-agent into the image we downloaded earlier. The same process can be used to add other packages into the image.
Create the template:
qm create 9001 --name debian12-template --memory 1024 --net0 virtio,bridge=vmbr0This will create a new VM with ID 9001, the name debian12-template, 1024Mb of RAM and a network bridge set to vmbr0 which is the usually the default one created by Proxmox.
qm importdisk 9001 debian-12-generic-amd64.qcow2 local-zfsNext we import the image we downloaded earlier as a disk for the VM with ID 9001 that we just created. local-zfs is the name of the storage in Proxmox where the disk should be stored.
qm set 9001 --scsihw virtio-scsi-pci --scsi0 local-zfs:vm-9001-disk-0
qm set 9001 --ide2 local-zfs:cloudinitWith the first command, we set the disk for the VM to be the disk we just imported in the previous step vm-9001-disk-0 is the name of the disk that was generated after the import.
The second command creates the cloud-init CD-ROM drive which activates the cloud-init options for the VM.
qm set 9001 --boot c --bootdisk scsi0
qm set 9001 --serial0 socket --vga serial0
qm set 9001 --ipconfig0 ip=dhcpFirst we set the boot order and specify the first boot disk to be used to be scsi0 which is the disk with the cloud image, then we configure a serial console to use as display otherwise we won't see anything in the "Console" view in Proxmox.
The last command will set the networking stack config to use DHCP in order for the VM to obtain an IP address.
qm set 9001 --agent enabled=1Enables guest agent so Proxmox UI can give more info about the VM when running.
qm resize 9001 scsi0 15G
qm template 9001These are the final steps, resize the disk, otherwise it will be the size of the cloud image we downloaded, in here I make it a 15GB disk so it has enough storage to install some packages, then we tell Proxmox to make VM 9001 a template.
Finally, cleanup:
rm debian-12-generic-amd64.qcow2