aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile41
1 files changed, 29 insertions, 12 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)