aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd-image
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-09-22 17:00:53 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-11 18:33:35 -0700
commitc9cfdbf86f2bf620c986abb2f67dcaabf5b01047 (patch)
tree23be01d9eb5cee38e1919e83d633ceff977f8f78 /openbsd-image
parentRemove need for explicit memory var override (diff)
downloadsite-server-images-c9cfdbf86f2bf620c986abb2f67dcaabf5b01047.zip
Add support for hcloud openbsd image snapshot
Diffstat (limited to '')
-rw-r--r--openbsd-image/Makefile (renamed from Makefile)5
-rw-r--r--openbsd-image/configs/doas.conf (renamed from configs/doas.conf)0
-rw-r--r--openbsd-image/locals.pkr.hcl4
-rw-r--r--openbsd-image/main.pkr.hcl23
-rw-r--r--openbsd-image/openbsd-amd64.pkr.hcl42
-rw-r--r--openbsd-image/openbsd-arm64.pkr.hcl51
-rwxr-xr-xopenbsd-image/scripts/harden-root.sh (renamed from scripts/harden-root.sh)0
-rwxr-xr-xopenbsd-image/scripts/setup.sh (renamed from scripts/setup.sh)0
-rw-r--r--openbsd-image/templates/install.conf.pkrtpl.hcl (renamed from templates/install.conf.pkrtpl.hcl)0
-rw-r--r--openbsd-image/variables.pkr.hcl55
10 files changed, 178 insertions, 2 deletions
diff --git a/Makefile b/openbsd-image/Makefile
index c1343f9..0c3ae00 100644
--- a/Makefile
+++ b/openbsd-image/Makefile
@@ -1,3 +1,4 @@
+# TODO: Replace with run-openbsd-image.sh and add ARM support to build-openbsd-image.sh
SHELL := /bin/sh
ARCH ?= arm64
@@ -6,8 +7,8 @@ EDK2_DIR := /opt/homebrew/share/qemu
SSH_PORT := 2222
SSH_USER := admin
SSH_KEY := ~/.ssh/id_rsa
-CPU := 1
-MEMORY := 4096M
+CPU := 8
+MEMORY := 32768M
PACKER_LOG := 1
VERSION := 7.9
diff --git a/configs/doas.conf b/openbsd-image/configs/doas.conf
index 96cf24d..96cf24d 100644
--- a/configs/doas.conf
+++ b/openbsd-image/configs/doas.conf
diff --git a/openbsd-image/locals.pkr.hcl b/openbsd-image/locals.pkr.hcl
new file mode 100644
index 0000000..f88100f
--- /dev/null
+++ b/openbsd-image/locals.pkr.hcl
@@ -0,0 +1,4 @@
+locals {
+ version_short = replace(var.version, ".", "")
+ root_password = "temp"
+}
diff --git a/openbsd-image/main.pkr.hcl b/openbsd-image/main.pkr.hcl
new file mode 100644
index 0000000..43d01dd
--- /dev/null
+++ b/openbsd-image/main.pkr.hcl
@@ -0,0 +1,23 @@
+packer {
+ required_plugins {
+ qemu = { source = "github.com/hashicorp/qemu", version = ">= 1.1.0" }
+ }
+}
+
+build {
+ sources = ["source.qemu.openbsd-amd64", "source.qemu.openbsd-arm64"]
+
+ provisioner "file" {
+ source = "configs/doas.conf"
+ destination = "/etc/doas.conf"
+ }
+
+ provisioner "shell" {
+ script = "scripts/setup.sh"
+ environment_vars = ["ADMIN_USER=${var.admin_user}"]
+ }
+
+ provisioner "shell" {
+ script = "scripts/harden-root.sh"
+ }
+}
diff --git a/openbsd-image/openbsd-amd64.pkr.hcl b/openbsd-image/openbsd-amd64.pkr.hcl
new file mode 100644
index 0000000..5d2c9f7
--- /dev/null
+++ b/openbsd-image/openbsd-amd64.pkr.hcl
@@ -0,0 +1,42 @@
+source "qemu" "openbsd-amd64" {
+ vm_name = "openbsd-${var.version}-amd64.raw"
+ 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 = "raw"
+ 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"]]
+}
diff --git a/openbsd-image/openbsd-arm64.pkr.hcl b/openbsd-image/openbsd-arm64.pkr.hcl
new file mode 100644
index 0000000..dbe5833
--- /dev/null
+++ b/openbsd-image/openbsd-arm64.pkr.hcl
@@ -0,0 +1,51 @@
+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"
+ output_directory = "build"
+ qemu_binary = "qemu-system-aarch64"
+ machine_type = "virt"
+ cpu_model = "host"
+ accelerator = "hvf"
+ 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 = "10m"
+
+ 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"
+ use_default_display = true
+ headless = false
+ qemuargs = [
+ ["-device", "qemu-xhci,id=xhci"],
+ ["-device", "usb-kbd,bus=xhci.0"],
+ ["-device", "virtio-gpu-pci"],
+ ["-display", "cocoa"],
+ ]
+ efi_firmware_code = "/opt/homebrew/share/qemu/edk2-aarch64-code.fd"
+ efi_firmware_vars = "./edk2-arm-vars.fd"
+}
+
diff --git a/scripts/harden-root.sh b/openbsd-image/scripts/harden-root.sh
index c8e267a..c8e267a 100755
--- a/scripts/harden-root.sh
+++ b/openbsd-image/scripts/harden-root.sh
diff --git a/scripts/setup.sh b/openbsd-image/scripts/setup.sh
index 320d93d..320d93d 100755
--- a/scripts/setup.sh
+++ b/openbsd-image/scripts/setup.sh
diff --git a/templates/install.conf.pkrtpl.hcl b/openbsd-image/templates/install.conf.pkrtpl.hcl
index 9df18ce..9df18ce 100644
--- a/templates/install.conf.pkrtpl.hcl
+++ b/openbsd-image/templates/install.conf.pkrtpl.hcl
diff --git a/openbsd-image/variables.pkr.hcl b/openbsd-image/variables.pkr.hcl
new file mode 100644
index 0000000..4bc0860
--- /dev/null
+++ b/openbsd-image/variables.pkr.hcl
@@ -0,0 +1,55 @@
+variable "version" {
+ type = string
+ description = "Version of OpenBSD to build"
+ validation {
+ condition = can(regex("^\\d\\.\\d$", var.version))
+ error_message = "The version must be a single-digit followed by a period followed by another single digit."
+ }
+}
+
+variable "arch" {
+ type = string
+ validation {
+ condition = contains(["amd64", "arm64"], var.arch)
+ error_message = "The arch must be one of: amd64, arm64."
+ }
+}
+
+variable "admin_user" {
+ type = string
+ description = "Username of the admin user on the VM"
+ default = "admin"
+}
+
+variable "ssh_public_key" {
+ type = string
+ description = "Public SSH key to associate with the admin user for login"
+}
+
+variable "mirror" {
+ type = string
+ description = "URL basename for where to download the OpenBSD ISO."
+ default = "https://cdn.openbsd.org"
+ validation {
+ condition = can(regex("^(https?)://", var.mirror)) && !endswith(var.mirror, "/")
+ error_message = "URL must start with http(s):// and must not have a trailing slash."
+ }
+}
+
+variable "hostname" {
+ type = string
+ description = "Hostname for the VM"
+ default = "openbsd-vm"
+}
+
+variable "memory" {
+ type = number
+ description = "Memory to allocate to the VM in MB while building the ISO"
+ default = 4096
+}
+
+variable "disk_size" {
+ type = number
+ description = "Size of the disk in GB while building the ISO"
+ default = 16
+}