Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 36 ยท Images for Cloud and VMs

VirtualBox, VMware and QEMU Images

Build local and on-premises VM images with Packer: ISO installs, boot commands, preseed and cloud-init, VirtualBox, VMware and QEMU builders, Vagrant boxes and Windows notes.

Cloud builders start from an image that already exists. Local hypervisor builders often start one step earlier, from an installation ISO, and drive the operating system installer without a human. That is how Vagrant boxes, VMware templates and KVM disk images are produced. It is also how you create a base image when no cloud marketplace image fits.

Hypervisors cannot run in the browser, so every HCL snippet here is read-only and the runnable examples are labelled JavaScript stand-ins. Check the plugin documentation for the exact arguments of your Packer plugin version.

Three families of builders

Builder Plugin Output Typical use
virtualbox-iso / virtualbox-ovf virtualbox OVF/OVA + VMDK Vagrant boxes on a laptop
vmware-iso / vmware-vmx vmware VMX + VMDK Workstation, Fusion, ESXi
vsphere-iso / vsphere-clone vsphere vSphere template Datacenter templates
qemu qemu qcow2 / raw KVM, OpenStack, Proxmox imports
proxmox-iso proxmox Proxmox template Homelab and private cloud

The -iso builders install from an ISO. The -ovf/-vmx/-clone builders start from an existing VM, which is faster and a good second stage after a minimal base.

An ISO build, step by step

HCL
source "qemu" "debian" {
  iso_url          = "https://example.com/debian-12-netinst.iso"
  iso_checksum     = "sha256:0123456789abcdef..."
  output_directory = "output-debian"
  disk_size        = "10G"
  format           = "qcow2"
  accelerator      = "kvm"
  memory           = 2048
  headless         = true

  http_directory = "http"
  boot_wait      = "5s"
  boot_command = [
    "<esc><wait>",
    "auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<enter>"
  ]

  ssh_username = "packer"
  ssh_password = "packer-temporary"
  ssh_timeout  = "30m"
  shutdown_command = "sudo shutdown -P now"
}

What happens:

  1. Packer downloads the ISO and verifies iso_checksum. Always set it; it protects against corrupted or swapped installers.
  2. It creates a virtual disk and a VM, then boots the ISO.
  3. After boot_wait, it types boot_command as keystrokes. This is how you reach the installer's boot prompt and point it to an answer file.
  4. Packer serves http_directory on a temporary web server. The installer fetches preseed.cfg (Debian), autoinstall/cloud-init user-data (Ubuntu), a kickstart file (RHEL family) or Autounattend.xml (Windows, often on a floppy or secondary ISO).
  5. When the installer finishes and the VM reboots, Packer connects by SSH (or WinRM) with the temporary credentials from the answer file and runs your provisioners.
  6. shutdown_command stops the VM cleanly and Packer collects the disk.

The weak spot is boot_command: it depends on timing and on the exact installer screen, so it breaks when the ISO version changes. Keep one working command per ISO release, test after every ISO bump and use PACKER_LOG=1 to watch the VM console.

Temporary credentials

The ssh_password above exists only so Packer can log in. Remove it or lock the account in a final provisioner, and replace it by keys or by your normal identity mechanism when the image boots. Never ship an image with a known password.

Output formats and Vagrant

QEMU produces qcow2 (compressed, thin) or raw disks. VirtualBox produces OVF and VMDK, which the vagrant post-processor can wrap into a .box file (see post-processors). Convert between disk formats with qemu-img convert, for example qcow2 to VMDK for VMware or to raw for cloud import.

Windows images

Windows builds differ in three ways:

  • The communicator is winrm, not SSH (or OpenSSH if you install it in the answer file).
  • The installer uses Autounattend.xml, which also creates the temporary Administrator account and enables WinRM.
  • Finish with Sysprep (sysprep /generalize /oobe /shutdown) so each clone gets a new SID and computer name. Cloud builders such as azure-arm often do it with a final inline provisioner.

Speed and size tips

  • Zero free space and shrink before export so compression works (dd if=/dev/zero ... then delete the file, or fstrim).
  • Use -ovf/-clone stages for layers you rebuild often.
  • Use headless = true on servers and CI; use PACKER_LOG for the console.
  • Pin ISO versions; do not use "latest" URLs, they change under you.

Try it: render a boot command

Boot commands use placeholders such as {{ .HTTPIP }}. This stand-in substitutes them to show what Packer would type.

JS Boot command renderer (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Try it: verify an ISO checksum

Packer compares the downloaded file with iso_checksum. This stand-in shows the idea with a simple FNV hash (real Packer uses SHA-256 or similar).

JS Checksum guard (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is boot_command for?

    Packer types the keys after boot_wait so the installer starts unattended.
  2. 2. Why must you set iso_checksum?

    The checksum guards against corrupted or swapped ISOs.
  3. 3. Which file does an unattended Windows installation read?

    Preseed is Debian, kickstart is RHEL, Autounattend.xml is Windows.
  4. 4. What should you do with the temporary build password?

    A known password in a shared image is a security hole.

Summary

  • ISO builders drive an installer with boot_command and an answer file served over HTTP.
  • Always pin the ISO and its checksum; keep boot_command tested per ISO release.
  • Output formats (qcow2, OVF, VMDK) can be converted or wrapped for Vagrant.
  • Windows needs WinRM, Autounattend.xml and Sysprep.

Next: The Docker builder and container images