Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 36 ยท Builders and Provisioners

Packer VM Builders: QEMU, VirtualBox and VMware ISO Builds

Build virtual machine images from an installer ISO with Packer: iso_url and checksums, boot_command, HTTP-served autoinstall files, shutdown, output formats and acceleration.

Cloud builders start from a ready-made image. Virtualization builders often start from nothing but an installer ISO and have to "type" the installer's answers themselves. That makes them slower and fiddlier, but they give you complete control, work on your laptop and let you create images for private clouds (KVM, OpenStack, VMware, Proxmox) and Vagrant boxes. This lesson explains how an ISO build works and shows the key settings of the qemu, virtualbox-iso and vmware-iso builders.

Virtual machines cannot run on this site and Packer is not installed here, so everything is read-only. No build output is shown. The Python stand-in expands a boot_command-style string so you can see what Packer sends to the VM.

How an ISO build works

flowchart TB
  A["Download ISO<br/>verify checksum"] --> B["Create empty VM<br/>(disk, CPU, memory)"]
  B --> C["Start HTTP server<br/>serving http_directory"]
  C --> D["Boot VM from ISO"]
  D --> E["Wait (boot_wait), then type<br/>boot_command keys"]
  E --> F["Installer reads answers<br/>from the HTTP server"]
  F --> G["Installer finishes, reboots"]
  G --> H["Packer connects over SSH"]
  H --> I["Provisioners run"]
  I --> J["shutdown_command<br/>save disk image"]

The unattended-install dance. Keystrokes start it; an answer file does the rest.

The pieces that you must supply:

  1. The ISO: iso_url (a URL or local path) and iso_checksum.
  2. An answer file: kickstart for RHEL-family, preseed for Debian, autoinstall (cloud-init user-data) for Ubuntu Server, autounattend.xml for Windows, AutoYaST for SUSE.
  3. A boot_command: the keys typed at the boot menu that point the installer at the answer file.
  4. SSH access configured by the answer file, so Packer can log in afterwards.
  5. A shutdown_command that powers the machine off.

QEMU

QEMU (with KVM acceleration on Linux) produces disk images such as QCOW2, which KVM, OpenStack and Proxmox consume directly.

HCL
source "qemu" "ubuntu" {
  iso_url          = "https://example.com/ubuntu-24.04-live-server-amd64.iso"
  iso_checksum     = "sha256:0000000000000000000000000000000000000000000000000000000000000000"

  format           = "qcow2"
  disk_size        = "20G"
  memory           = 2048
  cpus             = 2
  accelerator      = "kvm"           # "hvf" on macOS, "whpx" on Windows, "tcg" is slow software emulation
  headless         = true            # no VM window

  http_directory   = "http"          # contains user-data and meta-data
  boot_wait        = "5s"
  boot_command     = [
    "c<wait>",
    "linux /casper/vmlinuz autoinstall 'ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/' ---<enter>",
    "initrd /casper/initrd<enter>",
    "boot<enter>",
  ]

  ssh_username     = "ubuntu"
  ssh_password     = "build-only-password"
  ssh_timeout      = "30m"
  shutdown_command = "sudo shutdown -P now"

  output_directory = "output-ubuntu"
  vm_name          = "ubuntu-24.04.qcow2"
}

Notes:

  • The checksum placeholder above is an example. Use the real checksum from the vendor, in the form sha256:<hex> or a file:https://.../SHA256SUMS reference.
  • {{ .HTTPIP }} and {{ .HTTPPort }} are replaced by the address of Packer's temporary web server.
  • The password is for the build only; remove it or lock the account in a cleanup provisioner and use keys in production.
  • format can be qcow2 or raw. Convert later with qemu-img convert if needed.
  • The key sequence in boot_command depends on the ISO version; check it interactively once by watching the VM (headless = false).

VirtualBox

HCL
source "virtualbox-iso" "debian" {
  guest_os_type    = "Debian_64"
  iso_url          = "https://example.com/debian-12-netinst.iso"
  iso_checksum     = "sha256:0000000000000000000000000000000000000000000000000000000000000000"

  cpus             = 2
  memory           = 2048
  disk_size        = 20000                 # in MB for this builder
  headless         = true
  guest_additions_mode = "disable"         # skip installing Guest Additions

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

  ssh_username     = "debian"
  ssh_password     = "build-only-password"
  shutdown_command = "sudo shutdown -h now"

  format           = "ova"                 # or "ovf"
  vboxmanage = [
    ["modifyvm", "{{ .Name }}", "--nat-localhostreachable1", "on"],
  ]
}

