aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-09-11 19:38:39 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-11 18:33:34 -0700
commit14c11b790341cf332a712f142f61e2f18503a072 (patch)
treea5b34afb537fc816643255737a82f0a3e4bc16ef
parentAdd afterboot vm initialization setup script and makefile (diff)
downloadsite-server-images-14c11b790341cf332a712f142f61e2f18503a072.zip
Add build for x86 openbsd image
-rw-r--r--Makefile41
-rw-r--r--README.md13
-rw-r--r--configs/doas.conf2
-rw-r--r--openbsd.pkr.hcl72
-rw-r--r--openbsd79-amd64.pkvars.hcl8
-rw-r--r--openbsd79-arm64.pkvars.hcl (renamed from openbsd79-arm64-macos.pkvars.hcl)1
-rwxr-xr-xscripts/setup.sh4
7 files changed, 98 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index 1b5c630..c1343f9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,24 @@
SHELL := /bin/sh
-VARS_FILE := openbsd79-arm64-macos.pkvars.hcl
+ARCH ?= arm64
BUILD_DIR := build
-DISK := $(BUILD_DIR)/openbsd-7.9-aarch64.qcow2
-EFIVARS_RUN := $(BUILD_DIR)/efivars-run.fd
EDK2_DIR := /opt/homebrew/share/qemu
-EDK2_CODE := $(EDK2_DIR)/edk2-aarch64-code.fd
-EDK2_VARS := edk2-arm-vars.fd
SSH_PORT := 2222
-SSH_USER := eugene
+SSH_USER := admin
+SSH_KEY := ~/.ssh/id_rsa
CPU := 1
MEMORY := 4096M
PACKER_LOG := 1
+VERSION := 7.9
+VERSION_SHORT := 79
+QEMU_ARCH := $(if $(filter arm64,$(ARCH)),aarch64,x86_64)
+VARS_FILE := openbsd$(VERSION_SHORT)-$(ARCH).pkvars.hcl
+DISK := $(BUILD_DIR)/openbsd-$(VERSION)-$(QEMU_ARCH).qcow2
+EFIVARS_RUN := $(BUILD_DIR)/efivars-run.fd
+EDK2_CODE := $(EDK2_DIR)/edk2-aarch64-code.fd
+EDK2_VARS := edk2-arm-vars.fd
+
export PACKER_LOG
.PHONY: all init build run ssh clean
@@ -22,16 +28,16 @@ all: build
init:
packer init .
-build: init
- rm -rf $(BUILD_DIR)
+build: init clean
+ifeq ($(ARCH),arm64)
cp $(EDK2_DIR)/$(EDK2_VARS) ./$(EDK2_VARS)
- packer build -var-file=$(VARS_FILE) .
+endif
+ packer build -only qemu.openbsd-$(ARCH) -var-file=$(VARS_FILE) .
# Run the headless VM (SSH via port-forwarded localhost:$(SSH_PORT))
run:
+ifeq ($(ARCH),arm64)
cp ./$(EDK2_VARS) $(EFIVARS_RUN)
- # If you want to run with a GUI, replace -nographic
- # with `-display cocoa`.
qemu-system-aarch64 \
-machine type=virt,accel=hvf \
-cpu host \
@@ -46,9 +52,20 @@ run:
-drive file=$(DISK),if=virtio,cache=writeback,discard=ignore,format=qcow2 \
-drive file=$(EDK2_CODE),if=pflash,unit=0,format=raw,readonly=on \
-drive file=$(EFIVARS_RUN),if=pflash,unit=1,format=raw
+else
+ qemu-system-x86_64 \
+ -machine type=q35,accel=tcg \
+ -cpu max \
+ -m $(MEMORY) \
+ -smp $(CPU) \
+ -nographic \
+ -netdev user,id=net0,hostfwd=tcp::$(SSH_PORT)-:22 \
+ -device virtio-net,netdev=net0 \
+ -drive file=$(DISK),if=virtio,cache=writeback,discard=ignore,format=qcow2
+endif
ssh:
- ssh -p $(SSH_PORT) $(SSH_USER)@127.0.0.1
+ ssh -i $(SSH_KEY) -p $(SSH_PORT) $(SSH_USER)@127.0.0.1
clean:
rm -rf $(BUILD_DIR)
diff --git a/README.md b/README.md
index 2a475a8..623594d 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,9 @@
This repository contains a template for building OpenBSD boxes for QEMU using Packer.
-It may work for other configurations with additional variables added and some
-variables changed. However, I only use it for running OpenBSD on an ARM Mac, so
-that is the only configuration that is actively tested.
+I only use it for running OpenBSD on an ARM Mac and for building QEMU images to
+run in Hetzner on x86_64 machines, so that is the only configuration that is
+actively tested.
## Installation
@@ -14,10 +14,11 @@ First, ensure you have QEMU installed:
brew install qemu
```
-Then, you can build the box with the following:
+Then, you can build the box with the following, either for ARM64 or AMD64:
```sh
-make
+ARCH=amd64 make
+ARCH=arm64 make
```
## Usage
@@ -25,7 +26,7 @@ make
Once your image is built, you can run it:
```sh
-make run
+ARCH=arm64 make run
```
Once the system is up, you can SSH in using:
diff --git a/configs/doas.conf b/configs/doas.conf
index 96cf24d..9ed8576 100644
--- a/configs/doas.conf
+++ b/configs/doas.conf
@@ -1 +1 @@
-permit nopass keepenv :wheel
+permit persist keepenv :wheel
diff --git a/openbsd.pkr.hcl b/openbsd.pkr.hcl
index 80cae35..893439a 100644
--- a/openbsd.pkr.hcl
+++ b/openbsd.pkr.hcl
@@ -12,11 +12,6 @@ variable "version" {
}
}
-variable "admin_user" {
- type = string
- description = "Username of the admin user on the VM"
-}
-
variable "ssh_public_key" {
type = string
description = "Public SSH key to associate with the admin user for login"
@@ -29,24 +24,16 @@ variable "ssh_private_key_file" {
variable "arch" {
type = string
- default = "arm64"
validation {
- condition = contains(["arm64"], var.arch)
- error_message = "The arch must be one of: arm64."
+ condition = contains(["amd64", "arm64"], var.arch)
+ error_message = "The arch must be one of: amd64, arm64."
}
}
-variable "accelerator" {
+variable "admin_user" {
type = string
- default = "hvf"
- description = <<-EOT
- The accelerator type to use when running the VM. See the following for more information:
- https://developer.hashicorp.com/packer/integrations/hashicorp/qemu/latest/components/builder/qemu#optional
- EOT
- validation {
- condition = contains(["none", "kvm", "tcg", "hax", "hvf", "whpx", "xen"], var.accelerator)
- error_message = "Must be one of: 'none', 'kvm', 'tcg', 'hax', 'hvf', 'whpx', 'xen'."
- }
+ description = "Username of the admin user on the VM"
+ default = "admin"
}
variable "mirror" {
@@ -82,7 +69,50 @@ locals {
root_password = "temp"
}
-source "qemu" "openbsd" {
+source "qemu" "openbsd-amd64" {
+ vm_name = "openbsd-${var.version}-amd64.qcow2"
+ iso_url = "${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/install${local.version_short}.iso"
+ iso_checksum = "file:${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/SHA256"
+ output_directory = "build"
+ qemu_binary = "qemu-system-x86_64"
+ machine_type = "q35"
+ cpu_model = "max"
+ accelerator = "tcg"
+ memory = var.memory
+ disk_interface = "virtio"
+ disk_size = "${var.disk_size}G"
+ disk_compression = true
+ format = "qcow2"
+ ssh_username = "root"
+ ssh_password = local.root_password
+ ssh_timeout = "30m"
+
+ http_content = {
+ "/install.conf" = templatefile("${path.root}/templates/install.conf.pkrtpl.hcl", {
+ hostname = var.hostname
+ user = var.admin_user
+ ssh_key = var.ssh_public_key
+ root_password = local.root_password
+ mirror = var.mirror
+ version = var.version
+ version_short = local.version_short
+ arch = var.arch
+ })
+ }
+
+ boot_command = [
+ "<wait>S<enter><wait>",
+ "set tty com0<enter><wait>",
+ "autoinstall<enter><wait>",
+ "http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf<enter>",
+ ]
+ boot_wait = "20s"
+ shutdown_command = "shutdown -p now"
+ headless = false
+ qemuargs = [["-display", "cocoa"]]
+}
+
+source "qemu" "openbsd-arm64" {
vm_name = "openbsd-${var.version}-aarch64.qcow2"
iso_url = "${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/install${local.version_short}.iso"
iso_checksum = "file:${var.mirror}/pub/OpenBSD/${var.version}/${var.arch}/SHA256"
@@ -90,7 +120,7 @@ source "qemu" "openbsd" {
qemu_binary = "qemu-system-aarch64"
machine_type = "virt"
cpu_model = "host"
- accelerator = "hvf"
+ accelerator = "hvf"
memory = var.memory
disk_interface = "virtio"
disk_size = "${var.disk_size}G"
@@ -134,7 +164,7 @@ source "qemu" "openbsd" {
}
build {
- sources = ["source.qemu.openbsd"]
+ sources = ["source.qemu.openbsd-amd64", "source.qemu.openbsd-arm64"]
provisioner "file" {
source = "configs/doas.conf"
diff --git a/openbsd79-amd64.pkvars.hcl b/openbsd79-amd64.pkvars.hcl
new file mode 100644
index 0000000..c8624c3
--- /dev/null
+++ b/openbsd79-amd64.pkvars.hcl
@@ -0,0 +1,8 @@
+version = "7.9"
+arch = "amd64"
+memory = 4096
+disk_size = 40
+ssh_public_key = <<-EOF
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC31SiCeUZSJN3CueH6/+7UQvxwxkT/QkaDK6ZGdnkdpCWxRVp+0CTO4WG3u0PVEVd9DvSd81CEqrFaKxtKyiSh+4Va0A/mqY27tX7NZzEQLM/zLQrdESmaHY6EyQM0wlCtBKfNzuQqCa9QEw4TwkyMLOJzyI+bRsfeSHNCfxqnqGIMKKFiaF0ygakvQz57nWuKLOgqWsWkzFTuJKGI0OhefFBcZ4VzoCLV8i1zbB2AebhsmbyMza9OUF3px44atSM3o33Jto3gy7LTWtxU83NZU+wLEqY6IvcWx9BbSQZxAwEwXxUFmnzcX+FTkTiOs/Q2nXiLl2ggsGJffAq9Z1SGMCNGxT+Syyta5UtfBVVQdn6xtUxpppHwrdGC+TR8C5F9U12gsZRzvKkz0SSt5M4WHG2gna5rDgTisDbrEAsrqpmUqY9iSBzgAyk5xOi6fdI+r67gpjRSs+PNvDle3gImfIkPnEQg4eWJ54iKjfH+yd8vBk25T/ahu3J9rGgxp18= eugene@laptop
+EOF
+ssh_private_key_file = "~/.ssh/id_rsa"
diff --git a/openbsd79-arm64-macos.pkvars.hcl b/openbsd79-arm64.pkvars.hcl
index c8df031..48d7e05 100644
--- a/openbsd79-arm64-macos.pkvars.hcl
+++ b/openbsd79-arm64.pkvars.hcl
@@ -2,7 +2,6 @@ version = "7.9"
arch = "arm64"
memory = 4096
disk_size = 16
-admin_user = "eugene"
ssh_public_key = <<-EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC31SiCeUZSJN3CueH6/+7UQvxwxkT/QkaDK6ZGdnkdpCWxRVp+0CTO4WG3u0PVEVd9DvSd81CEqrFaKxtKyiSh+4Va0A/mqY27tX7NZzEQLM/zLQrdESmaHY6EyQM0wlCtBKfNzuQqCa9QEw4TwkyMLOJzyI+bRsfeSHNCfxqnqGIMKKFiaF0ygakvQz57nWuKLOgqWsWkzFTuJKGI0OhefFBcZ4VzoCLV8i1zbB2AebhsmbyMza9OUF3px44atSM3o33Jto3gy7LTWtxU83NZU+wLEqY6IvcWx9BbSQZxAwEwXxUFmnzcX+FTkTiOs/Q2nXiLl2ggsGJffAq9Z1SGMCNGxT+Syyta5UtfBVVQdn6xtUxpppHwrdGC+TR8C5F9U12gsZRzvKkz0SSt5M4WHG2gna5rDgTisDbrEAsrqpmUqY9iSBzgAyk5xOi6fdI+r67gpjRSs+PNvDle3gImfIkPnEQg4eWJ54iKjfH+yd8vBk25T/ahu3J9rGgxp18= eugene@laptop
EOF
diff --git a/scripts/setup.sh b/scripts/setup.sh
index e4dc169..460e569 100755
--- a/scripts/setup.sh
+++ b/scripts/setup.sh
@@ -4,8 +4,8 @@ set -e
: "${ADMIN_USER:?ADMIN_USER must be set}"
main() {
- # Ensure the time in the VM is in sync. If it is not, things like upgrading
- # the system packages via pkg_add -u fail.
+ # Ensure the time is in sync. If it is not, things like upgrading the system
+ # packages via pkg_add -u fail.
rdate -n pool.ntp.org
pkg_add -u