Use this when preparing a template so clones get unique identity.
Generalization
Generalization removes machine-specific identity from a template — hostname, SIDs, machine-id, SSH host keys, logs and network config — so every clone gets new, unique identity on first boot.
template → identity removed → clone regenerates
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Windows templates are generalized with Sysprep.
virt-sysprep -a <disk> --operations defaults— generalize Linux imagecat /etc/machine-id— should be empty in templatels /etc/ssh/ssh_host_*— host keys removed in template
ReferenceImportant terms & boundaries3 sections · depth on demand
In depth
Linux: what makes a clone a duplicate
| Item | Problem when duplicated | Generalisation step |
|---|---|---|
/etc/machine-id | Same DHCP client ID (systemd-networkd), same journal ID, confused monitoring | Empty the file (keep it present, zero length) so systemd generates a new ID at boot |
| SSH host keys | Clients see identical host keys; MITM warnings ignored | Delete /etc/ssh/ssh_host_*; regenerated at boot |
| Persistent network names / MAC in config | NIC renamed or no network on the clone | Remove hard-coded MACs |
| Cloud-init state | Cloud-init thinks first boot already happened | cloud-init clean --logs |
| Logs, shell history, temp files | Leak build information | Clean |
The virt-sysprep manual covers these as operations (machine-id, ssh-hostkeys, net-hwaddr, logfiles and more), applied to an offline image:
$ virt-sysprep -d tpl-debian12 --hostname localhost --operations defaults
Windows: sysprep
C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /shutdown /unattend:C:\unattend.xml
/generalize resets the SID, removes device-specific drivers state and prepares OOBE. Never clone a domain-joined Windows VM without sysprep — duplicate SIDs and computer accounts break domain trust. Remove apps installed per-user from the Store before sysprep; they are a frequent cause of sysprep failure (see C:\Windows\System32\Sysprep\Panther\setupact.log).
Verify on the first clone
| Check | Command |
|---|---|
| New machine-id | cat /etc/machine-id differs from the template |
| New SSH host key | ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub |
| Unique Windows SID | whoami /user (machine part) or PsGetSid |
| Cloud-init ran | cloud-init status --long → done |
*The Linux and Windows guest generalisation examples above are illustrative examples, not captured from a lab or production host.*
How it works
Generalisation removes machine-specific identity from an image before it becomes a template: Sysprep on Windows; clearing machine-id, SSH host keys, logs and cloud-init state on Linux.
What to reset per OS
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in VM Templates → Generalization. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/docs.html · confidence 94%