mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-21 01:01:18 -08:00
The natlab gokrazy image runs a recent upstream kernel (7.2.8 today) that gokrazy rebuilds and tailscale.com bumps regularly, which makes it a better primary test target than a distro kernel: it keeps us honest against new kernel APIs, and gokrazy has no userspace tools, as in the end state where tailscaled drives the kernel entirely. gokrazy kernels are kernel.org releases plus the patches in _build/series, built with an embedded config and without MODVERSIONS or module signing. gokrazy-kdir.sh downloads the release, applies the patches, installs the config pulled out of vmlinuz with the kernel's extract-ikconfig (vendored), and runs modules_prepare, caching the result by release and config hash. It takes about 20 seconds the first time. The only config differences after olddefconfig with the host's gcc 13 (gokrazy uses Debian 12's gcc 12) are toolchain capability bits. Factor the generic part of build-for-ubuntu.sh into build.sh, which now copies only sources (not objects from an in-place build in src/), and sets KBUILD_MODPOST_WARN=1 for trees without a Module.symvers. Add build-for-gokrazy.sh. Updates #426 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: Id28d9c013bdfaa7cec28aeff846f7f6087e25518
68 lines
2.1 KiB
Bash
Executable File
68 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# gokrazy-kdir.sh prepares a kernel build directory matching a gokrazy
|
|
# kernel package (such as the github.com/gokrazy/kernel.amd64 module that
|
|
# tailscale.com's natlab gokrazy image uses) and prints its path to stdout.
|
|
#
|
|
# gokrazy kernels are upstream kernel.org releases plus the patches listed in
|
|
# _build/series, and embed their .config (CONFIG_IKCONFIG). So we download
|
|
# that release, apply the patches, install the embedded config and run
|
|
# "make modules_prepare". That's enough to build tswg.ko for that kernel,
|
|
# since gokrazy kernels don't use MODVERSIONS or module signing.
|
|
#
|
|
# Results are cached in $TSLINUX_CACHE (default ~/.cache/tslinux), keyed by
|
|
# the kernel release and a hash of the config.
|
|
#
|
|
# usage: gokrazy-kdir.sh GOKRAZY_KERNEL_PACKAGE_DIR
|
|
|
|
set -eu
|
|
|
|
if [ $# -ne 1 ]; then
|
|
echo "usage: $0 GOKRAZY_KERNEL_PACKAGE_DIR" >&2
|
|
exit 2
|
|
fi
|
|
pkg=$1
|
|
cache=${TSLINUX_CACHE:-$HOME/.cache/tslinux}
|
|
|
|
url=$(cat "$pkg/_build/upstream-url.txt")
|
|
tarball=${url##*/} # linux-7.2.8.tar.xz
|
|
srcname=${tarball%.tar.*} # linux-7.2.8
|
|
|
|
config=$(mktemp)
|
|
trap 'rm -f "$config"' EXIT
|
|
"$(dirname "$0")/extract-ikconfig" "$pkg/vmlinuz" > "$config"
|
|
hash=$(sha256sum "$config" | cut -c1-12)
|
|
|
|
kdir=$cache/gokrazy/$srcname-$hash
|
|
if [ -f "$kdir/.tswg-prepared" ]; then
|
|
echo "$kdir"
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$cache/tarballs"
|
|
if [ ! -f "$cache/tarballs/$tarball" ]; then
|
|
echo "downloading $url" >&2
|
|
curl -sSfL -o "$cache/tarballs/$tarball.tmp" "$url"
|
|
mv "$cache/tarballs/$tarball.tmp" "$cache/tarballs/$tarball"
|
|
fi
|
|
|
|
# Build in place (kbuild state records absolute paths, so the tree can't
|
|
# be moved afterwards) and mark it complete at the end.
|
|
rm -rf "$kdir"
|
|
mkdir -p "$kdir"
|
|
echo "unpacking $tarball" >&2
|
|
tar -xf "$cache/tarballs/$tarball" -C "$kdir" --strip-components=1
|
|
if [ -f "$pkg/_build/series" ]; then
|
|
while read -r patch; do
|
|
[ -n "$patch" ] || continue
|
|
patch -s -d "$kdir" -p1 < "$pkg/_build/$patch"
|
|
done < "$pkg/_build/series"
|
|
fi
|
|
cp "$config" "$kdir/.config"
|
|
echo "preparing $srcname for modules" >&2
|
|
make -s -C "$kdir" olddefconfig >&2
|
|
make -s -C "$kdir" -j"$(nproc)" modules_prepare >&2
|
|
touch "$kdir/.tswg-prepared"
|
|
echo "$kdir"
|