qm template: what does it _do_? what makes a template different from a (k)vm?

johnnyutahh

Member
Sep 19, 2020
31
7
8
39
`qm template`: what does it _do_? what makes a template different from a (k)vm?

Details

I see references to how running `qm template [vm_number]` creates a template that makes future (linked or full) cloning better, more-efficient.

But... what does `qm template` do to the (k)vm? (A bit of web searching did not yield any answers here.) If my team understands better even just a little bit on what's happening "underneath the hood" we might make better decisions with our template creation, management, etc.
 
One can convert a VM into a Template. Such templates are read-only, and you can use them to create linked
clones.

It is helpful to convert the VM into a template. From this template you can then quickly create
linked clones. The deployment from VM templates is much faster than creating a full clone (copy).

LearnLInuxTv and ServeTheHome have some additional info on youtube.
 
@chintzy_butters - thanks for your timely replies. I'm not trying to learn (in this thread) the external benefits of creating a template; there's many, many reference for that info. We need not repeat it here. As such, if I'm reading it correctly, none of the above info tells me what the `qm template` command does to a (k)vm to turn it into a template, other than make the template read-only. Is making the vm read-only all that `qm template` does? (I'm guessing you're unfamiliar else you might have stated already - and that's really, totally fine.)

I suspect there's more. eg: does `qm template` strip out unneeded things in the vm to make clones faster? Does it convert the vm to (perhaps) a simple tarball (which is vaguely what I recall an lxc template does)? What else might the `qm template` command do the vm files/disks/etc?

I'm seeking more specifics. I have a deep, experienced, computer-science background. I can take whatever details anybody can give me. To anyone who has knowledge in this arena: pls, do not be bashful, and pls bring on the info.

Best regards,
~J

ps. I had already read https://pve.proxmox.com/wiki/VM_Templates_and_Clones and watched LearnLInuxTv video on cloud-init-template creation before starting this thread; I might dig through ServeTheHome videos later (good tip on that, thanks), but do I really need to spend lots of time finding and watching a bunch of videos to just to learn these details?
 
Last edited:
https://git.proxmox.com/?p=qemu-ser...bc52e2cce843407bf3;hb=refs/heads/master#l4168

is the API endpoint, does some checks, then calls

https://git.proxmox.com/?p=qemu-ser...1391b3954b122bc416;hb=refs/heads/master#l6557

which converts each disk that is a proper volume managed by PVE into a base volume via

https://git.proxmox.com/?p=pve-stor...e4a8b428c2aebedb9ca;hb=refs/heads/master#l761

which is handled by the plugin for the storage that volume is using:

https://git.proxmox.com/?p=pve-stor...cf878fbed75cd6821d400442;hb=refs/heads/master

finally the API endpoint sets a flag on the VM config to indicate it's a template (this flag is then checked for various other operations, e.g. preventing starting the VM, etc.pp.).

what happens on the storage level depends on the storage, e.g. some file-based storages will set the 'immutable' attribute of the image file, Ceph will rename, create a snapshot, and set the 'protected' flag on that snapshot. most plugins will rename the volume and change the volume ID accordingly to reflect it is a base volume now.
 
  • Like
Reactions: virttom and Dominic
Great details @fabian - thank you!

@dietmar - typically a directive like "Simply compare the config file before and after" means (for me) to run a diff(1) or cmp(1) on config file(s). Can you share where I can find the config file(s) for a (k)vm/template in a zfs-based install? I can then, per your suggest, confirm things for myself.

https://git.proxmox.com/?p=qemu-ser...bc52e2cce843407bf3;hb=refs/heads/master#l4168

is the API endpoint, does some checks, then calls [...]

finally the API endpoint sets a flag on the VM config to indicate it's a template (this flag is then checked for various other operations, e.g. preventing starting the VM, etc.pp.).

what happens on the storage level depends on the storage, e.g. some file-based storages will set the 'immutable' attribute of the image file, Ceph will rename, create a snapshot, and set the 'protected' flag on that snapshot. most plugins will rename the volume and change the volume ID accordingly to reflect it is a base volume now.
Basically yes. Simply compare the config file before and after - this will show you the changes.
 
config files for VMs are in /etc/pve/nodes/NODE/qemu/VMID.conf (parts in caps to be replaced ;)). the current config can also be printed by 'qm config VMID' (the config file might contain snapshots as well, these are not displayed by this command).
 
Ahhh, yes, super-duper helpful (again), thanks @fabian (!).

config files for VMs are in /etc/pve/nodes/NODE/qemu/VMID.conf (parts in caps to be replaced ;)). the current config can also be printed by 'qm config VMID' (the config file might contain snapshots as well, these are not displayed by this command).
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!