Creating an Ubuntu 24.04 Cloud-Init Template in Proxmox: A Step-by-Step Guide
Introduction
This guide will walk you through creating an Ubuntu 24.04 cloud-init template in Proxmox. We’ll start from downloading the image and end with a reusable template that you can use to create new virtual machines quickly.
Prerequisites
- A working Proxmox installation
- Root access to your Proxmox server
- Basic knowledge of using terminal/SSH
Step 1: Download Ubuntu Cloud Image
First, we’ll download the official Ubuntu 24.04 (Noble) cloud image. Cloud images are special versions of Ubuntu designed to work with cloud-init.
1
2
3
4
5
# Connect to your Proxmox server as root
ssh root@your_proxmox_ip
# Download the Ubuntu 24.04 cloud image
wget -q https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
The -q flag makes wget run quietly (without showing progress).
Step 2: Resize the Image
The default cloud image is quite small. We’ll resize it to 32GB to make it more useful.
1
qemu-img resize noble-server-cloudimg-amd64.img 48G
Step 3: Create a New Virtual Machine
Now we’ll create a new VM with ID 8001. Each command parameter is explained below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
qm create 8001 \
--name "ubuntu-2404-cloudinit-template" \
--ostype l26 \
--memory 1024 \
--agent 1 \
--bios ovmf \
--machine q35 \
--efidisk0 vms-vg:0,pre-enrolled-keys=0 \
--cpu host \
--socket 1 \
--cores 2 \
--vga serial0 \
--serial0 socket \
--net0 virtio,bridge=vmbr0
Let’s break down what each option means:
8001: The VM ID (you can choose any unused number)--name: A descriptive name for your template--ostype l26: Indicates this is a Linux 2.6/3.x/4.x kernel--memory 1024: Allocates 1GB RAM--agent 1: Enables QEMU guest agent--bios ovmf: Uses UEFI boot--machine q35: Uses a modern machine type--efidisk0: Creates an EFI disk--cpu host: Uses host CPU type--socket 1 --cores 2: Creates 1 CPU socket with 2 cores--net0: Sets up networking using the default bridge
Step 4: Import the Disk
Import the downloaded image to your VM:
1
qm importdisk 8001 noble-server-cloudimg-amd64.img vms-vg
This converts the downloaded image into a format Proxmox can use.
Step 5: Configure the Virtual Machine
Now we’ll configure the disk and boot settings:
1
2
3
4
5
6
7
8
# Configure the SCSI controller and disk
qm set 8001 --scsihw virtio-scsi-pci --virtio0 vms-vg:vm-8001-disk-1,discard=on
# Set boot order to use the imported disk
qm set 8001 --boot order=virtio0
# Add cloud-init drive
qm set 8001 --scsi1 vms-vg:cloudinit
Step 6: Create Cloud-Init Configuration
We’ll create a custom cloud-init configuration that handles initial setup:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Create the snippets directory if it doesn't exist
mkdir -p /var/lib/vz/snippets/
# Create and edit the cloud-init configuration file
cat > /var/lib/vz/snippets/vendor.yaml << 'EOF'
#cloud-config
runcmd:
- apt update
- apt install -y qemu-guest-agent
- systemctl enable --now qemu-guest-agent
- sed -i '/^PasswordAuthentication/d' /etc/ssh/sshd_config
- sed -i '/^#PasswordAuthentication/d' /etc/ssh/sshd_config
- echo 'PasswordAuthentication yes' | tee -a /etc/ssh/sshd_config
- echo 'ChallengeResponseAuthentication no' | tee -a /etc/ssh/sshd_config
- echo 'UsePAM yes' | tee -a /etc/ssh/sshd_config
- systemctl restart sshd
- reboot
ssh_pwauth: true
EOF
This configuration:
- Updates the system
- Installs and enables the QEMU guest agent
- Configures SSH to allow password authentication
- Ensures proper authentication settings
- Restarts SSH service
- Reboots to apply all changes
Step 7: Configure VM Cloud-Init Settings
Now we’ll set up the basic VM configuration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Apply the custom cloud-init configuration
qm set 8001 --cicustom "vendor=local:snippets/vendor.yaml"
# Add helpful tags
qm set 8001 --tags ubuntu-template,24.04,cloudinit
# Set the default user (replace 'your_username' with your preferred username)
qm set 8001 --ciuser your_username
# Set a password (replace 'your_password' with your desired password)
qm set 8001 --cipassword $(openssl passwd -6 'your_password')
# If you have SSH keys, add them (optional)
qm set 8001 --sshkeys ~/.ssh/authorized_keys
# Configure networking to use DHCP
qm set 8001 --ipconfig0 ip=dhcp
Step 8: Convert to Template
Finally, convert the VM into a template:
1
qm template 8001
Using Your New Template
To create a new VM from this template:
- Go to your Proxmox web interface
- Select your template (ID: 8001)
- Click “Clone”
- Choose between linked clone (saves space) or full clone (independent copy)
- Give the new VM an ID and name
- Start your new VM!
Troubleshooting
- If SSH password authentication doesn’t work:
- Verify the cloud-init configuration was applied
- Check /etc/ssh/sshd_config in the VM
- Ensure the VM has completed its initial boot sequence
- If the VM doesn’t get an IP:
- Check your network configuration
- Verify DHCP is available on your network
- If the guest agent isn’t working:
- Log into the VM and check its status:
systemctl status qemu-guest-agent - Verify it was installed:
dpkg -l | grep qemu-guest-agent
- Log into the VM and check its status:
Conclusion
You now have a reusable Ubuntu 24.04 template that you can use to quickly create new VMs. Each VM created from this template will:
- Have password authentication enabled for SSH
- Use DHCP for networking
- Have the QEMU guest agent installed and enabled
- Be updated with the latest packages at creation
Remember to replace any example values (usernames, passwords) with your own secure values when using this guide.