How To Create Proxmox Cloud Templates
- Before creating a cloud template you may want to edit the cloud image to include files or folders, install new packages in apt and update existing packages.
Templates are used to quickly create new VMs and there are some really cool things you can do to customize your templates. From editing how users to login to the distribution to ensuing specific packages are installed when the template is cloned. Cloud templates are templates with Cloudinit deployed to them. You can then use snippets to configure things like the networking inside new VMs. Here, we will create a Proxmox cloud template based on Debian.
Download Cloud Template
The process is exactly the same for each distribution. We are using a daily Debian template but you could use a CentOS or even a Ubuntu template. Some links to these are;
Simply use wget to get download the template;
cd /root wget https://cloud.debian.org/images/cloud/buster/daily/20210608-662/debian-10-genericcloud-amd64-daily-20210608-662.qcow2
Now it’s time to ensure we have the correct tools installed. First, we ensure libguestfs-tools is installed, set our editor to nano then open up the files we want to edit in the image.
# Install libguestfs apt-get install libguestfs-tools # Use nano as editor export EDITOR=nano # Mount VM Image virt-edit -a debian-10-genericcloud-amd64-daily-20210608-662.qcow2 /etc/cloud/cloud.cfg
Mount Distribution Image
Now we are ready to start editing the images files. A good place to start is the Cloud-init configuration. On all distributions this is located at /etc/cloud/cloud.cfg so, let’s open up that file and start editing.
virt-edit -a debian-10-genericcloud-amd64-daily-20210608-662.qcow2 /etc/cloud/cloud.cfg
In this file, all of the options related to the setup on servers. Most users will want to achieve things like enabling root logins and installing additional applications on newly created VMs. The statements are either true or false. For example, to enable root logins switch the disable_root: true statement to disable_root: false. You would also need to switch the lock_passwd: section to true.
Install New Packages
This file can also be used to install packages to newly created VMs. This is great to ensure any new VMs that are created using this image have the same packages installed. At the end of the cloud.cfg file add the required packages you want to install. Just list the required packages on a new line.
At this point, you could review our Cloud-init Modules post which shows some additional Cloud-init modules you can use to perform tasks like automatically setup apache virtual hosts and edit system files during boot.
packages: - nano - qemu-guest-agent - curl - net-tools - wget - htop
Changing SSH Settings
Save and close that file. Now, you could also edit other files like the default SSH settings. The process is exactly the same as above. Open up that file and change any required values. The default SSH file is always in the same location so just specify the path.
virt-edit -a debian-10-genericcloud-amd64-daily-20210608-662.qcow2 /etc/ssh/sshd_config
Create Template & VM
Now we have the image sorted with all of the edit we want its time to create the template and a VM. So next we need to create a VM and import the image to the VMs disk. We are using the settings that are the default ones on Proxmox setups. If you use a different bridge ensure you correct it in the code below.
# Create VM qm create 10000 --memory 2048 --net0 virtio,bridge=vmbr0 # Import the image qm importdisk 10000 debian-10-genericcloud-amd64-daily-20210608-662.qcow2 local # Attach disk to VM qm set 10000 --scsihw virtio-scsi-pci --scsi0 local:10000/vm-118-disk-0.raw # Attach a cloud-init drive. This will get our network settings qm set 10000 --ide2 local:cloudinit # Set boot device qm set 10000 --boot c --bootdisk scsi0 # Attach a serial console qm set 10000 --serial0 socket --vga serial0 # Create template qm template 10000
Now you have a template based on the custom edits you made. You can now use this to clone new VMs. This image will be in .raw format. In some cases you may want the hard drive to be in .qcow format. You can use the “move disk” feature to convert the template from .raw to .qcow format.
That’s the process complete. You have edited a cloud image and configured it to install custom packages on boot for new VMs.
How was this article? How To Create Proxmox Cloud Templates
You might also like
More from Proxmox
How to create a ZFS Swap Partition
Swap on Linux will assist if your environment is running short on memory. Usually, during setup, most distributions configure a …
How To Fix Proxmox Detected Hardware Unit Hang On Intel NICs
Proxmox Detected Hardware Unit Hang On Intel NICs In some cases, Intel NICs can cause a servers network card to freeze. …
How To Configure Bridged Proxmox Networking
How To Configure Bridged Proxmox Networking In a Routed Proxmox setup, you add your IP addresses to your interface then forward …