Create template for kvm using an existing KVM VM

I want to create customs KVM templates from a base KVM template.
So the sources should be a local template (VM)
But for the moment I see no article or howto describing this process.
What i frequently see is using and Iso as the source or a cloud image.
Any idea about how can I use a local vm/template?

To create a custom KVM template from an existing KVM VM, follow these steps:

  1. Prepare the VM: Clean up and shut down the existing VM.
  2. Create an Image: Use virt-sysprep to prepare the VM, then use virsh or qemu-img to create an image file from the VM’s disk.
  3. Set Up Packer: Create a Packer template using the QEMU builder, specifying the VM image you created as the source.
  4. Build the Template: Run Packer to create the new KVM template based on your prepared image.

This process involves converting your VM to an image and then using that image with Packer to build a new template.

Hello rtfolfe,
thanks for the answer, that’s what i want to do, but howto do I do it? specialily step 3?

Thanks you very much

Here is a sample Packer template snippet using the qemu builder:

“builders”: [
“type”: “qemu”,
“format”: “qcow2”,
“accelerator”: “kvm”,
“disk_size”: “10240”,
“http_directory”: “http”,
“iso_url”: “/path/to/your/base-template.qcow2”,
“iso_checksum”: “none”,
“vm_name”: “custom-kvm-template”,
“ssh_username”: “your-username”,
“ssh_password”: “your-password”,
“ssh_port”: 22,
“ssh_wait_timeout”: “30m”
“provisioners”: [
“type”: “shell”,
“inline”: [
“sudo apt-get update”,
“sudo apt-get install -y nginx”

Hello rtwolfe,
ok thanks very much.
so, it is about putting the disks in the iso_url
If my vm VM has multiple disks i just need tu put them one after the other?
like this:
“iso_url”: “/path/to/your/base-template1.qcow2”,“/path/to/your/base-template2.qcow2”,“/path/to/your/base-template3.qcow2”

thanks again

bets regards

Clone the local VM that you want to use as the base for your custom KVM template. You can do this using KVM management tools like virt-manager or virsh command-line tool. This will create a copy of the VM that you can modify without affecting the original.

sorry i was working in something else, I thank you for your answers.

But If my VM has multiple disks I just need to put them one after the other?
like this:
“iso_url”: “/path/to/your/base-template1.qcow2”,“/path/to/your/base-template2.qcow2”,“/path/to/your/base-template3.qcow2”

thanks again

bets regards