Create Rocky Linux Templates for Proxmox VE

Create Rocky Linux Templates for Proxmox VE

To avoid manually attaching a disk for each virtual machine, we aim to automate the process of creating VMs, assigning IP addresses, mapping disks, and connecting them to the correct network. In the case of Rocky Linux, there is a specific setting we need to configure to ensure the virtual machine boots properly and does not get stuck at 'Probing EDD...'

Prerequisites

Tools used and needed in this Article

The easiest approach is to install all the necessary tools directly on the Proxmox host. Since all images and templates are managed there, we install tools to edit and customize the qcow2 image provided by Rocky Linux. The only step required is to log in to your Proxmox host.

Creating a new Template

small scripts to automate the process

Set the default configuration for the virtual machine, including settings such as CPU sockets, CPU cores, memory, template ID, and other parameters.

Create a new File (e.g. config)

# Specifies the CPU model to be used for the VM
export QEMU_CPU_MODEL="x86-64-v2" 

# Specify the Socket and Core settings
export VM_CPU_SOCKETS=1
export VM_CPU_CORES=2

# Specify the Memory
export VM_MEMORY=4098

# Specify the user account for the template
export CLOUD_INIT_USER="skl" 

# Specify the SSH key
export CLOUD_INIT_SSHKEY="/root/.ssh/id_rsa.pub" 

# Specify the Network settings
export CLOUD_INIT_IP="dhcp"

# Specify the DNS Servers 
export CLOUD_INIT_NAMESERVER="1.1.1.1"

# Specify the ID which will be used in Proxmox
export TEMPLATE_ID=9002

# Specify the name of the template
export VM_NAME="rocky9-cloud-template"

# Specify the Path to the Image
export VM_DISK_IMAGE="/root/r9/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2"

Create another script for the Customization and VM creation (e.g create)

#/bin/bash
# Download the Image
wget https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2

# Customize the Image and install qemu-guest-agent
virt-customize -a Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 --install qemu-guest-agent

# Create VM. 
qm create ${TEMPLATE_ID} --name ${VM_NAME} --cpu ${QEMU_CPU_MODEL} --sockets ${VM_CPU_SOCKETS} --cores ${VM_CPU_CORES} --memory ${VM_MEMORY} --numa 1 --net0 virtio,bridge=vmbr0 --ostype l26 --agent 1 --scsihw virtio-scsi-single

# Import Disk
qm set ${TEMPLATE_ID} --scsi0 local-lvm:0,import-from=${VM_DISK_IMAGE}

# Add Cloud-Init CD-ROM drive. This enables the VM to receive customization instructions during boot.
qm set ${TEMPLATE_ID} --ide2 local-lvm:cloudinit --boot order=scsi0

# Cloud-init network-data
qm set ${TEMPLATE_ID} --ipconfig0 ip=${CLOUD_INIT_IP} --nameserver ${CLOUD_INIT_NAMESERVER}

# Cloud-init user-data
qm set ${TEMPLATE_ID} --ciupgrade 1 --ciuser ${CLOUD_INIT_USER} --sshkeys ${CLOUD_INIT_SSHKEY}

# Cloud-init regenerate ISO image, ensuring that the VM will properly initialize with the desired parameters.
qm cloudinit update ${TEMPLATE_ID}

Create the last script to convert the VM into a template (e.g template)

qm set ${TEMPLATE_ID} --name "${VM_NAME}"

qm template ${TEMPLATE_ID}

After running the scripts you should have a new template which can be used in Terraform to deploy new Rocky instances.