These notes have been tested with Proxmox Virtual Environment (PVE) 8.2.4, Debian 12 and cloud-init 22.4.2 (from Debian 12 packaging).
First create a virtual machine and install Debian Linux on it normally, with all the additional tools and updates as required. I usually use the netinstall CD image from Debian.
After completing the installation, for the current user, unset the Bash shell history file variable and delete the history file. Install cloud-init, run some cleanup commands as needed, clear the current machine ID, and finally shutdown the VM:
unset HISTFILE rm ~/.bash_history sudo apt install cloud-init sudo apt autoremove sudo apt clean sudo truncate -s 0 /etc/machine-id sudo rm /var/lib/dbus/machine-id sudo poweroff
Note: “sudo cloud-init clean –machine-id” was not working here properly, it resulted with a missing machine ID after reboot. Apparently some later cloud-init versions have a fix for that.
Then convert this VM to template in Proxmox.
In the Hardware settings of the template, add CloudInit Drive.
In the Cloud-Init settings of the template, adjust the settings as desired.
Note: If you add any IP Config settings, cloud-init will rename the network interfaces from the predictable names (like ens18
, ens19
, …) to legacy names like eth0
, eth1
and so on, using /etc/udev/rules.d/70-persistent-net.rules
file. The network interface configurations are then written in /etc/network/interfaces.d/50-cloud-init
. Removing the cloud-init IP Config configuration will require an additional reboot to fully return back to using Debian-default /etc/network/interfaces
file.
Now you can clone the template to a VM, make any required adjustments in the VM settings, and start it.
When the VM starts, these happen automatically:
- Machine ID (
/etc/machine-id
) is created - Machine ID is also symlinked to
/var/lib/dbus/machine-id
- SSH server keys are recreated
- System hostname is set to the VM name
- sudo access is granted for the normal user
Note: If you later change the VM name in PVE and then shutdown the VM at some point, in the next start the VM will have new SSH server keys and new hostname. Duplicate lines for the sudo access will also appear in /etc/sudoers.d/90-cloud-init-users
, but that does not seem to matter. These will also happen after any cloud-init IP Config changes.