Skip to content

Instantly share code, notes, and snippets.

@tristanmorgan
Last active August 3, 2023 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanmorgan/0cf49d4c6f080c144ef5f0c068f07de9 to your computer and use it in GitHub Desktop.
Save tristanmorgan/0cf49d4c6f080c144ef5f0c068f07de9 to your computer and use it in GitHub Desktop.
Packer file to build an Alpine Linux image for Qemu
packer {
required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = "~> 1"
}
}
}
source "qemu" "alpine" {
iso_url = "https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.2-x86_64.iso"
iso_checksum = "sha256:6bc7ff54f5249bfb67082e1cf261aaa6f307d05f64089d3909e18b2b0481467f"
shutdown_command = "echo 'packer' | poweroff"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
headless = true
http_content = {
"/latest/user_data" = <<EOF
echo running packer > logfile.txt
EOF
}
machine_type = "q35"
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "5m"
vm_name = "alpine_3.18.2.qcow2"
vnc_bind_address = "0.0.0.0"
vnc_use_password = true
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<wait>root<enter><wait>setup-alpine<enter><enter>alpine<enter>eth0<enter>dhcp<enter>n<enter><wait10>vagrant<enter>vagrant<enter>UTC<enter><wait10><enter>r<wait5><enter>no<enter><wait><wait5>openssh<enter><wait5>yes<enter>https://github.com/tristanmorgan.keys<enter>vda<enter>sys<enter>y<enter><wait2m><enter><wait10>"]
}
build {
sources = ["source.qemu.alpine"]
provisioner "shell" {
inline = [
"apk update",
"apk upgrade",
"echo packer success."
]
}
}
@tristanmorgan
Copy link
Author

to run afterwards I used...
qemu-system-x86_64 -machine type=q35,accel=kvm -name alpine_3.18.2.qcow2 -m 512M -drive file=output-alpine/alpine_3.18.2.qcow2,if=ide -nographic -enable-kvm -cpu host

@tristanmorgan
Copy link
Author

P.S. buried in those boot_commands is a url to public keys, please use your own ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment