DevOps Practices·6 min read·

Building Immutable VPS Golden Images with Packer and QEMU Automation

Eliminate configuration drift by baking hardened, pre-patched cloud images with systemd security policies and automated vulnerability scanning.

NB

Netbay Cloud Team

Netbay Engineering

On this page

Deploying fresh cloud instances by executing long shell scripts or running package updates at boot time is slow, fragile, and prone to breaking changes. Upstream package mirrors experience downtime, minor dependencies change beneath you, and a new server takes 10 to 15 minutes to reach operational readiness.

Immutable infrastructure solves this by baking fully configured 'golden images' ahead of time. Using HashiCorp Packer paired with QEMU/KVM hardware virtualization, engineering teams can compile, test, security-scan, and compress ready-to-run VPS disk images in automated CI pipelines.

The Immutable Image Lifecycle

Rather than configuring mutable servers in production, every release produces an immutable artifact:

  1. Base OS Ingestion: Packer boots an official minimal ISO (e.g., Ubuntu 24.04 LTS or Rocky Linux 9).
  2. Provisioning & Hardening: Installs locked application binaries, applies Center for Internet Security (CIS) benchmarks, configures systemd units, and removes temporary build artifacts.
  3. Automated Security Scanning: Trivy or OpenSCAP scans the virtual disk for CVEs and configuration compliance.
  4. Fast Boot Deployment: The resulting QCOW2 or raw disk image is uploaded to cloud storage, allowing fresh Netbay VPS instances to boot in under 25 seconds with zero startup scripts.
Immutable Golden Image Pipeline (Packer + QEMU) Official OS ISO Ubuntu 24.04 Minimal Cryptographic Hash Packer Automation QEMU / KVM Builder Applies CIS Hardening Profile Installs Application Binaries Trivy Vulnerability Scan: 0 CVEs Cleans machine-id & SSH host keys Netbay VPS Fleet Golden QCOW2 Image Boot Time: < 25 seconds Zero Cloud-Init Wait Immutable Operational Advantages Complete elimination of snowflake configurations across production clusters Rollbacks are instantaneous: simply boot the previous golden image release

Packer HCL Configuration

Here is a modern 'packer.pkr.hcl' definition for automated local QEMU builds:

hcl
# packer.pkr.hcl
packer {
  required_plugins {
    qemu = {
      source  = "github.com/hashicorp/qemu"
      version = "~> 1.1"
    }
  }
}

source "qemu" "ubuntu_base" {
  iso_url           = "https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso"
  iso_checksum      = "sha256:8762f7e13e51025a803e66881119e97e85741639f15038b34002e1b8a514d3b6"
  output_directory  = "build/output-golden"
  shutdown_command  = "echo 'packer' | sudo -S shutdown -P now"
  disk_size         = "20G"
  format            = "qcow2"
  accelerator       = "kvm"
  http_directory    = "http"
  ssh_username      = "ubuntu"
  ssh_password      = "packer"
  ssh_timeout       = "20m"
}

build {
  sources = ["source.qemu.ubuntu_base"]

  provisioner "shell" {
    inline = [
      "sudo apt-get update && sudo apt-get -y upgrade",
      "sudo apt-get install -y fail2ban auditd ufw",
      "sudo systemctl enable fail2ban",
      "sudo truncate -s 0 /etc/machine-id",
      "sudo rm -f /etc/ssh/ssh_host_*",
      "echo 'Golden image hardening completed successfully'"
    ]
  }
}

Running 'packer build packer.pkr.hcl' outputs a compressed, sanitized image ready for instantaneous cloud provisioning.

Expand
Server Golden Image Datacenter
Enterprise datacenter server deployment

Video Reference on Infrastructure as Code & Image Baking

Learn more about infrastructure automation and server image pipelines:

Terraform Infrastructure as Code
YouTube

Building immutable server images replaces slow and unpredictable mutable deployments with reliable, bit-identical production nodes.

Boot custom golden images in under 30 seconds on Netbay Cloud high-speed VPS hardware at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance