Guide to Proxmox Cloud-Init and Templating with Rocky/Rhel 9

Create VM

First, Create your VM and add the CloudInit Drive:

Choose a datastore that is available to your VM and Add:

Prepare VM

Setup your VM with the partitioning layout and all the base components as you like without any use-case specific tools. (Guest-Tools, Node Exporter, …)

I would recommend the following:

# dnf update
# dnf install -y qemu-guest-agent cloud-init cloud-utils-growpart vim ipa-client

Now enable the following services:

# systemctl enable --now qemu-guest-agent cloud-init.service cloud-config.service cloud-final.service

Cloudinit specific configuration can be found under /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/

Cleanup VM for. Take in mind that everything you leave on it will be on every clone you make.

# dnf clean all                                      # clear dnf cache
# rm -f /etc/ssh/ssh_host_*                          # remove ssh host keys
# truncate -s 0 /etc/machine-id                      # reset machine id
# rm -rf /tmp/* /var/tmp/*                           # remove temporary files
# find /var/log -type f -exec truncate -s 0 {} \;    # clear log files (optional)
# passwd -d root                                     # Deletes the root password
# passwd -l root                                     # Locks the root account (prevents password login)
# history -c && history -w                           # Clears current session history and writes it
# export HISTFILESIZE=0                              # Prevents saving future history for this session
# cloud-init clean --logs --seed

Convert to template

Shutdown the vm.

Right-Click and select “Convert to Template”. If you want to change your template clone it to a VM, make the changes and convert it back to a template.

Clone Template to new VM

To clone the Template or any VM, richtclick on the template and select Clone:

Put in the name (Target, ID and Resource Pool can be left default) and select a Mode:

Linked Clone vs. Full Clone

For the most use-cases I would recommend selecting Full Clone.

Full CloneLinked Clone
creates a new VM and copies the disks
The created VM is independent from the template and can be run with the template changed or deleted
Better I/O Performance
requires less space since it uses the template disk and writes its own changes in a diff
The linked Clone VM cannot run without the template VM
Worse I/O Performance
Comparison between Full Clone and Linked Clone

For more information consult the Proxmox Wiki.

Cloud-Init

Now, under the Cloud-Init Tab you can configure these variables. Make sure to click on Regenerate Image afterwards. These changes will take affect once the VM is started/rebooted.

Make sure to change the IP-Address if set to static!

Once you start the vm the guest OS should get the information from the CloudInit Drive.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to Top