Intro
Lately I was revisiting my VM templates in Proxmox that I created some time ago. I used to create them with a mix of steps done with the Web interface and some done through the CLI, but this time I wanted to check if there was a way to do everything through CLI, for consistency and also to be quicker.
The templates I was focused on were for Linux VMs and I also wanted to use the cloud image provided by Ubuntu or Debian, so that I can leverage the cloud-init feature.
Creating the template
After reading the qm create
and qm set
man pages, I was finally able to make everything using CLI. Here’s how:
- Create a VM that will never be powered on
qm create <vmid> \
--name <vmname> \
--ostype l26 \
--cpu cputype=x86-64-v2-AES --cores 2 --sockets 2 \
--memory 4096 \
--net0 bridge=vmbr0,virtio \
--scsihw virtio-scsi-single \
--serial0 socket
- Download the cloud image of the linux distro you prefer.
For Debian 12 they can be found here. The correct image is usual the genericcloud one with qcow2 extension, of course for the cpu architecture you want to use.
For Ubuntu 24.04 LTS they can be found here. The correct image is the one with .img extension, of course for the cpu architecture you want to use.
wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2
- Once the image has been downloaded you need to import that file into the vm created at step #1
qm importdisk <vmid> debian-12-genericcloud-amd64.qcow2 <StorageName>
If you are using an image .img extentions, which is actually a qcow2, you need to add the option--format qcow2
- Once the image has been imported into the VM, it has now become a disk. That disk must be attached to the VM
qm set <vmid> --scsi0 <StorageName>:vm-<vmid>-disk-0
- You now have to specify the boot order so that the VM created from the template will boot from the disk created using the qcow2 image
qm set <vmid> --boot order=scsi0
- The VM is now ready to become a template.
qm set <vmid> --template true
Now you can check in the web interface and there is a template ready to be cloned with <vmid>
and <vmname>
.
With a template created in this way you can only create vm using the Full Clone
mode.
What’s next
In a future post I will describe the different ways of using cloud-init in Proxmox, starting from a VM template.