aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd-image/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-image/Makefile')
-rw-r--r--openbsd-image/Makefile73
1 files changed, 73 insertions, 0 deletions
diff --git a/openbsd-image/Makefile b/openbsd-image/Makefile
new file mode 100644
index 0000000..0c3ae00
--- /dev/null
+++ b/openbsd-image/Makefile
@@ -0,0 +1,73 @@
+# TODO: Replace with run-openbsd-image.sh and add ARM support to build-openbsd-image.sh
+SHELL := /bin/sh
+
+ARCH ?= arm64
+BUILD_DIR := build
+EDK2_DIR := /opt/homebrew/share/qemu
+SSH_PORT := 2222
+SSH_USER := admin
+SSH_KEY := ~/.ssh/id_rsa
+CPU := 8
+MEMORY := 32768M
+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
+
+all: build
+
+init:
+ packer init .
+
+build: init clean
+ifeq ($(ARCH),arm64)
+ cp $(EDK2_DIR)/$(EDK2_VARS) ./$(EDK2_VARS)
+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)
+ qemu-system-aarch64 \
+ -machine type=virt,accel=hvf \
+ -cpu host \
+ -m $(MEMORY) \
+ -smp $(CPU) \
+ -nographic \
+ -device qemu-xhci,id=xhci \
+ -device usb-kbd,bus=xhci.0 \
+ -device virtio-gpu-pci \
+ -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 \
+ -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 -i $(SSH_KEY) -p $(SSH_PORT) $(SSH_USER)@127.0.0.1
+
+clean:
+ rm -rf $(BUILD_DIR)
+