Gentoo now publishes official qcow2 images with Cloud-Init support. This post covers how to turn one into a template on Proxmox VE.
Cloud-Init handles the early initialization of a VM. On first boot it applies the hostname, IP, DNS, packages to install and other settings.
Combined with Cloud-Init, Proxmox templates make new VMs quick to deploy. The template creates a new VM quickly, and Cloud-Init initializes it, so all you set is the hostname and the initial user account. Creating a new VM no longer means installing an operating system from scratch.
Download
There are several variants here:

Pick the build with Cloud-Init support. Don’t hard-code the date; read the current filename from latest-di-amd64-cloudinit.txt:
MIRROR=https://distfiles.gentoo.org/releases/amd64/autobuilds
FILE=$(curl -s "$MIRROR/latest-di-amd64-cloudinit.txt" | awk '/^[0-9]/{print $1; exit}')
wget -c "$MIRROR/$FILE"
QCOW2=$(basename "$FILE")
Create the Template
First, create a VM named gentoo-cloudinit with machine type q35:
qm create 114514 --name gentoo-cloudinit --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci --machine q35
Import the qcow2 image and resize the disk:
ceph-pveis my storage; adjust it to your own setup.
qm set 114514 --scsi0 ceph-pve:0,discard=on,ssd=1,format=qcow2,import-from=/root/$QCOW2
qm disk resize 114514 scsi0 20G
format=qcow2is for directory-based storage. Ifceph-pveis Ceph RBD, dropformat=qcow2— RBD uses raw. Set the boot order:
qm set 114514 --boot order=scsi0
Configure CPU and memory:
qm set 114514 --cpu host --cores 2 --memory 2048
Configure UEFI:
qm set 114514 --bios ovmf --efidisk0 ceph-pve:1,format=qcow2,efitype=4m
Likewise, drop
format=qcow2for RBD storage.
Configure Cloud-Init:
qm set 114514 --ide2 ceph-pve:cloudinit
qm set 114514 --agent enabled=1
Adjust these settings to your environment; typically they cover the user name, DNS, SSH key, and how the IP is obtained:

For convenience, I converted it to a template:
qm template 114514
Usage
I’ll only cover using the template from the UI here. In a real production environment, try to avoid this approach.
Select Clone:

Note that the clone type has to be Full Clone, not Linked Clone. Enter a VM name and go ahead with the clone:

Once the clone finishes, start the VM and you have a fresh Gentoo to enjoy:

I didn’t set a static IP through Cloud-Init here; I checked the ARP table to find the VM’s IP instead. You can set a static IP through Cloud-Init, which is easier to manage.
Connect over SSH:

Afterword
Now that a Gentoo Cloud-Init image exists, the friction of running Gentoo in production is much lower.
You can use Packer to build images on a regular schedule.
You can also keep a build machine on the internal network, point emerge at a proxy, and even build offline. After publishing binpkgs, each node no longer spends a lot of time and resources compiling updates.
Gentoo is highly flexible and can be optimized for different hardware. You can take Portage snapshots and build binpkgs from a snapshot for incremental updates. With a large fleet you only need to maintain one Portage configuration, which keeps maintenance costs low.
In my view, Gentoo has real potential in production. It just depends on whether more companies are willing to be the first to try it and give back upstream.
Comments