
A template on Proxmox Virtual Environment (Proxmox VE) is a master copy of a configured virtual machine (VM) that you clone to create new VMs without building each one from scratch. Cloud-Init is an open-source tool that configures a VM on its first boot. It applies the user, Secure Shell (SSH) key, and network settings you provide, so a new clone is ready to log in to once its first boot finishes.
This guide explains how to convert an Ubuntu cloud image into a reusable VM template on a Vultr Bare Metal server running Proxmox VE. It covers configuring Cloud-Init with your SSH key, installing the QEMU guest agent, setting up a private network for the VMs, and cloning the template to deploy VMs.
Before you begin:
Cloud images are operating system disks that distributions typically publish with Cloud-Init included. On a VM's first boot, Cloud-Init reads the settings that Proxmox VE provides for it, such as the user, SSH key, hostname, and network, and applies them.
A clone comes together in this order:
This guide uses the Ubuntu 24.04 cloud image. Ubuntu publishes it along with a checksum file listing the correct checksum for each image.
Download the Ubuntu 24.04 (noble) cloud image from the Ubuntu cloud images site.
Download the checksum file that Ubuntu publishes for the image.
Verify the image against its checksum.
The SHA256SUMS file lists checksums for several images. The --ignore-missing option checks only the image you downloaded. Verify that the output shows noble-server-cloudimg-amd64.img: OK. A match confirms that the download is intact.
A new VM has no operating system. Because the cloud image already contains an installed one, you import it as the VM's disk and skip the installer.
Check which VM IDs the server already uses.
Each ID is a unique number from 100 to 999999999. A new installation has no VMs, so the list is empty.
Check which container IDs the server already uses.
A new installation has no containers, so the list is empty. This guide uses 9000 as the template ID. If 9000 appears in either list, choose another ID and replace it in the remaining commands.
Create the VM.
This command creates an empty VM with 2048 MiB of memory, 2 CPU cores, and a network card attached to the vmbr0 bridge, which is the virtual switch that connects VMs to the server’s network. Every clone inherits these memory and CPU settings by default. You may specify different values if your server’s resources allow.
List the VMs.
Verify that the output lists VM 9000 with the name ubuntu-2404-template and the status stopped.
List the storage pools that can hold VM disks.
Verify that the Name column lists local-lvm. Proxmox VE creates it when you install with the ext4 or xfs filesystem. The output can also list a Directory storage, such as data1.
Import the cloud image as a disk. Replace STORAGE with the name from the Name column in the previous step, for example, local-lvm.
The last line of the output names the new disk, for example, unused0: successfully imported disk 'local-lvm:vm-9000-disk-0'. Note the disk name between the quotes. The next step uses it.
Attach the imported disk to the VM. Replace IMPORTED_DISK with the disk name from the previous step.
Set the VM to boot from the disk.
A new VM boots from the network. This command makes it boot from the disk instead.
Add a serial port and use it as the display. The cloud image writes its boot messages to a serial port, so this setting lets you see them.
Resize the disk. Cloud images ship with a small disk, so resize it before you convert the VM to a template.
The command sets the disk's total size to 10 GiB. You can choose a different size, as long as it fits in the free space that sudo pvesm status shows for the storage. Each clone gets a disk of this size. Cloud-Init grows the root filesystem to use the extra space on the first boot of each clone.
Display the VM configuration.
Verify that the output includes these values:
scsi0 with the size you setboot: order=scsi0serial0: socket and vga: serial0net0 with bridge=vmbr0Cloud-Init reads its settings from a small virtual drive that Proxmox VE attaches to the VM.
Add the Cloud-Init drive to the VM. Replace STORAGE with the same name that you used in the import command, for example, local-lvm.
The output includes a line such as ide2: successfully created disk 'local-lvm:vm-9000-cloudinit,media=cdrom'.
Display the VM configuration.
Verify that the output includes an ide2 line that contains cloudinit, for example, ide2: local-lvm:vm-9000-cloudinit,media=cdrom.
Ubuntu cloud images have no password, so a clone accepts logins only via an SSH key. Cloud-Init installs a public key for the ubuntu user on every clone at first boot. The public key is safe to share, and the matching private key stays on your local computer as the only way to log in.
You can use a dedicated key pair for the VMs. Use its .pub file when you display the public key, and pass its private key to the login command later with the -i option.
On macOS or Linux, display your public key in a terminal on your local computer. If your key file has a different name, use its .pub file.
The output is one line that starts with the key type, such as ssh-ed25519. Copy the whole line.
On Windows, display your public key in PowerShell on your local computer. If your key file has a different name, use its .pub file.
The output is one line that starts with the key type, such as ssh-ed25519. Copy the whole line.
Save the public key to a file on the server. Replace PUBLIC_KEY with the line you copied.
Set the username and the SSH key on the VM.
The --ciuser option sets the username that receives the key. The --sshkeys option reads the file and stores the key in the VM configuration. The VMs have no password, so you log in with your private key.
Make a backup of the private key, because you cannot recover it if you lose it.
Display the Cloud-Init user data.
Verify that the output shows user: ubuntu and lists your public key under ssh_authorized_keys.
The QEMU guest agent is a service inside a VM that lets Proxmox VE read the VM's IP address, send power commands such as shutdown, and freeze its filesystem during a backup. Ubuntu cloud images do not include it. Cloud-Init installs it on every clone when you give it vendor data, which is a file with settings that Cloud-Init applies in addition to the ones Proxmox VE generates. Proxmox VE stores such files as snippets on a storage that allows them.
Check whether the local storage allows snippets.
If the Name column lists local, skip the next two steps. If the output shows only the column headings, no storage allows snippets yet. Continue with the next step.
Display the storage configuration.
Find the dir: local entry and note the types on its content line, such as import,vztmpl,backup,iso.
Add snippets to the local content types. Replace CONTENT_TYPES with the types from the previous step.
The command sets the complete list, so CONTENT_TYPES keeps the types that local already allows.
Create the snippets directory.
The local storage is a Directory storage at /var/lib/vz, and it reads snippets from this folder.
Create the vendor data file.
The #cloud-config line marks the file as Cloud-Init configuration. The packages list tells Cloud-Init to install the qemu-guest-agent package on the first boot of each clone. The agent starts automatically when the VM boots, and the package installs afterward, so the runcmd entry starts it immediately after installation. The clone downloads the package through the private network, which gives it internet access.
Enable the guest agent on the template and attach the vendor data file.
The --agent option enables communication between Proxmox VE and the agent. The --cicustom option points the template to the vendor data file. Each clone inherits both settings.
Display the VM configuration.
Verify that the output includes agent: enabled=1 and cicustom: vendor=local:snippets/vendor.yaml.
Converting the VM turns it into a template that you can clone. Convert it without starting it first.
Convert the VM to a template.
The output reports that Proxmox VE renamed the VM disk, for example, Renamed "vm-9000-disk-0" to "base-9000-disk-0" in volume group "pve".
Display the VM configuration.
Verify that the output includes template: 1. The disk name in the scsi0 line now starts with base-, for example, local-lvm:base-9000-disk-0.
The hosting network assigns a public IP address to the server and does not assign IPv4 addresses to VMs on the public bridge, vmbr0. A private network gives the VMs fixed addresses and routes them to the internet through the server. The network uses IPv4 addresses only.
For a private network where a Dynamic Host Configuration Protocol (DHCP) server assigns addresses, see the Proxmox VE documentation on setting up a Simple zone with Source Network Address Translation (SNAT) and DHCP.
Check which interface has the server's public IP address.
Verify that the line for vmbr0, the default Proxmox VE bridge, shows the server's public IP address.
The commands in this section use vmbr0. If the address is on another interface, use that interface in place of vmbr0.
Check whether the server already has a vmbr1 bridge.
If the command prints nothing, continue with the next step. If it prints lines, choose another bridge name, such as vmbr2, replace vmbr1 with it in this section and the clone commands.
Back up the network configuration file.
Add a private bridge named vmbr1 to the end of the file.
If your network already uses 10.10.10.0/24, choose another private /24 range and use its first three numbers in place of 10.10.10 in this step and the remaining commands.
The bridge gives the VMs a private network address range, 10.10.10.0/24. The post-up line adds a masquerade rule. For traffic leaving via vmbr0, the rule replaces a VM's private address with the server's public IP address, so the VMs can reach the internet. It adds the rule only when it is missing, so repeating the reload does not create duplicates.
Display the network configuration file.
Verify that the vmbr0 section is unchanged and that the vmbr1 block appears at the end.
Enable packet forwarding so the server can forward traffic between the two bridges.
The command saves the setting for future restarts.
Load the setting.
Verify that the output includes net.ipv4.ip_forward = 1.
Check the change without applying it.
The -n option shows what would change without changing it. Verify that the output lists vmbr1 as one of the interfaces to bring up.
Apply the network configuration.
A mistake in the network configuration can disconnect your SSH session. Keep a second SSH session open until you verify the change.
List the bridges.
Verify that vmbr1 has the address 10.10.10.1/24.
List the NAT rules for outgoing traffic.
Verify that the output lists one MASQUERADE rule for 10.10.10.0/24.
Check whether the server uses Uncomplicated Firewall (UFW).
If the output starts with Status: active, continue with the next step. If the status is inactive, skip the next two steps.
Allow the traffic of the VMs through UFW. UFW denies routed traffic by default, so VMs on vmbr1 cannot reach the internet until you allow it.
List the UFW rules for routed traffic.
Verify that the output lists two ALLOW FWD rules involving vmbr0 and vmbr1, one for IPv4 and one for IPv6.
Each clone is a copy of the template with its own ID, name, and address.
Get the next unused VM ID and save it in a variable.
Proxmox VE returns the next ID that no VM or container uses. The next commands use $VMID, so you do not type the number.
The variable lasts only for this SSH session, so run the following steps in the same session.
Print the value of the variable.
Verify that the output is a number, such as 100.
Clone the template.
The VM name becomes the hostname, for example, ubuntu-vm-100. The --full option copies the template disk, so the clone does not depend on the template. Without it, Proxmox VE creates a linked clone on local-lvm. A linked clone stores only its changes and needs the template disk.
Set the network of the clone. The template uses the vmbr0 bridge, so each clone needs this step.
The command moves the network card to the private bridge and assigns a fixed address ending in the VM ID. Each VM gets a different address when its ID is between 100 and 254. The gateway, 10.10.10.1, is the address of vmbr1 on the server.
Start the clone.
On this first start, Cloud-Init runs and applies the user, SSH key, hostname, and address.
(Optional) Watch the clone's boot messages on its serial console.
The terminal shows the boot messages and the Cloud-Init output. Wait until the console prints Reached target cloud-init.target - Cloud-init target. This line means that Cloud-Init finished. Then press :key_ctrl: + :key_o: to exit the console.
Wait for the clone to be ready to log in.
After you start a clone, it needs time to set itself up. A login attempt before then fails. The command checks every five seconds for up to about five minutes and prints nothing while it waits. Wait until it prints a line such as 10.10.10.100 is ready, and then continue to the next step. The next step uses that address. If the command ends without printing that line, verify that the output of sudo qm config 9000 includes the ide2 line from the Cloud-Init drive step.
Open a new terminal on your local computer, and keep the terminal with your SSH session on the server open.
Log in to the clone through the server. Replace USER with the name of the sudo user that you use to log in to the server, SERVER_IP with the public IP address of the server, and CLONE_ADDRESS with the address that the previous step printed, for example, 10.10.10.100.
The clone is on the private network, so SSH connects to the server first, then to the clone, using your private key. SSH prompts you in this order:
USER's password, enter it.yes.If you recreate a clone with the same address, SSH reports REMOTE HOST IDENTIFICATION HAS CHANGED. Remove the old key using ssh-keygen -R CLONE_ADDRESS, then log in again.
Run the next four steps in the clone.
Wait for Cloud-Init to finish.
The command returns when Cloud-Init finishes. On the first boot, Cloud-Init upgrades the packages and installs the guest agent. This takes about a minute. Verify that the output shows status: done.
Display the hostname.
Verify that the hostname matches the VM name, for example, ubuntu-vm-100.
List the network interfaces of the clone.
Verify that eth0 shows the address of the clone, for example, 10.10.10.100/24.
Test the connection to the internet.
Verify that the command prints HTTP/1.1 200 OK. The command uses curl because UFW can allow ping while blocking web traffic.
Return to the terminal with your SSH session on the server. Run the remaining steps there.
List the origin of the clone's disks. This check applies to the local-lvm storage.
Verify that the Origin column is empty for the clone's disk, for example, vm-100-disk-0, so the clone does not depend on the template. A linked clone lists base-9000-disk-0 there.
Query the guest agent for the clone's network interfaces.
Verify that an ip-address field shows the address of the clone, for example, 10.10.10.100.
Deploy more VMs with a loop. Each pass picks the next unused ID, so every VM gets a different name and address. Use one number for each VM you want, for example, 1 2 3 4 5.
The loop stores each ID in NEW_ID, so $VMID keeps the ID of the first clone.
List the VMs.
Verify that the output lists the new VMs as running. The address of each VM is 10.10.10. followed by its ID.
You have created a reusable VM template from an Ubuntu cloud image on Proxmox VE. The template carries a Cloud-Init drive with your user and SSH key and points to a vendor data file that installs the QEMU guest agent. The private network connects the clones to the internet through the server. Each clone you deploy applies its settings on first boot and is ready to log in to once Cloud-Init finishes. You can now install your own software on the clones, such as a web server or a database, and reach it from the server over the private network. For more information, refer to the Proxmox VE Cloud-Init Support documentation.
0 Comments
Be the first to comment and share your perspective with the community.