Recently, I had to replace my homelab VMware ESXi server… we all know why. After considering the many open-source options available, I decided on Proxmox due to its similarities with ESXi. Don’t get me wrong—I love OpenStack, but for a single server setup, it felt like too much overhead.

Proxmox stood out for its simplicity and flexibility, and with my recent explorations in Terraform and Vagrant on ESXi, I was thrilled to discover that Proxmox makes it just as easy to upload VM images. One of my current projects involves crafting a Terraform script to deploy OpenStack Kolla Ansible on Proxmox, and in doing so, I got hands-on experience with managing VM templates efficiently.

While I'm still new to Proxmox, the amount of helpful information online is immense. I managed to download a qcow2 image of Rocky Linux 9, attach it to a fresh VM, and with cloud-init, set the user and password. And voilà—we have a running Rocky 9 VM that can be used as a template for future VMs.

No more tedious installs from ISO images. Just upload, configure, and go!

Steps to Create a Rocky 9 Template on Proxmox

If you’re curious how to do this yourself, here’s how you can achieve it:

  1. Login to your Proxmox server via SSH:
ssh root@your-proxmox-server-ip
  1. Create a directory to store the qcow2 image:
mkdir -p /var/lib/vz/template/qcow2
cd /var/lib/vz/template/qcow2
  1. Download the Rocky Linux 9 Generic qcow2 cloud image:
wget https://mirror.netzwerge.de/rocky-linux/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2
  1. Create a new VM in Proxmox and attach the downloaded qcow2 disk

My storage is local-lvm. You may want to adjust this.

vmid="201"
storage="local-lvm"
qm create $vmid --name rocky9-template --cores 2 --memory 4096 --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci --cpu cputype=host &&
qm importdisk $vmid Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 $storage &&
qm set $vmid --ide2 $storage:cloudinit &&
qm set $vmid --cipassword rocky &&
qm set $vmid --agent 1 &&
qm set $vmid --ciuser rocky &&
qm set $vmid --ciupgrade 0 &&
qm set $vmid --virtio0 $storage:vm-$vmid-disk-0,cache=writeback,discard=on &&
qm set $vmid --boot c --bootdisk virtio0

Instead if you want to use an ssh pubkey(s), add them to file "authorized_keys"

qm set $vmid --sshkeys authorized_keys

In case you want the VM to automatically upgrade all packages

qm set $vmid --ciupgrade 1

In case of Rocky9 the disk size is just 10GB, we can easily increase it

qm resize $vmid virtio0 +20G

We can now either directly use this VM or convert it to a template

qm template $vmid

If converted to a template we can easily create new VMs from it

qm clone 201 202 --name rocky9-new-vm

Or just use my scripts from Github. Besides importing a Rocky 9 template it also contains two scripts to clone a single or multiple VMs from the template. Happy cloning. 😄

Amazing how quick and easy this was. Now you’ve got a ready-to-go Rocky Linux 9 template for all your future VMs, no more ISO installs necessary! Of course this works with many other images too.

Just a hint in case you run into problems with cloud-init, here are some important files.

  • /etc/cloud/*
  • /var/log/cloud-init.log
  • /var/log/cloud-init-output.log