# -*- mode: sh; fill-column: 72; comment-column: 62; -*- # OpenBSD 6.9 the last release which support tftp-server-name # all another ine requires next-server which is IP address and # leads to VERSION="${VERSION-6.9}" # Leaseweb is CDN based mirror which keep historical archive MIRROR="${MIRROR-https://mirror.leaseweb.com/pub/OpenBSD}" # Keep in mind that auto_upgrade won't work for COMMAND="${COMMAND:-pxeboot}" # Hardcode my host, but allow it to easy change INSTALL_SERVER="${INSTALL_SERVER:-install.catap.net}" # bypass 2222 to guest 22 by default SSH_PORT="${SSH_PORT:-2222}" BOOT_CMD="${BOOT_CMD:-tftp:/bsd.rd}" set -e if [ "$#" -eq 0 ] then echo "You should add disk, like -hda /dev/blabla" 1>&2 exit 1 fi # well, it can be adjusted for another arch one day thus, I # may not use host/ifconfig if HOSTNAME provided but check it # here makes code cleaner and I can't image the rescue system # without it for cmd in qemu-system-x86_64 wget host ifconfig do if ! command -v "${cmd}" >/dev/null then echo "command not found: ${cmd}" 1>&2 exit 1 fi done # here I may use rsync instead, but leaseweb's mirror has # limit of connection and can't be used without loop mkdir -p tftpboot for file in bsd.rd pxeboot do wget -q -O tftpboot/${file} ${MIRROR}/${VERSION}/amd64/${file} done for file in auto_install auto_upgrade do rm -f tftpboot/${file} && ln -s pxeboot tftpboot/${file} done mkdir -p tftpboot/etc cat > tftpboot/etc/boot.conf << EOF stty com0 115200 set tty com0 boot ${BOOT_CMD} EOF if [ -z "${HOSTNAME}" ]; then HOSTNAME=$(host $(ifconfig eth0 | grep 'inet ' | awk '{print $2}') | awk '{print $5}') fi qemu-system-x86_64 \ -m 1024 \ -smp 2 \ -device e1000,netdev=net0 \ -nographic \ -netdev user,id=net0,hostname=${HOSTNAME},tftp=tftpboot,bootfile=${COMMAND},tftp-server-name=${INSTALL_SERVER},hostfwd=tcp::${SSH_PORT}-:22 \ -boot order=c,once=n \ -serial mon:stdio \ "$@"