Repository navigation
Expand file tree
/
Copy pathboot.sh
More file actions
executable file
·57 lines (51 loc) · 2.02 KB
/
Copy pathboot.sh
File metadata and controls
executable file
·57 lines (51 loc) · 2.02 KB
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
52
53
54
55
56
57
#!/usr/bin/env bash
# Boots a built kernel image in QEMU with a minimal initramfs and checks that the kernel
# comes up and can load a module. Used as a sanity check before an image is published.
#
# Usage: ./boot.sh <tag>
set -euo pipefail
if [ $# -ne 1 ]; then
echo "usage: $0 <tag>" >&2
exit 2
fi
TAG=$1
REPO=${REPO:-ghcr.io/coroot/ci-kernels}
HELPER_IMAGE=${HELPER_IMAGE:-alpine:3.20}
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
c=$(docker create --platform linux/amd64 "$REPO:$TAG" /none)
docker cp "$c:/." "$work/kernel"
docker rm "$c" >/dev/null
release=$(cat "$work/kernel/boot/release")
cat >"$work/init" <<'INIT'
#!/bin/busybox sh
/bin/busybox mount -t proc proc /proc
/bin/busybox mount -t devtmpfs dev /dev
exec >/dev/console 2>&1
echo "BOOT kernel $(/bin/busybox uname -r)"
if /bin/busybox modprobe nf_conntrack_netlink && /bin/busybox grep -q '^nf_conntrack_netlink ' /proc/modules; then
echo "BOOT OK"
else
echo "BOOT FAIL: cannot load nf_conntrack_netlink"
fi
/bin/busybox sleep 1
echo o > /proc/sysrq-trigger
/bin/busybox sleep 60
INIT
kvm=""
cpu="-cpu max"
if [ -e /dev/kvm ]; then
kvm="--device /dev/kvm"
cpu="-enable-kvm -cpu host"
fi
# shellcheck disable=SC2086
docker run --rm $kvm -v "$work:/work" "$HELPER_IMAGE" sh -c "
apk add --no-cache -q qemu-system-x86_64 busybox-static cpio >/dev/null &&
mkdir -p /rootfs/bin /rootfs/proc /rootfs/dev /rootfs/lib &&
cp /bin/busybox.static /rootfs/bin/busybox && install -m 755 /work/init /rootfs/init &&
cp -a /work/kernel/lib/modules /rootfs/lib/ &&
(cd /rootfs && find . | cpio -o -H newc 2>/dev/null | gzip -1 > /work/initramfs.gz) &&
timeout 300 qemu-system-x86_64 $cpu -m 2G -nographic -no-reboot -kernel /work/kernel/boot/vmlinuz \
-initrd /work/initramfs.gz -append 'console=ttyS0 panic=-1 quiet'" </dev/null >"$work/console.log" 2>&1 || true
tr -d '\r' <"$work/console.log" | grep -a "BOOT" || tr -d '\r' <"$work/console.log" | tail -n 30
grep -a -q "BOOT kernel $release" "$work/console.log" && grep -a -q "BOOT OK" "$work/console.log"