In this tutorial, we will go over the steps required to create an Ubuntu 24.04 template in Proxmox and instantiate a VM based on it.
Step 0: Proxmox Shell Access
All Proxmox commands referenced in this article should be run in the proxmox shell.
To access the shell select the xterm.js option from the dropdown in the desired node as shown in the image below.
Step 1: Download Ubuntu Image
We will use the Ubuntu image provided in the Ubuntu Cloud Images directory here. Specifically, we will select the latest available Ubuntu cloud release version.
There are two approaches to download the image. Either run the below command in the Proxmox Shell:
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
Or download via the GUI as shown below:
Step 2: Create the Base VM
The base VM is a virtual machine we will be converting into a template.
The easiest way to create it is to run the below command in the Proxmox shell:
qm create 9000 --name "ubuntu-24.04-cloud-init-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr1
A few notes on the above command:
9000
- Is the unique identifier of your VM. If you haven't been managing this before, your first VM has likely been assigned an ID of 100 and each successive VM increments by 1. Some users prefer to organize the IDs in a way that groups VMs. 9000 is a high enough number such this VM is separated from the default ones.
--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 vmbr1). Depending on your specific configuration you would likely be using vmbr0 or vmbr1. In my case, it's the latter since I use vmbr1 for my private subnet.
Step 3: Assign Required Hardware to Base VM
In order for the base VM to work, we need to assign it some hardware.
The first one is a disk containing the image we downloaded previously:
qm importdisk 9000 /var/lib/vz/template/iso/ubuntu-24.04-server-cloudimg-amd64.img local-lvm
The above command will create a disk for VM with ID 9000 using the downloaded image and placed in the local-lvm storage. If you are using a different type of storage, adjust accordingly.
We will then configure this storage to be of the desired type and assign it as a boot volume:
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
qm set 9000 --boot c --bootdisk scsi0
Finally, we will create a cloud-disk storage so that Proxmox cloud-init configuration can be read by the VM:
qm set 9000 --ide2 local-lvm:cloudinit
Step 4: Configure Cloud-Init
Cloud-init is a useful tool to configure VM parameters safely such as the password of a new VM instance.
To configure the desired values, you can run the following commands:
qm set 9000 --ipconfig0 ip=dhcp
qm set 9000 --ciuser ubuntu --cipassword 'your-favorite_password'
Or you can set them directly via the Proxmox web interface as shown in the image below:
Step 5: Convert to Template
In order to create new VMs from our current VM we should transform it into a template with the following command:
qm template 9000
Step 6: Create a VM from the Temple
We can now use the previously created template (ID 9000) to create any number of new VMs with the command below:
qm clone 9000 201 --name "new-ubuntu-vm"
201
is the ID of the new VM.
Optional: Resize VM Disk Size
Note that the VM disk is currently somewhere between 3–4GB since it defaulted from the original disk image size. We can increase by running the following command:
qm resize 201 scsi0 +10G
The above command will increase the disk size by 10GB for the newly created VM of ID 201.
However, resizing in Proxmox does not mean the VM OS will automatically use the increased volume size. For that, access the VM via the console option (or SSH) and run the following commands (NOTE: These command should be run in the VM shell NOT the Proxmox shell):
sudo su
The above command will change your session from ubuntu user to root user. You can then run the df
command to see the partitions you currently have and their size. It should look something like the image below:
You can then run the below command to manage the partition:
parted /dev/sda
The output should look something like the screenshot below:
You can then resize the sda1 partition by running:
resizepart 1 100%
Conclusion
We have gone over the process of creating a Proxmox Ubuntu 24.04 template with cloud-init and created a VM from it.
If you need help with this process or are looking to perform a more complex private/public cloud deployment visit our website.
Top comments (0)