1
+# VM Templates and Clones
2
+
3
+:::danger
4
+
5
+**Destructive Operations - Data Loss Warning**
6
+
7
+The commands in this guide **permanently delete**:
8
+- All historical metrics
9
+- [Node identity](node-identities.md#agent-self-identity)
10
+- [Cloud connection](node-identities.md#agent-cloud-link-aclk-identity)
11
+- Alert history
12
+
13
+**This is irreversible. There is no undo.**
14
+
15
+Only run these commands on VMs you intend to convert to templates.
16
+Running these on a production system will destroy your monitoring data.
17
+
18
+:::
19
+
20
+:::tip
21
+
22
+**What You'll Learn**
23
+
24
+How to prepare a VM template so each clone gets a unique Netdata identity and automatically connects to Netdata Cloud.
25
+
26
+:::
27
+
28
+## Prerequisites
29
+
30
+- **Read first**: [Node Identities](node-identities.md) - understand what you're deleting
31
+- Netdata installed on a VM
32
+- Hypervisor that supports templates or golden images
33
+- (Optional) `/etc/netdata/claim.conf` configured for auto-claiming to Cloud
34
+
35
+## Overview
36
+
37
+To prepare a VM template:
38
+
39
+1. **Stop Netdata** - Prevent file regeneration
40
+2. **Delete identity and data files** - Force new identity on clone boot
41
+3. **Keep claim.conf** - Enable auto-claiming (optional)
42
+4. **Convert to template** - Without starting Netdata
43
+
44
+## Files to Delete
45
+
46
+:::danger
47
+
48
+**Verify you are on the correct VM before running these commands.**
49
+
50
+:::
51
+
52
+| Category | Files | What's Lost |
53
+|----------|-------|-------------|
54
+| **[Agent Identity](node-identities.md#agent-self-identity)** | [GUID file](node-identities.md#agent-self-identity), [status backups](node-identities.md#status-file-backups) | Node identity |
55
+| **[ACLK Auth](node-identities.md#agent-cloud-link-aclk-identity)** | [`cloud.d/`](node-identities.md#agent-cloud-link-aclk-identity) directory | Cloud connection, must re-claim |
56
+| **[Node Metadata](node-identities.md#parent-children-identities)** | `netdata-meta.db*`, `context-meta.db*` | Node metadata, metric mappings |
57
+| **Metrics** | `dbengine*` directories (all tiers) | All historical metrics |
58
+
59
+**Keep**: `/etc/netdata/claim.conf` - enables auto-claiming on clones
60
+
61
+## Step-by-Step
62
+
63
+### 1. Stop Netdata
64
+
65
+```bash
66
+sudo systemctl stop netdata
67
+```
68
+
69
+### 2. Delete All Identity and Data Files
70
+
71
+:::danger
72
+
73
+**Point of No Return**
74
+
75
+The following commands permanently delete Netdata data. Verify you are on the template VM.
76
+
77
+:::
78
+
79
+```bash
80
+# Machine GUID (Agent Self Identity)
81
+sudo rm -f /var/lib/netdata/registry/netdata.public.unique.id
82
+
83
+# Status file backups (GUID recovery locations)
84
+sudo rm -f /var/lib/netdata/status-netdata.json
85
+sudo rm -f /var/cache/netdata/status-netdata.json
86
+sudo rm -f /tmp/status-netdata.json
87
+sudo rm -f /run/status-netdata.json
88
+sudo rm -f /var/run/status-netdata.json
89
+
90
+# ACLK authentication (Claimed ID, RSA keys)
91
+sudo rm -rf /var/lib/netdata/cloud.d/
92
+
93
+# Databases and metrics (metadata, all dbengine tiers)
94
+sudo rm -f /var/cache/netdata/netdata-meta.db*
95
+sudo rm -f /var/cache/netdata/context-meta.db*
96
+sudo rm -rf /var/cache/netdata/dbengine*
97
+```
98
+
99
+### 3. Configure Auto-Claiming (Optional)
100
+
101
+To have clones automatically claim to Netdata Cloud on first boot, ensure `/etc/netdata/claim.conf` exists:
102
+
103
+```bash
104
+cat /etc/netdata/claim.conf
105
+```
106
+
107
+Should contain:
108
+```ini
109
+[global]
110
+ url = https://app.netdata.cloud
111
+ token = YOUR_SPACE_TOKEN
112
+ rooms = ROOM_ID
113
+```
114
+
115
+### 4. Convert to Template
116
+
117
+**Do not start Netdata.** Convert the VM to a template using your hypervisor.
118
+
119
+## When Clones Boot
120
+
121
+1. Netdata starts, no [GUID](node-identities.md#agent-self-identity) found, generates new unique identity
122
+2. If `claim.conf` exists, auto-claims to Cloud
123
+3. Cloud assigns [Node ID](node-identities.md#cloud-node-identity), new node appears in your Space
124
+
125
+Each clone is a unique, independent node.
126
+
127
+## Hypervisor Notes
128
+
129
+The Netdata cleanup commands are the same for all hypervisors. The difference is **when** and **how** to run them.
130
+
131
+| Hypervisor | Template Support | When to Clean | Automation |
132
+|------------|------------------|---------------|------------|
133
+| **Proxmox** | Convert to Template | Before conversion | cloud-init scripts |
134
+| **VMware/vSphere** | VM Templates | Before conversion | Guest customization |
135
+| **libvirt/KVM** | virt-sysprep | During sysprep | `--delete` flags |
136
+| **AWS** | AMI | Before image creation | user-data scripts |
137
+| **Azure** | Managed Image | Before capture | cloud-init |
138
+| **GCP** | Machine Image | Before creation | startup scripts |
139
+| **Vagrant** | Box packaging | Before `vagrant package` | Vagrantfile provisioner |
140
+
141
+<details>
142
+<summary><strong>libvirt/KVM: virt-sysprep example</strong></summary>
143
+
144
+```bash
145
+virt-sysprep -a myvm.qcow2 \
146
+ --delete /var/lib/netdata/registry/netdata.public.unique.id \
147
+ --delete /var/lib/netdata/status-netdata.json \
148
+ --delete /var/cache/netdata/status-netdata.json \
149
+ --delete /tmp/status-netdata.json \
150
+ --delete /run/status-netdata.json \
151
+ --delete /var/run/status-netdata.json \
152
+ --delete /var/lib/netdata/cloud.d \
153
+ --delete '/var/cache/netdata/netdata-meta.db*' \
154
+ --delete '/var/cache/netdata/context-meta.db*' \
155
+ --delete '/var/cache/netdata/dbengine*'
156
+```
157
+
158
+</details>
159
+
160
+<details>
161
+<summary><strong>Cloud-init: Fresh install approach</strong></summary>
162
+
163
+Alternative: Install Netdata on first boot instead of templating:
164
+
165
+```yaml
166
+# cloud-init user-data
167
+runcmd:
168
+ - curl -fsSL https://get.netdata.cloud/kickstart.sh -o /tmp/kickstart.sh
169
+ - bash /tmp/kickstart.sh --claim-token TOKEN --claim-rooms ROOM_ID
170
+```
171
+
172
+Each instance installs fresh with unique identity.
173
+
174
+</details>
175
+
176
+## Troubleshooting
177
+
178
+### Clones share the same identity
179
+
180
+Cause: [GUID recovered from status backup](node-identities.md#status-file-backups). Netdata checks multiple backup locations before generating a new GUID.
181
+
182
+Solution: Delete **all** status file locations, not just the primary GUID file. See the cleanup commands in [Step 2](#2-delete-all-identity-and-data-files).
183
+
184
+### Clones don't connect to Parent
185
+
186
+Cause: Either clones share the same [Machine GUID](node-identities.md#agent-self-identity) (only one can connect at a time), or `stream.conf` wasn't configured in the template.
187
+
188
+Solution:
189
+- Verify each clone has a unique GUID: `cat /var/lib/netdata/registry/netdata.public.unique.id`
190
+- Verify `stream.conf` exists and has the correct Parent destination and API key
191
+- If GUIDs are duplicated, run the cleanup on each clone (loses metrics)
192
+
193
+### Stale "template" node appears in Cloud
194
+
195
+Cause: [Database files kept](node-identities.md#multiple-node-identities-in-database) from the template. The template's node identity persists in the metadata.
196
+
197
+Solution: Delete databases on all clones. This loses historical metrics but removes the stale node reference.
198
+
199
+### Clones using Parent profile unexpectedly
200
+
201
+Cause: Template had `stream.conf` with an enabled API key section (configured to receive streams, as Parent).
202
+
203
+Solution: Reset `stream.conf` on clones or delete the API key sections that enable receiving.
204
+
205
+### Unstable Cloud connections (flapping)
206
+
207
+Cause: Two agents have the same [Machine GUID](node-identities.md#agent-self-identity). Cloud kicks the older connection offline when the second connects.
208
+
209
+Solution: Each agent needs a unique GUID. Run the cleanup procedure on affected clones.
210
+
211
+### Clone doesn't auto-claim to Cloud
212
+
213
+Cause: Missing `claim.conf` or environment variables not set.
214
+
215
+Solution: Create `/etc/netdata/claim.conf` with your Space token.
216
+
217
+### Fixing Already-Deployed Clones
218
+
219
+If clones were deployed with identity files:
220
+
221
+```bash
222
+# On each affected clone
223
+sudo systemctl stop netdata
224
+
225
+# Machine GUID
226
+sudo rm -f /var/lib/netdata/registry/netdata.public.unique.id
227
+
228
+# Status file backups (all locations)
229
+sudo rm -f /var/lib/netdata/status-netdata.json
230
+sudo rm -f /var/cache/netdata/status-netdata.json
231
+sudo rm -f /tmp/status-netdata.json
232
+sudo rm -f /run/status-netdata.json
233
+sudo rm -f /var/run/status-netdata.json
234
+
235
+# ACLK authentication (if re-claiming to Cloud)
236
+sudo rm -rf /var/lib/netdata/cloud.d/
237
+
238
+# Databases and metrics
239
+sudo rm -f /var/cache/netdata/netdata-meta.db*
240
+sudo rm -f /var/cache/netdata/context-meta.db*
241
+sudo rm -rf /var/cache/netdata/dbengine*
242
+
243
+sudo systemctl start netdata
244
+```
245
+
246
+:::warning
247
+
248
+This deletes all historical metrics on the clone. If you skip deleting `cloud.d/`, you must re-claim to Cloud manually.
249
+
250
+:::
251
+
252
+## FAQ
253
+
254
+<details>
255
+<summary>What if I reboot a clone?</summary>
256
+
257
+Identity persists. Netdata only generates a new [GUID](node-identities.md#agent-self-identity) when the file AND all [backups](node-identities.md#status-file-backups) are missing.
258
+
259
+</details>
260
+
261
+<details>
262
+<summary>Can multiple clones use the same claim token?</summary>
263
+
264
+Yes. Each clone gets a unique [Machine GUID](node-identities.md#agent-self-identity) and [Claimed ID](node-identities.md#claimed-id). They authenticate with the same token but appear as separate nodes.
265
+
266
+</details>
267
+
268
+<details>
269
+<summary>Do containers need this?</summary>
270
+
271
+No. Containers start with empty volumes, so each gets a unique identity automatically.
272
+
273
+</details>
274
+
275
+<details>
276
+<summary>Is my claim token secure in the template?</summary>
277
+
278
+The token only allows claiming to your Space. It cannot read data or modify other nodes. Treat it like an API key - don't expose publicly, but it's safe in private templates.
279
+
280
+</details>