From c39e7c37ed46e0090dac52253d2bb3e4b09cc9c9 Mon Sep 17 00:00:00 2001 From: Andrea Rogers Date: Thu, 9 Oct 2025 14:23:02 -0500 Subject: [PATCH] initial VERY rough commit --- GNUmakefile | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 29 ++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 GNUmakefile create mode 100644 README.md diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..7917825 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,59 @@ +ARCH ?= $(shell uname -m) +QEMU ?= qemu-system-$(ARCH) +UBUNTU_ROOT ?= roots/ubuntu_wiredemo-admin.targetdisk.local +SSH_PORT ?= 2222 + +ifeq ($(ARCH),x86_64) + OVMF_ARCH := x64 +else ifeq ($(ARCH),x86) + OVMF_ARCH := ia32 +else ifneq (,$(findstring arm,$(ARCH))) + OVMF_ARCH := arm +else + OVMF_ARCH := $(ARCH) +endif + +QEMU_OVMF ?= /usr/share/ovmf/$(OVMF_ARCH)/OVMF.*fd + +QEMUOPTS ?= -cpu max -enable-kvm -smp $(shell nproc) \ + -nodefaults -no-user-config -nographic \ + -chardev stdio,id=virtcons0 \ + -device virtio-serial-pci \ + -device virtconsole,chardev=virtcons0 \ + -m 62G \ + -net user,hostfwd=tcp::$(SSH_PORT)-:22 \ + -net nic \ + -device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs0 \ + -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +# -bios $(QEMU_OVMF) \ +# -bios /usr/share/qemu/qboot.rom +# -machine microvm,accel=kvm,rtc=on \ + +UBUNTU_ISO ?= iso/ubuntu/ubuntu-24.04.2-live-server-amd64.iso +UBUNTU_ISO_ARGS ?= -drive file=$(UBUNTU_ISO),media=cdrom,id=virtiso1 \ +# -device virtio-blk-pci,drive=virtiso1 \ +# -kernel mnt/casper/vmlinuz \ +# -append "earlyprintk=ttyS0" + +UBUNTU_FAT_ARGS ?= -drive file=fat:rw:$(UBUNTU_ROOT)/boot,id=virtiso1 \ + +$(UBUNTU_ROOT): + mkdir -p $@ + +root1: $(UBUNTU_ROOT) + +roots/ubuntu_wiredemo-admin.wiredemo.local: + mkdir -p $@ + +run1-installer: $(UBUNTU_ROOT) + $(QEMU) $(QEMUOPTS) $(UBUNTU_ISO_ARGS) \ + -fsdev local,security_model=mapped,id=fsdev-fs0,multidevs=remap,path=$< + +run1: $(UBUNTU_ROOT) + $(QEMU) $(QEMUOPTS) \ + -kernel $(UBUNTU_ROOT)/boot/$(shell cat $(UBUNTU_ROOT)/boot/vmlinuz) \ + -append "earlyprintk=ttyS0 root=fs0 rw rootfstype=9p rootflags=trans=virtio,version=9p2000.L,msize=5000000,cache=mmap,posixacl console=ttyS0" \ + -initrd $(UBUNTU_ROOT)/boot/$(shell cat $(UBUNTU_ROOT)/boot/initrd.img) \ + -fsdev local,security_model=mapped,id=fsdev-fs0,multidevs=remap,path=$< + +.PHONY: root1 run1 run1-installer diff --git a/README.md b/README.md new file mode 100644 index 0000000..7eecd20 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# 9p Ubuntu Server VM +There are still some rough edges here, but this is a GNU makefile that allows +you to run a headless Ubuntu VM on a 9p filesystem. + +When I get my website back up, I'll link the blog post this inspired that +explains what and why this is. + +## Requirements +- A QEMU build with the 9p stuff (many distros include the stuff in their QEMU + packages) +- GNU Make +- OVMF EFI firmware (this requirement may go away later on) + +## Using +Run the installer: +``` +SSH_PORT=2221 UBUNTU_ISO=path/to/ubuntu_whatever.iso make run1-installer +``` + +More info on the installer coming soon... + +Enjoy your VM: +``` +make run1 +``` + +## TODO +- pull down the Ubuntu ISO automagically so somewhere pointed to +by `UBUNTU_ISO` automagically