Ben Lobaugh
  • Growth & Leadership
  • Giving Back
  • Sailing
  • VW Bus
  • About

How to Make an Awesome Ubuntu Template in Proxmox

Originally published at https://benlobaugh.medium.com/how-to-make-an-awesome-ubuntu-template-in-proxmox-c06928f8b426

Note: Written in July 2025. Check versions as things may have changed!

VM templates are a game-changer for spinning up virtual machines fast. They save you from reinstalling everything from scratch. But a sloppy template can cause headaches. Let me share what I have learned in this step-by-step guide to creating a solid Ubuntu template in Proxmox.

What You’ll Need

  • A working Proxmox VE setup
  • Ubuntu 24.04 LTS (or newer) ISO uploaded to your Proxmox storage
  • Admin access to your Proxmox host
  • Basic comfort with Linux commands

Step 1: Set Up Your Base VM

Create a new virtual machine in Proxmox. This will become the template later:

VM Settings:

  • Name: Go with something clear, like ubuntu-24.04-template.
  • OS: Select your Ubuntu ISO, set Guest OS to “Linux 6.x/2.6 Kernel” (usually the default).
  • System: Defaults are fine, tweak for performance if needed.
  • Hard Disk: Use SCSI, pick your storage (like local-lvm), set at least 32GB disk size.
  • CPU/Memory: Match what your typical VMs need.
  • Network: Choose VirtIO for snappy performance.

If you plan to use the Cloud-Init feature of Proxmox, add a Serial Port to the Hardware devices before powering on the VM. We will go deeper into this in Step 3.

Step 2: Install Ubuntu

Fire up the VM and install Ubuntu:

  • Boot from the ISO and follow the wizard.
  • Set up a standard user account (don’t use root for extra security).
  • Install the OpenSSH server for remote management.
  • Stick with default partitioning unless you have special needs.
  • Finish and reboot.

Step 3: Configure Cloud-Init

Connect via SSH or Proxmox console and install cloud-init. We will usecloud-init so cloned VMs can be configured from the Proxmox Cloud-Init interface. If you do not use that feature, skip the cloud-init steps:

sudo apt update && sudo apt upgrade -y
sudo apt install -y cloud-init

sudo tee /etc/cloud/cloud.cfg.d/99-pve.cfg > /dev/null <<EOF
datasource_list: [ConfigDrive, NoCloud]
EOF

sudo cloud-init clean
sudo systemctl enable cloud-init-local cloud-init cloud-config cloud-final

This ensures network settings, SSH keys, and other configs work smoothly.

Step 4: Clean Up (Don’t Skip This!)

A good template needs a clean slate to avoid issues. Run these:

# Reset machine ID (regenerates on boot)
sudo truncate -s 0 /etc/machine-id# Clear network caches
sudo rm -f /var/lib/dhcp/dhclient.*
sudo rm -f /var/lib/dhcpcd5/*
sudo rm -f /var/lib/systemd/network/*# Remove SSH host keys (regenerate on boot)
sudo rm -f /etc/ssh/ssh_host_*# Clear logs
sudo truncate -s 0 /var/log/wtmp /var/log/btmp /var/log/lastlog
sudo find /var/log -name "*.log" -exec truncate -s 0 {} \;
sudo find /var/log -name "*.old" -delete
sudo find /var/log -name "*.gz" -delete# Wipe bash history
history -c
sudo rm -f /root/.bash_history ~/.bash_history# Clean temp files and package cache
sudo rm -rf /tmp/* /var/tmp/*
sudo apt clean
sudo apt autoremove -y

Step 5: Set Up First-Boot Magic

Make sure cloned VMs set themselves up properly with a first-boot script:

sudo tee /usr/local/bin/first-boot-setup.sh > /dev/null <<'EOF'
#!/bin/bash

# Regenerate SSH keys if needed
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
ssh-keygen -A
systemctl restart sshd
fi
# Set a unique hostname if needed
CURRENT_HOSTNAME=$(hostname)
if [ "$CURRENT_HOSTNAME" = "ubuntu-2404-template" ] || [ "$CURRENT_HOSTNAME" = "localhost" ]; then
MACHINE_ID=$(cat /etc/machine-id | cut -c1-8)
NEW_HOSTNAME="ubuntu-${MACHINE_ID}"
hostnamectl set-hostname "$NEW_HOSTNAME"
sed -i "s/127.0.1.1.*/127.0.1.1\t$NEW_HOSTNAME/" /etc/hosts
if ! grep -q "127.0.1.1" /etc/hosts; then
echo "127.0.1.1\t$NEW_HOSTNAME" >> /etc/hosts
fi
fi

# Clean up this script
rm -f /usr/local/bin/first-boot-setup.sh
rm -f /etc/systemd/system/first-boot.service
systemctl daemon-reload
EOF

sudo chmod +x /usr/local/bin/first-boot-setup.sh

sudo tee /etc/systemd/system/first-boot.service > /dev/null <<EOF
[Unit]
Description=First Boot Setup
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/first-boot-setup.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable first-boot.service

Step 6: Shut It Down

Do a clean shutdown:

sudo shutdown -h now

Step 7: Turn It Into a Template

In Proxmox:

  • Right-click the VM.
  • Choose “Convert to template.”
  • Confirm. (Note: Templates can’t be started directly — only cloned.)

Step 8: Test It Out

Clone the template to verify it works:

  • Right-click the template, select “Clone.”
  • Give the clone a new VM ID and name.
  • Start it and check that it:
  • Gets a unique IP via DHCP.
  • Has unique SSH keys.
  • Has a unique machine ID.
  • Runs without conflicts.

Wrapping Up

You’ve got a slick Ubuntu template that’ll save you tons of time! Keep it updated as Ubuntu releases new versions or your needs change. Document your setup for easy tweaks later. Now go spin up some VMs and enjoy the efficiency!

benlobaugh.com
Devops
Homelab
Medium
Networking
Proxmox
Virtualization