Skip to content

Proxmox VM Preparation for Cloning

This guide covers preparing a VM so it can be cloned cleanly in Proxmox. We do not convert the VM to a template: the prepared VM is simply powered off and used as the clone source. It covers the guest agent, the pre-shutdown cleanup, and the Proxmox-side settings.

Applies to: Ubuntu, Debian, AlmaLinux


Table of Contents

  1. Overview checklist
  2. Install the guest agent
  3. Cleanup before shutdown
  4. Proxmox-side configuration
  5. Add the VM to the dashboard templates
  6. Validate the clones
  7. Notes and troubleshooting

Overview checklist

  1. Reserve an IP in NetBox in the 10.6. range:
  2. IP: 10.60.9.151/24
  3. Gateway: 10.60.9.1
  4. Use this IP on the template machines while they are being prepared.
  5. Once complete, switch the bridge back from vmbr609 to vmbr0.
  6. Turn the VM off (do not convert it to a template).
  7. Add the powered-off VM to the dashboard templates using its VMID, so it can be deployed through the custom dashboard.
  8. Deploy a clone and test that it works properly.

1. Install the guest agent

Ubuntu / Debian

apt update
apt install -y qemu-guest-agent
systemctl enable qemu-guest-agent

AlmaLinux

dnf install -y qemu-guest-agent
systemctl enable qemu-guest-agent

Note: On AlmaLinux the agent is often preinstalled. The dnf install simply confirms it; the enable step is the one that matters.

Note: There is no need to start the service now. It does nothing until the VM has the virtio-serial channel from Proxmox, and it will come up on the next boot once enabled.


2. Cleanup before shutdown

Run this on every distro immediately before powering off. It:

  • resets cloud-init so it runs fresh on the next boot, which is what lets cloud-init apply its configuration (hostname, network, users, etc.) when a clone is deployed,
  • wipes the machine-id so clones don't collide on DHCP leases/IPs,
  • removes SSH host keys so each clone generates unique ones.
# Reset cloud-init so it runs fresh on next boot
cloud-init clean --logs

# Reset machine-id (must exist but be empty so systemd regenerates it)
truncate -s 0 /etc/machine-id
rm -f /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id

# Remove SSH host keys (cloud-init/sshd regenerates on boot)
rm -f /etc/ssh/ssh_host_*

Optional: shrink the image and tidy up

# Clean package caches (apt on Debian/Ubuntu, dnf on AlmaLinux)
apt-get clean 2>/dev/null || dnf clean all 2>/dev/null

# Clear logs and temp files
rm -rf /var/log/*.log /var/log/journal/* /tmp/* /var/tmp/*

# Clear shell history
cat /dev/null > ~/.bash_history && history -c

Power off

poweroff

Note: Do not convert the VM to a template. Leave it powered off and clone directly from it. Don't boot it again before cloning, or the machine-id and SSH host keys will be regenerated and you'll need to repeat the cleanup.


3. Proxmox-side configuration

Installing the agent in the guest does nothing unless Proxmox is told to use it. Enable the QEMU Guest Agent option on each source VM so clones get the virtio-serial channel.

CLI:

qm set <VMID> --agent enabled=1

GUI: VM → Options → QEMU Guest Agent → Enabled.

Before cloning, confirm the network bridge has been switched back from vmbr609 to vmbr0.


4. Add the VM to the dashboard templates

Once the VM is powered off and ready to be cloned, it must be registered in our dashboard's templates so it can be deployed through the custom dashboard.

  1. Note the VM's VMID (shown next to the VM name in the Proxmox sidebar, or via qm list).
  2. Add the VM to the dashboard's templates list using that VMID.
  3. Confirm the new entry appears in the dashboard and is available to deploy.

Note: The dashboard clones by VMID, so the VM must stay powered off and must not be deleted or renumbered after it is registered.


5. Validate the clones

Deploy a clone through the dashboard (or clone manually from the powered-off VM) and confirm on the clone:

  • [ ] The clone boots and cloud-init runs on first boot and applies its configuration (hostname, network, users, etc.) as set at deploy time
  • [ ] The clone has a unique machine-id (cat /etc/machine-id)
  • [ ] The clone has unique SSH host keys (ls /etc/ssh/ssh_host_*)
  • [ ] Networking comes up correctly on the vmbr0 bridge
  • [ ] The guest agent is running (systemctl status qemu-guest-agent) and the VM shows its IP in the Proxmox summary

Notes and troubleshooting

  • Truncate, don't delete, /etc/machine-id. If you rm it instead, some systemd setups won't regenerate it cleanly. Empty-but-present is the reliable state.
  • Manual network config. If the AlmaLinux template uses Predictable=false or has any static netplan/NetworkManager config baked in, double-check that networking comes up on the first clone. cloud-init clean resets the generated network config but does not touch anything configured manually.