We deploy Cloud-Init based KVM Cloud Servers from WHMCS. The IP address and credentials are allocated by WHMCS. Once one template has been setup, you can easily reinstall new containers to test whether the image works.
Step 1: Setup the environment
First of all, you will need to install libguestfs-tools
apt-get install libguestfs-tools
We use the virt-edit part of libguestfs-tools to make any amendments to the cloud image before converting the container to a template in Proxmox.
Our preference for text editing is nano. To set nano as default, use the command below
Now, if you run the following command you can see that nano has been set as the default editor
printenv | grep EDITOR
You will see the below in the terminal
printenv | grep EDITOR EDITOR=/bin/nano
Step 2: Find your Cloud Image
You are looking for a .img or .qcow2 disk image. We’ve included some links below to help your search –
- Debian – https://cloud.debian.org/images/cloud/
- CentOS – https://cloud.centos.org/
- Ubuntu – https://cloud-images.ubuntu.com/
- AlmaLinux – https://github.com/AlmaLinux/cloud-images
- Rocky Linux – https://rockylinux.org/cloud-images/
This link on the OpenStack website is also useful – https://docs.openstack.org/image-guide/obtain-images.html
Once you have found the image, SSH into your Proxmox server and grab the image directory to the server. We will use AlmaLinux 8 for this example.
Step 3: Prepare the Cloud Image
Now we need to setup the Cloud Image to be ready for automated provisioning based upon the cloud-init request passed to the template during setup and creation.
For the purpose of this guide, we will enable root and SSH password authentication. This is a precaution in case you have any issues and need to log into the VM to diagnose the issue.
Using virt-edit, we will now edit the cloud.cfg file within the image –
virt-edit -a AlmaLinux-8-GenericCloud-8.6-20220718.x86_64.qcow2 /etc/cloud/cloud.cfg
It may take a few seconds to open the file.
Once it’s opened, you will need to change the following line –
With some cloud images, you may see true / false instead of 1 / 0.
- True = 1
- False = 0
You must stick to the formatting that you discover when you open the file, changing this to a different format could break the cloud image.
Change disable_root to the below. This will set cloud-init not to disable root login on the first boot in order to allow root based login access.
Next, you will need to scroll down in the file. We need to change the lock_passwd from true to false. Without this, you will be unable to use password based authentication to access the container.
This is the line you are looking for –
Change this to –
The last part is optional and would go in the same file. We install other packages whilst the container is being created so it’s ready to go straight away. The formatting is critical, if you amend this it will likely break the cloud image.
Under the packages: heading, we add the following –
packages: - qemu-guest-agent - nano - wget - curl - net-tools
Use Control + X and type Y to save and exit the file.
Step 4: Modify SSHD_CONFIG
Using virt-edit again, we need to make sure our SSH config is correctly setup to allow root and password based authentication.
virt-edit -a AlmaLinux-8-GenericCloud-8.6-20220718.x86_64.qcow2 /etc/ssh/sshd_config
We change PermitRootLogin
Change it to –
Then, look for PasswordAuthentication –
Change it to
The cloud image is now ready to be turned into template. Follow the next guide on How to create a Proxmox Template with a Cloud-Init image.