I use proxmox in my homelab to run VM's, but by default you have to install each VM from scratch which can be annoying. Luckily Proxmox has a feature where you can make templates and use Cloud-Init to set them up.
Downloading the base image
First, we need to download a cloud image we can use. Most distributions already prepare special images for this. I've linked a few below:
In this tutorial I will reference to these images as
<image>
. Replace this with the image you downloaded
Adding software to the images
We need to add the qemu guest agent to these images, this can be done with (replace <image>
with the image you downloaded):
sudo apt update;
sudo apt install libguestfs-tools -y;
virt-customize --install qemu-guest-agent -a <image>
Creating the template
Now we have prepared the disk image, we can make the VM template. We can make a new blank VM with the following command (feel free to change ram/cpu to values that you prefer)
qm create 9000 --name debian-12-bookworm-template --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0 --agent 1
Next we can import the disk:
# replace local-lvm with the name of your storage
qm importdisk 9000 <image> local-lvm
# if you use a normal "directory" volume for storage, you can use this instead:
qm importdisk 9000 <image> local --format qcow2
Next, attach the disk, cloud-init and set some additional options:
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
qm set 9000 --ipconfig0 ip=dhcp
qm set 9000 --cpu cputype=x86-64-v2-AES
If you like, you can also set the default cloud-init user/sshkey:
qm set 9000 --sshkeys <filepath>
qm set 9000 --ciuser <username>
Now we can resize the disk to a more comfortable minimum size, keep in mind you can not shrink this later.
qm resize 9000 scsi0 50G
qm template 9000
Now you can use "clone" to make a new VM based on this image.