Proxmox Templates and Clones

Proxmox Cloud-init Templates

Cloud-init is a on boot provisioning utility that helps setup new VM guests from a template. This article will go though how to create a Debian template that is cloud-init enabled so that you can then use it to clone and provision new Debian VM Guests.

Prerequisites

This article assumes you have the following:

  • A running Proxmox VE server setup.
  • Provmox version 9.x (but almost any version will work)
  • Can connect to the Proxmox host with SSH
  • Have a medium understanding of Linux or Unix command line.

Step 1: Creating the Cloud-init Image store locations.

SSH into the Proxmox host and run the following commands (as root):

mkdir -p /var/lib/vz/template/iso/cloud-init/debian
mkdir -p /var/lib/vz/snippets

This storage is on the local host, if you have a cluster or store your iso images in another location, then you can adjust these locations but note, this location is used in this article so you will have to adjust where you see a path.

Step 2: Download the Debian Cloud-init Images.

There are a few official cloud-init images and those images come in a couple of formats. There is a Generic image and a Generic Cloud Image. We will be using the Generic Cloud image for this template as it is optimized for Virtualization Environments and doesn’t include some of the hardware drivers that are not needed for a VM guest.

The two main formats that are used (for Proxmox) are QCOW2 and RAW. If your Proxmox server is using ZFS storage for your guest VMs then download the RAW format. If you are not using ZFS or are unsure then QCOW2 will always work but you will not get some of the extra performance feature in the RAW format on ZFS. For this article, my Proxmox server is using ZFS so I will be using the RAW format.

Login to your Proxmox cli and download the image.

cd /var/lib/vz/template/iso/cloud-init/debian
wget https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw

Step 3: Create the VM Template

NOTE: Most of this article will be done using the Proxmox cli but you could also it via the web interface. To make this article shorter I will only show the cli way.

NOTE: I like making all my Proxmox templates with a higher ID number so that is is easy to identify them as a template. I usually start with ID number 5000.

To create the VM that will eventually become our template, enter this:

qm create 5000 --name Debian13-Cloud-Template --ostype l26 --cores 2 --memory 2048 --net0 virtio,bridge=Internal,mtu=1500,queues=2 --machine q35 --cpu cputype=host,flags=+pdpe1gb;+aes

Import the disk and setup hardware

qm importdisk 5000 /var/lib/vz/template/iso/cloud-init/debian/debian-13-genericcloud-amd64.raw vmpool --format raw
qm set 5000 --scsihw virtio-scsi-single --virtio0 vmpool:base-5000-disk-1,discard=on,iothread=1,size=3G
qm set 5000 --ide2 vmpool:cloudinit,media=cdrom
qm set 5000 --boot c --bootdisk virtio0
qm set 5000 --serial0 socket --vga serial0
qm set 5000 --ipconfig0 ip-dhcp
qm set 5000 --agent enable=1,fstrim_cloned_disks=1

Step 4: Starting up the VM and Verify

IN order to start up the VM, you will have to give the Cloud-init a user and password to create so you can login to it. This can be done from hte Proxmox Web Interface.

Login to the Proxmox web interface and select the the VM we just created (ID 5000). Then select Cloud-init from the menu for that VM. Edit the user and password. I changed it to the root user and gave it a password. Then click on Regenerate Image.

Startup the VM Guest and verify (from the Proxmox cli):

qm start 5000
qm cloudinit dump 5000 user
qm console 5000
qm guest cmd 5000 network-get-interfaces

Login to the VM (using the user and password you gave in the Cloudinit menu)

sudo cloud-init status
shutdown -P now

Step 5: Convert the guest to a template.

Log back into the Proxmox CLI and run the following command ot convert it to a template.

qm template 5000

Leave a Comment

Your email address will not be published. Required fields are marked *