Cloud-init enabled AlmaLinux 8 template for Proxmox to facilitate automatic instance deploy by Terraform
Create Proxmox Template (AlmaLinux 8)
Prepare Proxmox node for Template creation process
Update/Upgrade all packages. And install libguestfs-tools package
sudo apt update
sudo apt upgrade -y
sudo apt install libguestfs-tools -y
Add current user to kvm group to be able to use the virt-edit command
sudo usermod -aG kvm <username>
Logout and login again and add an environment variable EDITOR which is used by virt-edit
export EDITOR=nano
printenv | grep EDITOR
Download and Prepare AlmaLinux8 cloud image
Download AlmaLinux8 cloud image
http://mirror.xeonbd.com/almalinux/8.7/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2 -O almalinux8.qcow2
Customize cloud.cfg
file for cloud-init enabling SSH PasswordAuthentication
by adding a line
virt-edit -a almalinux8.qcow2 /etc/cloud/cloud.cfg
ssh_pwauth: 1
Customize sshd_conf
file for ssh configuration
virt-edit -a almalinux8.qcow2 /etc/ssh/sshd_config
After nano opens up the sshd_config
file, do the following changes, save the file and exit
- Comment HostKey(s)
- Comment SyslogFacility AUTHPRIV
- Comment AuthorizedKeysFile
- UnComment PubkeyAuthentication yes
- Comment GSSAPIAuthentication yes
- Comment GSSAPICleanupCredentials no
- Comment AcceptEnv(s)
- Add AcceptEnv LC_*
Customize SELINUX
configuration file
virt-edit -a almalinux8.qcow2 /etc/selinux/config
After nano opens up the config
file, change SELINUX
value to permissive
, save the file and exit
SELINUX=permissive
Since AlmaLinux-8's cloud-init adds /etc/resolv.conf
files instead of replacing it. It need to be edited from the cloud image, before template creation
virt-edit -a almalinux8.qcow2 /etc/resolv.conf
After nano opens up the resolv.conf
file, change nameserver
value to 172.16.4.1
, save the file and exit
nameserver 172.16.4.1
Prepare Cloud image before starting to create a new VM from it
Setup Time-Zone, Run update for all packages, Install additional packages
virt-customize -a almalinux8.qcow2 --timezone "Asia/Dhaka"
virt-customize -a almalinux8.qcow2 --update
virt-customize -a almalinux8.qcow2 --install qemu-guest-agent,nano,wget
virt-customize -a almalinux8.qcow2 --run-command 'sudo systemctl enable qemu-guest-agent'
Set password for root
read -sp "Password for root: " pwd && virt-customize -a almalinux8.qcow2 --root-password password:$pwd
Create Proxmox Template from prepared cloud image
Create a VM with minimum configuration
sudo qm create 8073 --name "almalinux8-CI-Template" --memory 1024 --cores 1 --net0 virtio,bridge=vmbr0
sudo qm importdisk 8073 almalinux8.qcow2 pve-rbd
Additional settings for the new VM
sudo qm set 8073 --scsihw virtio-scsi-pci --scsi0 pve-rbd:vm-8073-disk-0
sudo qm set 8073 --boot c --bootdisk scsi0
sudo qm set 8073 --ide2 pve-rbd:cloudinit
sudo qm set 8073 --agent 1
sudo qm set 8073 --sshkey .ssh/myKey.pub
Set cloud-init settings for the VM
sudo qm set 8073 --ciuser almalinux8 --citype nocloud --nameserver 172.16.4.1 --ipconfig0 ip=dhcp --searchdomain cs.net
read -sp 'Password for centos: ' pwd && sudo qm set 8073 --cipassword $pwd
Convert the new VM to template
sudo qm template 8073