Skip to content

Proxmox Ubuntu VM Template Setup Guide - Cloud-Init Integration

This guide walks you through creating a reusable Ubuntu VM template in Proxmox using cloud-init. This approach allows for rapid deployment of VMs with automatic configuration, making it perfect for scaling infrastructure quickly.

Prerequisites

  • Proxmox VE installed and configured
  • Access to the Proxmox web interface and shell
  • At least 1GB RAM and 10GB storage available per VM
  • Internet connection for downloading Ubuntu cloud image

Step 1: Create the Base VM

  1. Create new VM

    • Click “Create VM” in the Proxmox interface
    • Configure the VM with the following settings:
      • VM ID: Choose an available ID (e.g., 900)
      • Name: ubuntu-2404-template
      • Resource Pool: (optional)
  2. OS Configuration

    • Guest OS: Linux
    • Version: 6.x - 2.6 Kernel
    • Do not use any media: ✅ Enabled
  3. System Settings

    • BIOS: Default (SeaBIOS)
    • Machine: Default (i440fx)
    • SCSI Controller: VirtIO SCSI single
    • Qemu Agent: ✅ Enabled
  4. Hard Disk Configuration

    • Skip this step - delete any disk that was created
    • We’ll add the cloud image disk later
  5. CPU Configuration

    • Sockets: 1
    • Cores: 1 (can be increased when cloning)
    • Type: x86-64-v2-AES (modern CPU features)
  6. Memory Configuration

    • Memory: 1024 MB (can be increased when cloning)
  7. Network Configuration

    • Bridge: vmbr0 (or your configured bridge)
    • Model: VirtIO (paravirtualized network driver)
    • Firewall: ✅ Enabled (optional but recommended)

Step 2: Configure Cloud-Init

  1. Add Cloud-Init drive

    • Navigate to the Hardware tab of your newly created VM
    • Click AddCloudInit Drive
    • Select your preferred storage location
    • Click Add
  2. Configure Cloud-Init settings

    • Go to the Cloud-Init tab in your VM
    • Configure the following essential settings:
      • User: Set your desired username (e.g., ubuntu)
      • Password: Set a secure password
      • SSH Public Key: Paste your SSH public key (optional)
      • DNS domain: Optional (e.g., local)
      • DNS servers: Optional (e.g., 8.8.8.8 1.1.1.1)
  3. Network Configuration

    • Set IP Config to DHCP
  4. Regenerate Cloud-Init image

    • Click Regenerate Image to apply your configuration
    • This creates the cloud-init configuration disk

Step 3: Download and Import Ubuntu Cloud Image

  1. Access Proxmox shell

    • Click on your Proxmox node in the left panel
    • Navigate to Shell or SSH into your Proxmox host
  2. Download Ubuntu cloud image

    Terminal window
    # Download Ubuntu 24.04 LTS minimal cloud image
    wget https://cloud-images.ubuntu.com/minimal/releases/noble/release/ubuntu-24.04-minimal-cloudimg-amd64.img
  3. Resize the image

    Terminal window
    # Resize to 32GB (adjust as needed)
    qemu-img resize ubuntu-24.04-minimal-cloudimg-amd64.img 32G
  4. Add serial console for cloud-init output

    Terminal window
    # Replace VM-ID with your VM ID (e.g., 900)
    qm set VM-ID --serial0 socket --vga serial0
  5. Import the image to your VM

    Terminal window
    # Replace VM-ID with your VM ID (e.g., 900)
    # Replace 'local-lvm' with your storage if different
    qm disk import VM-ID ubuntu-24.04-minimal-cloudimg-amd64.img local-lvm
  6. Attach the imported disk

    • Return to the Proxmox web interface
    • Go to your VM’s Hardware tab
    • You’ll see an Unused Disk - double-click it to edit
    • Configure the disk settings:
      • Bus/Device: SCSI 0
      • Cache: Default
      • Discard: ✅ Enabled (if using SSD storage)
      • SSD emulation: ✅ Enabled (if using SSD storage)
    • Click Add to attach the disk
  7. Clean up downloaded file

    Terminal window
    # Remove the downloaded image file to save space
    rm ubuntu-24.04-minimal-cloudimg-amd64.img

Step 4: Final Configuration and Template Creation

  1. Configure boot order

    • Go to Options tab in your VM
    • Double-click Boot Order
    • Ensure the imported disk is first in the boot order
    • Enable the disk if it’s not already enabled
    • Click OK
  2. Configure additional options

    • Start at boot: ✅ Enable if you want VMs to auto-start (optional)
  3. Optional: Pre-configure the template with additional software

    • If you want to customize the template before converting it, boot the VM
    • Login using the cloud-init credentials you configured
    • Install and configure additional software as needed:
    Terminal window
    # Update package repositories and upgrade system
    sudo apt update && sudo apt upgrade -y
    # Install SSH import utility for GitHub key management
    sudo apt install -y ssh-import-id
    ssh-import-id gh:YOUR-GITHUB-USERNAME
    # Install QEMU guest agent for better VM integration
    sudo apt install -y qemu-guest-agent
    sudo systemctl enable --now qemu-guest-agent
    # Install commonly needed packages
    sudo apt install -y curl wget git vim htop
    # Clean up package cache and unnecessary packages
    sudo apt -y autoremove --purge
    sudo apt -y clean
    # Prepare template for cloning - clean cloud-init state
    sudo cloud-init clean -s -l
    sudo truncate -s 0 /etc/machine-id
    sudo truncate -s 0 /var/lib/dbus/machine-id
    # Clean potential DHCP leases
    sudo rm -f /var/lib/dhcp/*
    # Shutdown the VM
    sudo shutdown -h now
  4. Convert to template

    • Right-click on your VM in the resource tree
    • Select Convert to template
    • Confirm the conversion
  5. Verify template creation

    • The VM should now show a template icon
    • The template is ready for cloning

Step 5: Using Your Template

  1. Clone the template

    • Right-click on your template
    • Select Clone
    • Configure the clone:
      • VM ID: New unique ID
      • Name: Descriptive name for your new VM
      • Mode: Full clone (recommended)
      • Target Storage: Choose appropriate storage
  2. Configure the cloned VM

    • Hardware: Adjust CPU, memory, and disk size as needed
    • Cloud-Init: Update user credentials, network config, SSH keys
    • Options: Configure boot order, protection, etc.
  3. Customize cloud-init for the clone

    Terminal window
    # Example: Configure static IP
    # In the Cloud-Init tab, set IP Config to Manual:
    # IP: 192.168.1.100/24
    # Gateway: 192.168.1.1
    # DNS: 8.8.8.8 1.1.1.1
  4. Start your new VM

    • Start the VM
    • Cloud-init will automatically configure the system on first boot
    • SSH into the VM using the credentials you configured