vboxmanage runs extra VBoxManage commands before boot. Use guest_os_type values reported by VBoxManage list ostypes. Exported OVA files import into VirtualBox, VMware and many other tools.

Related builders: virtualbox-ovf (start from an exported machine), virtualbox-vm (provision an already-registered VM).

VMware

HCL
source "vmware-iso" "rocky" {
  guest_os_type    = "rockylinux-64"
  iso_url          = "https://example.com/Rocky-9-x86_64-minimal.iso"
  iso_checksum     = "sha256:0000000000000000000000000000000000000000000000000000000000000000"

  version          = 19                    # VMware hardware version
  cpus             = 2
  memory           = 2048
  disk_size        = 20480                 # MB
  disk_adapter_type = "nvme"

  http_directory   = "http"
  boot_command     = [
    "<up><tab> inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter>",
  ]

  ssh_username     = "packer"
  ssh_password     = "build-only-password"
  shutdown_command = "sudo shutdown -h now"
}

vmware-iso works with VMware Workstation, Fusion and (with remote settings) ESXi. For vCenter-managed clusters, the vsphere-iso and vsphere-clone builders from the vsphere plugin talk to the vCenter API and can convert the result into a template in place.

Boot commands explained

A boot_command is a list of strings sent as keystrokes. Special tokens appear in angle brackets:

Token Meaning
<enter>, <tab>, <esc>, <up>, <down>, <f10> Press that key
<wait>, <wait5>, <wait10s> Pause for 1 second, 5 seconds, 10 seconds
<leftShiftOn>/<leftShiftOff> Hold and release a modifier
{{ .HTTPIP }}, {{ .HTTPPort }} Address of Packer's HTTP server
{{ .Name }} VM name (builder specific)

Expand one in a stand-in

This Python stand-in expands a boot command into a readable key sequence with substituted address values, much like you would read in a debug log. It is a simplified model: real Packer supports many more keys and timing rules.

Python Stand-in: expand a boot_command

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

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Practical tips

  • Cache: Packer caches downloaded ISOs in packer_cache/; verify the checksum so a changed or broken ISO is detected.
  • Speed: use accelerator = "kvm"/hvf, give the VM at least 2 CPUs, and keep headless = true in CI.
  • Debugging a stuck install: set headless = false and watch the console, or use -debug. A wrong boot_command timing is the most common failure.
  • Networking: the guest must reach your computer's HTTP server. Firewalls on the host often block the random port; allow it or set http_port_min and http_port_max.
  • Windows: provide autounattend.xml through a floppy or secondary ISO (floppy_files, cd_files) and use WinRM or OpenSSH as communicator.
  • Sysprep and cleanup: before shutdown, remove build-only users, SSH host keys (they regenerate on first boot) and machine IDs so clones are unique (Shell and file provisioners shows cleanup scripts).

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the job of boot_command?

    boot_command sends keys to the VM console, usually pointing the installer at an answer file.
  2. 2. What does http_directory do?

    Packer starts a temporary web server for that directory; {{ .HTTPIP }} and {{ .HTTPPort }} give its address.
  3. 3. Which accelerator is the right choice for QEMU on Linux?

    KVM uses hardware virtualization on Linux; hvf is macOS; tcg is slow software emulation.
  4. 4. Why verify iso_checksum?

    A mismatch stops the build before an untrusted installer runs.
  5. 5. Which builder suffix starts from an exported machine rather than an installer?

    virtualbox-ovf starts from an OVF/OVA export.

Summary

  • ISO builders (qemu, virtualbox-iso, vmware-iso, vsphere-iso) boot an installer and automate it with boot_command plus an answer file served from http_directory.
  • Always set iso_url with a verified iso_checksum, plus ssh_username, a communicator timeout and a shutdown_command.
  • QEMU makes QCOW2/raw disks, VirtualBox exports OVA/OVF, VMware builds VMX-based machines; the vsphere plugin targets vCenter.
  • Most failures come from boot timing, unreachable HTTP servers or missing SSH setup in the answer file.
  • Clean build-only credentials and machine-unique data before shutdown.

Next: Shell and file provisioners