Latest news from 5wire Networks

How to prepare a Cloud-Init OS Templates for Proxmox

This guide will show you how to prepare a Cloud Image for a Proxmox VM Template. The same process works for any Cloud-Init OpenStack based image. 

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

export EDITOR=nano

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 –

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. 

wget https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-8.6-20220718.x86_64.qcow2

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.

Disable Root

Once it’s opened, you will need to change the following line –

disable_root 1

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. 

disable_root 0

Lock_passwd

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 –

lock_passwd true

Change this to –

lock_passwd false

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

PermitRootLogin

We change PermitRootLogin

PermitRootLogin no

Or

PermitRootLogin without-password

Change it to –

PermitRootLogin Yes

Password Authentication

Then, look for PasswordAuthentication –

PasswordAuthentication no

Change it to

PasswordAuthentication yes

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.

25% DISCOUNT FOR LIFE

Life time discount when you purchase your first order. Applies to Web Hosting, Reseller Hosting, and Cloud Servers.

Free Domain included on yearly Web Hosting plans.

Use code WEBOFF at the checkout!

Terms and Conditions apply. Voucher code is only valid for new customers.