#! /bin/sh # Auto-install OpenBSD/amd64 6.6 to a QEMU guest machine. # # Inspired by: # # - https://man.openbsd.org/autoinstall # # - https://eradman.com/posts/autoinstall-openbsd.html # # - https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html # # Remove generated files with # # git clean -Xdf # # Copyright (c) 2020 Stefan Kreutz set -o errexit set -o xtrace # Download and verify OpenBSD/amd64 6.6 distribution. # # Note: rsync deletes superfluous files, e.g., the site66.tgz. [ -e openbsd-66-base.pub ] || \ curl --output openbsd-66-base.pub --silent \ https://ftp.openbsd.org/pub/OpenBSD/6.6/openbsd-66-base.pub mkdir -p http/pub/OpenBSD/6.6/amd64 rsync --recursive --delete --quiet \ rsync://ftp.halifax.rwth-aachen.de/openbsd/6.6/amd64/ \ http/pub/OpenBSD/6.6/amd64/ ( cd http/pub/OpenBSD/6.6/amd64 && \ signify -C -q -p ../../../../../openbsd-66-base.pub -x SHA256.sig ) # Add a site-specific file set to patch the system at the end of the # installation -- and optionally on the first boot. # # Note: Afterwards, signify will fail to verify the integrity of the # distribution. tar -czf http/pub/OpenBSD/6.6/amd64/site66.tgz install.site ( cd http/pub/OpenBSD/6.6/amd64 && ls -l > index.txt ) # Add public ssh key to install.conf. grep -q -e "^Public ssh key for user =" http/install.conf || { ssh_pub_key="$( cat ~/.ssh/id_rsa.pub )" echo "Public ssh key for user = ${ssh_pub_key}" >> http/install.conf } # TODO: Start HTTP server automatically in the background. # sudo python3 -m http.server --directory http --bind 127.0.0.1 80 # Create copy-on-write disk image. [ -e openbsd-66-vm.qcow2 ] || qemu-img create -f qcow2 openbsd-66-vm.qcow2 16G # Auto-install guest machine. # # Connect with # # ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" -o "Port 2222" root@127.0.0.1 # # Stop guest machine with C-a x # # Show help with C-a h # # network = 10.0.2.0/24 # host = 10.0.2.2 # nameserver = 10.0.2.3 # guest = 10.0.2.15-31 qemu-system-x86_64 \ -enable-kvm \ -m 4G \ -device e1000,netdev=n1 \ -netdev user,id=n1,hostname=openbsd-vm,tftp=tftp,bootfile=auto_install,hostfwd=tcp::2222-:22 \ -drive file=openbsd-66-vm.qcow2,media=disk,if=virtio \ -nographic