Last active
August 3, 2023 04:32
-
-
Save tristanmorgan/0cf49d4c6f080c144ef5f0c068f07de9 to your computer and use it in GitHub Desktop.
Packer file to build an Alpine Linux image for Qemu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | |
] | |
} | |
} |
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
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