fix(iso): auto-detect and install kernel headers at build time

- Dockerfile: linux-headers-amd64 meta-package instead of pinned ABI;
  remove DEBIAN_KERNEL_ABI build-arg (no longer needed at image build time)
- build-in-container.sh: drop --build-arg DEBIAN_KERNEL_ABI
- build.sh: apt-get update + detect ABI from apt-cache at build time;
  auto-install linux-headers-<ABI> if kernel changed since image build

Image rebuild is now needed only when changing Go version or lb tools,
not on every Debian kernel point release.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-03-25 11:25:29 +03:00
parent 7ed5cb0306
commit 2f4ec2acda
3 changed files with 13 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
FROM debian:12 FROM debian:12
ARG GO_VERSION=1.24.0 ARG GO_VERSION=1.24.0
ARG DEBIAN_KERNEL_ABI=6.1.0-43
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
@@ -24,7 +23,7 @@ RUN apt-get update -qq && apt-get install -y \
gcc \ gcc \
make \ make \
perl \ perl \
"linux-headers-${DEBIAN_KERNEL_ABI}-amd64" \ linux-headers-amd64 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN arch="$(dpkg --print-architecture)" \ RUN arch="$(dpkg --print-architecture)" \

View File

@@ -59,7 +59,6 @@ IMAGE_REF="${IMAGE_TAG}:debian${DEBIAN_VERSION}"
if [ "$REBUILD_IMAGE" = "1" ] || ! "$CONTAINER_TOOL" image inspect "${IMAGE_REF}" >/dev/null 2>&1; then if [ "$REBUILD_IMAGE" = "1" ] || ! "$CONTAINER_TOOL" image inspect "${IMAGE_REF}" >/dev/null 2>&1; then
"$CONTAINER_TOOL" build \ "$CONTAINER_TOOL" build \
--build-arg GO_VERSION="${GO_VERSION}" \ --build-arg GO_VERSION="${GO_VERSION}" \
--build-arg DEBIAN_KERNEL_ABI="${DEBIAN_KERNEL_ABI}" \
-t "${IMAGE_REF}" \ -t "${IMAGE_REF}" \
"${BUILDER_DIR}" "${BUILDER_DIR}"
else else

View File

@@ -34,18 +34,27 @@ mkdir -p "${CACHE_ROOT}"
: "${GOMODCACHE:=${CACHE_ROOT}/go-mod}" : "${GOMODCACHE:=${CACHE_ROOT}/go-mod}"
export GOCACHE GOMODCACHE export GOCACHE GOMODCACHE
# Auto-detect kernel ABI from apt when not pinned explicitly. # Auto-detect kernel ABI: refresh apt index, then query current linux-image-amd64 dependency.
# If headers for the detected ABI are not yet installed (kernel updated since image build),
# install them on the fly so NVIDIA modules and ISO kernel always match.
if [ -z "${DEBIAN_KERNEL_ABI}" ] || [ "${DEBIAN_KERNEL_ABI}" = "auto" ]; then if [ -z "${DEBIAN_KERNEL_ABI}" ] || [ "${DEBIAN_KERNEL_ABI}" = "auto" ]; then
echo "=== refreshing apt index to detect current kernel ABI ==="
apt-get update -qq
DEBIAN_KERNEL_ABI=$(apt-cache depends linux-image-amd64 2>/dev/null \ DEBIAN_KERNEL_ABI=$(apt-cache depends linux-image-amd64 2>/dev/null \
| awk '/Depends:.*linux-image-[0-9]/{print $2}' \ | awk '/Depends:.*linux-image-[0-9]/{print $2}' \
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+-[0-9]+' \ | grep -oE '[0-9]+\.[0-9]+\.[0-9]+-[0-9]+' \
| head -1) | head -1)
if [ -z "${DEBIAN_KERNEL_ABI}" ]; then if [ -z "${DEBIAN_KERNEL_ABI}" ]; then
echo "ERROR: could not auto-detect kernel ABI from apt-cache" >&2 echo "ERROR: could not auto-detect kernel ABI from apt-cache" >&2
echo " Run: apt-cache depends linux-image-amd64" >&2
exit 1 exit 1
fi fi
echo "=== kernel ABI auto-detected: ${DEBIAN_KERNEL_ABI} ===" echo "=== kernel ABI: ${DEBIAN_KERNEL_ABI} ==="
fi
KVER="${DEBIAN_KERNEL_ABI}-amd64"
if [ ! -d "/usr/src/linux-headers-${KVER}" ]; then
echo "=== installing linux-headers-${KVER} (kernel updated since image build) ==="
apt-get install -y "linux-headers-${KVER}"
fi fi
echo "=== bee ISO build ===" echo "=== bee ISO build ==="