Setting up

Step 1: Create the Virtual Machine

Use the Proxmox Web UI or CLI to create the base VM using these recommended settings. In this case, I’m using ubuntu server.

Web UI:

  1. General:

    • VM ID: Set to a unique value (e.g., 900).
    • Name: ubuntu-cloud-template.
  2. OS:

    • ISO Image: Select the uploaded OS installer ISO (e.g., ubuntu-20.04-server.iso).
    • Guest OS Type: Linux.
    • Version: Choose the appropriate version (e.g., Ubuntu 20.04).
  3. System:

    • BIOS: OVMF (UEFI) or SeaBIOS (default).
    • Machine Type: Leave as default (i440fx).
    • Graphic Card: Default.
    • QEMU: Enable
  4. Disks:

    • Bus/Device: SCSI (recommended for better performance).
    • Storage: Select a storage pool (e.g., local-lvm).
    • Disk Size: 10 GB or your preferred size.
    • Discard: Enable (thin provisioning).
    • Cache: Default(no cache)
  5. CPU:

    • Cores: 2.
    • Sockets: 1.
    • Type: Host (recommended for compatibility).
  6. Memory:

    • RAM: 2048 MB.
    • Ballooning Device: Disable for templates.
  7. Network:

    • Model: VirtIO (paravirtualized for performance).
    • Bridge: vmbr0.
  8. Confirm:

    • Review settings and create the VM.
    • Do not start the VM immediately.

Step 2: Install the Operating System

  1. Boot the VM:

    • Start the VM and access the console.
  2. Install the OS:

    • Perform a minimal installation.
    • Avoid installing additional software to keep the template lightweight.
  3. Enable OpenSSH Server (optional):

    • During installation, select OpenSSH to enable SSH access by default.
  4. Finish Installation:

    • Complete the setup and reboot into the new system.

Step 3: Configure Cloud-Init

  1. Install Cloud-Init:

    sudo apt update
    sudo apt install -y cloud-init
    
  2. Configure Cloud-Init Datasource: Ensure the NoCloud datasource is enabled:

    sudo nano /etc/cloud/cloud.cfg.d/90_dpkg.cfg
    

    Add or verify:

    datasource_list: [ NoCloud, ConfigDrive ]
    
  3. Disable Persistent Network Configuration (optional): Remove existing network configurations to allow cloud-init to take over:

    sudo rm -f /etc/netplan/*.yaml
    sudo cloud-init clean
    
  4. Clean Cloud-Init State: Reset cloud-init to prepare the VM for cloning:

    sudo cloud-init clean
    

Step 4: Proxmox-Specific VM Settings

Add a Cloud-Init Drive:

SSH into proxmox and attach a cloud-init drive to the VM:

qm set <vmid> --ide2 local-lvm:cloudinit

Set Boot Options:

Configure the VM to boot from the cloud-init disk:

qm set <vmid> --boot c --bootdisk scsi0

Configure the SCSI Controller:

Set the SCSI controller type:

qm set <vmid> --scsihw virtio-scsi-pci

Enable Hot-Plugging (Optional):

Allow hot-plugging for network, disk, and USB devices:

qm set <vmid> --hotplug network,disk,usb

Step 5: Convert to a Template

  1. Shut down the VM:

    qm shutdown <vmid>
    
  2. Convert the VM to a template:

    qm template <vmid>
    

Step 6: Clone the Template

You can clone this template to create new VMs with different settings:

Using Proxmox CLI:

  1. Clone the template:

    qm clone <template-vmid> <new-vmid> --name new-vm-name
    
  2. Set Cloud-Init Properties:

    qm set <new-vmid> --ipconfig0 ip={your-ip-range}/24,gw={your-gateway}}
    qm set <new-vmid> --ciuser {testuser} --cipassword {testpassword}
    
  3. Start the VM:

    qm start <new-vmid>
    

Using Proxmox Web Interface:

  1. Right-click the template and select Clone.
  2. Configure the new VM (name, VM ID, target storage, etc.).
  3. After cloning, update the Cloud-Init settings in Hardware > Cloud-Init.

Step 7: Verify the Template

  1. Log into the Cloned VM:

    • Use the username (ciuser) and password (cipassword) you configured.
  2. Check Cloud-Init Logs:

    sudo tail -f /var/log/cloud-init-output.log
    
  3. Test IP and SSH Access: Ensure the IP address and SSH configuration work as expected.