diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2019-02-21 02:31:43 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2019-02-21 02:41:38 +0100 |
commit | 2da9d8c440cfb2097a05f6eb9edcc98bba6fca7d (patch) | |
tree | 8092910096d63ea37bcd74db4f26b204cac3e4e2 /kpov_judge/scripts/make-base.sh | |
parent | 7dd74ded5bfcd36b6a498c0dff71235c4bc764ca (diff) |
Add scripts to generate virtual images with Debian
The script make-base downloads and installs Debian Buster in a backing
image which is then used by make-arbiter and make-student to create
derived images with specific configurations.
Diffstat (limited to 'kpov_judge/scripts/make-base.sh')
-rwxr-xr-x | kpov_judge/scripts/make-base.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/kpov_judge/scripts/make-base.sh b/kpov_judge/scripts/make-base.sh new file mode 100755 index 0000000..970acac --- /dev/null +++ b/kpov_judge/scripts/make-base.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# Create the base disk image: a minimal Debian install with a user +# account student / vaje. Root password is kaboom. Serial console is +# enabled for grub and boot messages are displayed. Some useful +# additional packages are installed, and the image is sparsified +# (requires at least 30 GB free space). + +set -e + +if [ $# -lt 1 ]; then + echo "usage: ${0} image-name" + exit 1 +fi + +name="${1}" +format=qcow2 + +outfile="${name}.${format}" +fatfile="${name}-fat.${format}" + +tmpdir="$(mktemp -d kpov-tmp.XXXXXX)" +trap 'rm -rf "${tmpdir}"' EXIT + +for f in linux initrd.gz; do + wget "https://d-i.debian.org/daily-images/i386/daily/netboot/debian-installer/i386/${f}" -O "${tmpdir}/${f}" +done + +qemu-img create -f "${format}" -o size=30G "${fatfile}" + +qemu-system-i386 \ + -enable-kvm \ + -nographic \ + -m 1G -smp 2 \ + -kernel "${tmpdir}/linux" -initrd "${tmpdir}/initrd.gz" \ + -append "console=ttyS0,115200n8 serial auto=true url=http://10.0.2.10:8080/preseed.cfg hostname=${name} domain=" \ + -net user,guestfwd=:10.0.2.10:8080-cmd:"/bin/busybox httpd -i" -net nic \ + -hda "${fatfile}" + +virt-customize -a "${fatfile}" \ + --update \ + --install virtualbox-guest-utils,virtualbox-guest-modules \ + --install nftables \ + --install git,nano,net-tools,rsync,sudo,tmux,vim \ + --run-command 'apt clean' \ + --edit /etc/default/grub:'s/^GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0"/' \ + --edit /etc/default/grub:'s/^GRUB_TERMINAL=.*$/GRUB_TERMINAL=\"console serial\"/' \ + --run-command update-grub + +virt-sparsify "${fatfile}" "${outfile}" +rm -f "${fatfile}" |