summaryrefslogtreecommitdiff
path: root/scripts/make-base.sh
blob: 970acac681380575edb09c715e4a1922a8676cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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}"