Vincent's Site

Making Proxmox templates

Date: 2023-11-24

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:

Adding software to the images

We need to add the qemu guest image to these images, this can be done with:

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 extra 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, but keep in mind we can only grow the disk later.

qm resize 9000 scsi0 10G
qm template 9000

if you clone the template, you can make a new VM based on this template.