DEV Community

Cover image for Create an Ubuntu Cloud-Init Template on Proxmox: The Command Line Guide
Miner Ninja
Miner Ninja

Posted on • Updated on

Create an Ubuntu Cloud-Init Template on Proxmox: The Command Line Guide

This guide will demonstrate how to create an Ubuntu cloud-init template on Proxmox and set up a virtual machine with Ubuntu Server 24.04 LTS via the command line.
For the latest Ubuntu Cloud images, you can check Ubuntu Cloud Images.
All steps in this guide are to be executed on a Proxmox server.

Step 1: Prepare the Ubuntu Cloud-init Image

1.1 Download the Ubuntu Cloud Image:

To download the Ubuntu 24.04 image, use wget with the appropriate URL and save it to the /var/lib/vz/template/iso/ directory:

wget -P /var/lib/vz/template/iso/ https://cloud-images.ubuntu.com/daily/server/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img
Enter fullscreen mode Exit fullscreen mode
  • -P — option tells wget to save the file in the specified directory

1.2 Verify that the file was downloaded successfully:

Make sure the file is in the correct directory:

ls /var/lib/vz/template/iso/
Enter fullscreen mode Exit fullscreen mode

You should see ubuntu-24.04-server-cloudimg-amd64.img listed in the directory.

Step 2: Create a Virtual Machine Template in Proxmox

2.1. Create a new Virtual Machine (VM):

Create a VM with a unique identifier 9000 (or any other available ID):

qm create 9000 --name "ubuntu-cloud-init-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
Enter fullscreen mode Exit fullscreen mode
  • 9000 — Unique identifier for the VM.
  • --name — Name of the virtual machine.
  • --memory — Amount of RAM in megabytes.
  • --cores — Number of CPU cores.
  • --net0 — Network card configuration (uses virtio with bridge vmbr0).

2.3 Import the downloaded image into the Proxmox storage

Use qm importdisk to import the downloaded image into local storage:

qm importdisk 9000 /var/lib/vz/template/iso/ubuntu-24.04-server-cloudimg-amd64.img local-lvm
Enter fullscreen mode Exit fullscreen mode
  • 9000 — ID of the virtual machine.
  • Path to the Ubuntu Cloud-init image file.
  • local-lvm — Name of the storage in Proxmox.

2.4 Configure the primary disk and VM settings:

Set up the disk using the scsi type and configure the boot options:

qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
qm set 9000 --boot c --bootdisk scsi0
Enter fullscreen mode Exit fullscreen mode
  • --scsihw — Specifies the SCSI controller type (using virtio-scsi-pci).
  • --scsi0 — Configures the primary disk of the VM.
  • --boot c --bootdisk scsi0 — Sets the VM to boot from the primary disk.

2.5. Add a Cloud-init disk:

Add a Cloud-init disk to the VM:

   qm set 9000 --ide2 local-lvm:cloudinit
Enter fullscreen mode Exit fullscreen mode
  • --ide2 — Specifies that the disk will be attached as an IDE device.
  • local-lvm:cloudinit — Specifies the storage and type of the disk.

Step 3: Configure Cloud-init

Configure Cloud-init settings such as user, password, and SSH key:

   qm set 9000 --ipconfig0 ip=dhcp
   qm set 9000 --ciuser ubuntu --cipassword 'yourpassword'
   qm set 9000 --sshkey "$(cat ~/.ssh/id_rsa.pub)"
Enter fullscreen mode Exit fullscreen mode
  • --ipconfig0 ip=dhcp — Configures the IP to be assigned via DHCP.
  • --ciuser — Specifies the Cloud-init username.
  • --cipassword — Sets the password for the user (replace 'yourpassword' with your desired password).
  • --sshkey — Adds an SSH key for the user (the contents of the public key from ~/.ssh/id_rsa.pub).

Step 4: Save the Template

Convert the VM to a template:

   qm template 9000
Enter fullscreen mode Exit fullscreen mode

Step 5: Use the Template to Create New Virtual Machines

5.1 Clone the template to create a new VM:

Create a new VM from the template:

   qm clone 9000 201 --name "new-ubuntu-vm"
Enter fullscreen mode Exit fullscreen mode
  • 100 — Unique ID for the new VM.
  • --name — Name of the new virtual machine.

5.2 Configure the new VM (if needed):

You can modify settings for the new VM, such as memory size and the number of cores:

   qm set 201 --memory 4096 --cores 4
Enter fullscreen mode Exit fullscreen mode

5.3 Start the new VM:

   qm start 201
Enter fullscreen mode Exit fullscreen mode

Conclusion

Now you have an guide for creating a virtual machine using the Ubuntu 24.04 Cloud-init image. This process allows you to quickly and conveniently deploy new virtual machines with minimal effort using the Proxmox command line.

Top comments (0)