summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kreutz <mail@skreutz.com>2020-04-02 01:21:34 +0200
committerStefan Kreutz <mail@skreutz.com>2020-04-02 01:21:34 +0200
commit0e269af97d08a6d588e38d6b817fe4c7900b8e47 (patch)
tree47b5fb8ce60b808c62ce83370ec156e1df8339eb
parent083d8a01ee2633bba59bfc970fe9236dd4b05b84 (diff)
downloadautoinstall-openbsd-on-qemu-0e269af97d08a6d588e38d6b817fe4c7900b8e47.tar
Revise
-rw-r--r--.gitignore5
-rw-r--r--boot.conf3
-rw-r--r--disklabel.conf2
l---------http/disklabel.conf1
-rw-r--r--install.conf15
-rwxr-xr-xinstall.site5
-rwxr-xr-xrun175
l---------tftp/auto_install1
l---------tftp/bsd.rd1
l---------tftp/etc/boot.conf1
10 files changed, 128 insertions, 81 deletions
diff --git a/.gitignore b/.gitignore
index 40ffe06..e1620dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-http/pub/
-http/install.conf
-openbsd-66-base.pub
+mirror
openbsd-66-vm.qcow2
+tftp
diff --git a/boot.conf b/boot.conf
deleted file mode 100644
index b7daacc..0000000
--- a/boot.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-stty com0 115200
-set tty com0
-boot tftp:/bsd.rd
diff --git a/disklabel.conf b/disklabel.conf
deleted file mode 100644
index 74c93f7..0000000
--- a/disklabel.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-/ 12G
-swap 1G
diff --git a/http/disklabel.conf b/http/disklabel.conf
deleted file mode 120000
index 1ced26d..0000000
--- a/http/disklabel.conf
+++ /dev/null
@@ -1 +0,0 @@
-../disklabel.conf \ No newline at end of file
diff --git a/install.conf b/install.conf
deleted file mode 100644
index 01c0d93..0000000
--- a/install.conf
+++ /dev/null
@@ -1,15 +0,0 @@
-Change the default console to com0 = yes
-Which speed should com0 use = 115200
-System hostname = openbsd-vm
-Password for root = *************
-Allow root ssh login = no
-Setup a user = puffy
-Password for user = *************
-What timezone are you in = UTC
-Location of sets = http
-HTTP Server = 10.0.2.2
-Unable to connect using https. Use http instead = yes
-URL to autopartitioning template for disklabel = http://10.0.2.2/disklabel.conf
-Set name(s) = site66.tgz
-Checksum test for site66.tgz failed. Continue anyway = yes
-Unverified sets: site66.tgz. Continue without verification = yes
diff --git a/install.site b/install.site
deleted file mode 100755
index 512974f..0000000
--- a/install.site
+++ /dev/null
@@ -1,5 +0,0 @@
-#! /bin/ksh
-set -o errexit
-echo "https://cdn.openbsd.org/pub/OpenBSD" > /etc/installurl
-echo "permit nopass keepenv :wheel" > /etc/doas.conf
-#echo "syspatch && shutdown -r now" >> /etc/rc.firsttime
diff --git a/run b/run
index 8fe53a4..9cc5f39 100755
--- a/run
+++ b/run
@@ -1,76 +1,153 @@
#! /bin/sh
-# Auto-install OpenBSD/amd64 6.6 to a QEMU guest machine.
+# Auto-install OpenBSD/amd64 6.6 to a QEMU guest machine. A POSIX shell script
+# intended to run headless, ssh-controlled integration tests.
#
-# Inspired by:
+# Run the following command to serve the automatically created directory mirror
+# at http://127.0.0.1 (port 80):
#
-# - https://man.openbsd.org/autoinstall
+# sudo python3 -m http.server --directory mirror --bind 127.0.0.1 80
#
-# - https://eradman.com/posts/autoinstall-openbsd.html
+# Pass the following options to ssh or scp to connect to the guest machine:
#
-# - https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html
+# ssh \
+# -o "StrictHostKeyChecking no" \
+# -o "UserKnownHostsFile /dev/null" \
+# -o "Port 2222" \
+# puffy@127.0.0.1
#
-# Remove generated files with
+# Press C-a x to stop the guest machine. Press C-a h to show other options.
+#
+# The virtual network:
+#
+# network = 10.0.2.0/24
+# host = 10.0.2.2
+# nameserver = 10.0.2.3
+# guest = 10.0.2.15-31
+#
+# Port forwardings:
+#
+# host:2222 -> guest:22
+# host:8080 -> guest:80
+#
+# Run the following command to clean up any mess created by this script :)
#
# git clean -Xdf
#
# Copyright (c) 2020 Stefan Kreutz <mail@skreutz.com>
set -o errexit
+set -o nounset
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 )
+# Set parameters.
+DISK_SIZE="${DISK_SIZE-20G}"
+CPU_COUNT="${CPU_COUNT-1}"
+MEMORY_SIZE="${MEMORY_SIZE-4G}"
-# Add public ssh key to install.conf.
-cp install.conf http/install.conf
-grep -q -e "^Public ssh key for user =" install.conf || {
- ssh_pub_key="$( cat ~/.ssh/id_rsa.pub )"
- echo "Public ssh key for user = ${ssh_pub_key}" >> http/install.conf
+# Download and verify OpenBSD/amd64 6.6 installation images and file sets.
+[ -d mirror ] || {
+ mkdir -p mirror-tmp/pub/OpenBSD/6.6
+ [ -e mirror-tmp/pub/OpenBSD/6.6/openbsd-66-base.pub ] || \
+ curl --output mirror-tmp/pub/OpenBSD/6.6/openbsd-66-base.pub --silent \
+ https://ftp.openbsd.org/pub/OpenBSD/6.6/openbsd-66-base.pub
+ mkdir -p mirror-tmp/pub/OpenBSD/6.6/amd64
+ rsync --recursive --delete --quiet \
+ rsync://ftp.halifax.rwth-aachen.de/openbsd/6.6/amd64/ \
+ mirror-tmp/pub/OpenBSD/6.6/amd64/
+ ( cd mirror-tmp/pub/OpenBSD/6.6/amd64 && \
+ signify -C -q -p ../openbsd-66-base.pub -x SHA256.sig )
+ mv mirror-tmp mirror
}
-# TODO: Start HTTP server automatically in the background.
-# sudo python3 -m http.server --directory http --bind 127.0.0.1 80
+# Create default site-specific file set.
+mkdir -p mirror/pub/OpenBSD/6.6/amd64/site66
+[ -d mirror/pub/OpenBSD/6.6/amd64/site66/install.site ] || \
+ cat << EOF > mirror/pub/OpenBSD/6.6/amd64/site66/install.site
+#! /bin/ksh
+set -o errexit
+echo "https://cdn.openbsd.org/pub/OpenBSD" > /etc/installurl
+echo "permit nopass keepenv :wheel" > /etc/doas.conf
+#echo "syspatch && shutdown -r now" >> /etc/rc.firsttime
+EOF
+chmod +x mirror/pub/OpenBSD/6.6/amd64/site66/install.site
+
+# Package site-specific file set.
+( cd mirror/pub/OpenBSD/6.6/amd64 && \
+ rm -f site66.tgz && \
+ cd site66 && \
+ tar -czf ../site66.tgz . && \
+ cd .. && \
+ ls -l > index.txt )
+
+# Create default install.conf.
+ssh_pub_key="$( cat ~/.ssh/id_rsa.pub )"
+[ -e mirror/install.conf ] || cat << EOF > mirror/install.conf
+Change the default console to com0 = yes
+Which speed should com0 use = 115200
+System hostname = openbsd-vm
+Password for root = *************
+Allow root ssh login = no
+Setup a user = puffy
+Password for user = *************
+Public ssh key for user = ${ssh_pub_key}
+What timezone are you in = UTC
+Location of sets = http
+HTTP Server = 10.0.2.2
+Unable to connect using https. Use http instead = yes
+URL to autopartitioning template for disklabel = http://10.0.2.2/disklabel
+Set name(s) = site66.tgz
+Checksum test for site66.tgz failed. Continue anyway = yes
+Unverified sets: site66.tgz. Continue without verification = yes
+EOF
+
+# Create default disklabel template.
+[ -e mirror/disklabel ] || cat << EOF > mirror/disklabel
+/ 500M
+swap 1G
+/tmp 1G
+/var 1G
+/var/www 1G
+/usr 2G
+/usr/X11R6 500M
+/usr/local 4G
+/usr/src 1M
+/usr/obj 1M
+/home 4G
+EOF
+
+# Wait until the HTTP server is online.
+while [ ! "$( curl --silent --location --write-out '%{http_code}\n' --output /dev/null http://127.0.0.1/install.conf )" = 200 ] ;
+do
+ ( >&2 printf "Please serve the directory mirror at http://127.0.0.1 (port 80).\n" )
+ sleep 5
+done
+
+# Collect files to be served over TFTP.
+mkdir -p tftp
+[ -e tftp/auto_install ] || \
+ ln -s ../mirror/pub/OpenBSD/6.6/amd64/pxeboot tftp/auto_install
+[ -e tftp/bsd.rd ] || \
+ ln -s ../mirror/pub/OpenBSD/6.6/amd64/bsd.rd tftp/bsd.rd
+
+# Create default boot.conf.
+mkdir -p tftp/etc
+[ -e tftp/etc/boot.conf ] || cat << EOF > tftp/etc/boot.conf
+stty com0 115200
+set tty com0
+boot tftp:/bsd.rd
+EOF
# Create copy-on-write disk image.
-[ -e openbsd-66-vm.qcow2 ] || qemu-img create -f qcow2 openbsd-66-vm.qcow2 16G
+[ -e openbsd-66-vm.qcow2 ] || \
+ qemu-img create -f qcow2 openbsd-66-vm.qcow2 "${DISK_SIZE}"
# 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 \
+ -m "${MEMORY_SIZE}" \
+ -smp "cpus=${CPU_COUNT}" \
-device e1000,netdev=n1 \
- -netdev user,id=n1,hostname=openbsd-vm,tftp=tftp,bootfile=auto_install,hostfwd=tcp::2222-:22 \
+ -netdev user,id=n1,hostname=openbsd-vm,tftp=tftp,bootfile=auto_install,hostfwd=tcp::2222-:22,hostfwd=tcp::8080-:80 \
-drive file=openbsd-66-vm.qcow2,media=disk,if=virtio \
-nographic
diff --git a/tftp/auto_install b/tftp/auto_install
deleted file mode 120000
index 7224e61..0000000
--- a/tftp/auto_install
+++ /dev/null
@@ -1 +0,0 @@
-../http/pub/OpenBSD/6.6/amd64/pxeboot \ No newline at end of file
diff --git a/tftp/bsd.rd b/tftp/bsd.rd
deleted file mode 120000
index 7a35bd8..0000000
--- a/tftp/bsd.rd
+++ /dev/null
@@ -1 +0,0 @@
-../http/pub/OpenBSD/6.6/amd64/bsd.rd \ No newline at end of file
diff --git a/tftp/etc/boot.conf b/tftp/etc/boot.conf
deleted file mode 120000
index e679804..0000000
--- a/tftp/etc/boot.conf
+++ /dev/null
@@ -1 +0,0 @@
-../../boot.conf \ No newline at end of file
Generated by cgit. See skreutz.com for my tech blog and contact information.