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:
General:
- VM ID: Set to a unique value (e.g.,
900
). - Name:
ubuntu-cloud-template
.
- VM ID: Set to a unique value (e.g.,
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).
- ISO Image: Select the uploaded OS installer ISO (e.g.,
System:
- BIOS:
OVMF (UEFI)
orSeaBIOS
(default). - Machine Type: Leave as default (
i440fx
). - Graphic Card:
Default
. - QEMU: Enable
- BIOS:
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)
- Bus/Device:
CPU:
- Cores: 2.
- Sockets: 1.
- Type:
Host
(recommended for compatibility).
Memory:
- RAM: 2048 MB.
- Ballooning Device: Disable for templates.
Network:
- Model: VirtIO (paravirtualized for performance).
- Bridge:
vmbr0
.
Confirm:
- Review settings and create the VM.
- Do not start the VM immediately.
Step 2: Install the Operating System
Boot the VM:
- Start the VM and access the console.
Install the OS:
- Perform a minimal installation.
- Avoid installing additional software to keep the template lightweight.
Enable OpenSSH Server (optional):
- During installation, select OpenSSH to enable SSH access by default.
Finish Installation:
- Complete the setup and reboot into the new system.
Step 3: Configure Cloud-Init
Install Cloud-Init:
sudo apt update sudo apt install -y cloud-init
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 ]
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
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
Shut down the VM:
qm shutdown <vmid>
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:
Clone the template:
qm clone <template-vmid> <new-vmid> --name new-vm-name
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}
Start the VM:
qm start <new-vmid>
Using Proxmox Web Interface:
- Right-click the template and select Clone.
- Configure the new VM (name, VM ID, target storage, etc.).
- After cloning, update the Cloud-Init settings in Hardware > Cloud-Init.
Step 7: Verify the Template
Log into the Cloned VM:
- Use the username (
ciuser
) and password (cipassword
) you configured.
- Use the username (
Check Cloud-Init Logs:
sudo tail -f /var/log/cloud-init-output.log
Test IP and SSH Access: Ensure the IP address and SSH configuration work as expected.