Skip to content

Commit 54b550d

Browse files
committed
Successfully build x86 and arm64 kernel headers for new linux versions
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 8cbaedc commit 54b550d

4 files changed

Lines changed: 55 additions & 68 deletions

File tree

bazel/linux_headers.bzl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ def linux_headers():
2828
http_file(
2929
name = "linux_headers_merged_x86_64_tar_gz",
3030
urls = [
31-
"https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl7/linux-headers-merged-x86_64-pl7.tar.gz",
32-
"https://storage.googleapis.com/pixie-dev-public/linux-headers/pl7/linux-headers-merged-x86_64-pl7.tar.gz",
31+
"https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl8/linux-headers-merged-x86_64-pl8.tar.gz",
3332
],
34-
sha256 = "e4635db60d7f4139a8fea1b0490a0d0159e1edb9f3272ba2bcf40f8ea933bf93",
33+
sha256 = "07d0393aca727faadd41146585f92e3d9df239d91e2fa985ec55e50dc8526594",
3534
downloaded_file_path = "linux-headers-merged-x86_64.tar.gz",
3635
)
3736
http_file(
3837
name = "linux_headers_merged_arm64_tar_gz",
3938
urls = [
40-
"https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl7/linux-headers-merged-arm64-pl7.tar.gz",
41-
"https://storage.googleapis.com/pixie-dev-public/linux-headers/pl7/linux-headers-merged-arm64-pl7.tar.gz",
39+
"https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl8/linux-headers-merged-arm64-pl8.tar.gz",
4240
],
43-
sha256 = "c2a99ad6462dd1211c4e2f54f7279b7cf526e73918148350ccba988b95ca6115",
41+
sha256 = "75a05de508a7e83204e023ecdbdc2322b42fc812037a253de29c178871db7012",
4442
downloaded_file_path = "linux-headers-merged-arm64.tar.gz",
4543
)
4644

tools/docker/Makefile

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,25 @@ SYSROOT_CREATOR_IMAGE_TAG := sysroot-creator-$(SYSROOT_REV)
7272
## Linux image parameters
7373
LINUX_HEADER_BUILD_DIR := $(BUILD_DIR)/linux_headers
7474
LINUX_HEADER_ASSETS_BUILD_DIR := $(LINUX_HEADER_BUILD_DIR)/assets
75+
# Kernel versions selected to cover major enterprise distros and recent mainline.
76+
# Popular eBPF projects like cilium have moved to 5.10+ as their minimum
77+
# supported kernel version, with an exception for RHEL.
78+
# 4.18.20 - RHEL 8.10
79+
# 5.10.252 - Debian 11 / Amazon Linux 2
80+
# 5.14.21 - RHEL 9
81+
# 6.1.167 - Debian 12 / Amazon Linux 2023
82+
# 6.6.132 - Ubuntu 24.04 LTS
83+
# 6.12.80 - latest LTS
84+
# 6.18.21 - recent mainline
85+
# 6.19.10 - latest mainline
7586
LINUX_KERNEL_VERSIONS := 4.18.20 \
7687
5.10.252 \
77-
5.14.21 \
78-
6.1.167 \
79-
6.6.132 \
80-
6.12.80 \
81-
6.18.21 \
82-
6.19.10
88+
5.14.21 \
89+
6.1.167 \
90+
6.6.132 \
91+
6.12.80 \
92+
6.18.21 \
93+
6.19.10
8394

8495

8596
LINUX_HEADER_TEMPLATE := linux-headers-%.tar.gz
@@ -91,7 +102,6 @@ LINUX_HEADER_ARM64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, \
91102

92103
LINUX_HEADERS_X86_64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-x86_64-$(LINUX_HEADERS_REV).tar.gz
93104
LINUX_HEADERS_ARM64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-arm64-$(LINUX_HEADERS_REV).tar.gz
94-
LINUX_HEADERS_GS_PATH := gs://pixie-dev-public/linux-headers/$(LINUX_HEADERS_REV)
95105

96106
## NATS image parameters.
97107
NATS_IMAGE_VERSION := 2.9.25
@@ -114,12 +124,13 @@ elasticsearch_image_tag := "gcr.io/pixie-oss/pixie-dev-public/elasticsearch:$(EL
114124

115125
## Linux kernel for qemu/BPF tests.
116126
KERNEL_BUILD_DIR := $(BUILD_DIR)/kernel_build
117-
KERNEL_BUILD_VERSIONS := 5.10.252 \
118-
5.14.21 \
119-
6.1.167 \
120-
6.6.132 \
121-
6.12.80 \
122-
6.18.21
127+
KERNEL_BUILD_VERSIONS := 4.18.20 \
128+
5.10.252 \
129+
5.14.21 \
130+
6.1.167 \
131+
6.6.132 \
132+
6.12.80 \
133+
6.18.21
123134

124135
KERNEL_BUILD_TEMPLATE := linux-build-%.tar.gz
125136
KERNEL_BUILD_TARGETS = $(addprefix $(KERNEL_BUILD_DIR)/, $(patsubst %,$(KERNEL_BUILD_TEMPLATE), $(KERNEL_BUILD_VERSIONS)))
@@ -228,7 +239,6 @@ $(LINUX_HEADERS_ARM64_MERGED_FILE): $(LINUX_HEADER_ARM64_TARGETS)
228239

229240
.PHONY: upload_linux_headers
230241
upload_linux_headers: $(LINUX_HEADERS_X86_64_MERGED_FILE) $(LINUX_HEADERS_ARM64_MERGED_FILE) ## Target to build and upload linux headers image
231-
# gsutil cp $^ $(LINUX_HEADERS_GS_PATH)
232242
$(GH_RELEASE_UPLOAD) linux-headers $(LINUX_HEADERS_REV) $^
233243
sha256sum $^
234244

tools/docker/linux_headers_image/Dockerfile

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,16 @@ RUN apt-get update
2727
RUN apt-get upgrade -y -q
2828
RUN apt-get install -y -q build-essential \
2929
bc \
30-
libdw-dev \
3130
libelf-dev \
3231
libssl-dev \
3332
flex \
3433
bison \
35-
kmod \
36-
cpio \
3734
rsync \
3835
wget \
3936
binutils-aarch64-linux-gnu \
4037
gcc-aarch64-linux-gnu \
41-
dwarves \
42-
debhelper \
4338
python3
4439

45-
# opensslconf.h lives at the multiarch path (e.g. /usr/include/x86_64-linux-gnu/openssl/).
46-
# During cross-compilation, dpkg-buildpackage alters include paths so host tools
47-
# (like scripts/sign-file) can no longer find it. Symlink it to the standard path.
48-
RUN if [ -f /usr/include/x86_64-linux-gnu/openssl/opensslconf.h ] && \
49-
[ ! -f /usr/include/openssl/opensslconf.h ]; then \
50-
ln -s /usr/include/x86_64-linux-gnu/openssl/opensslconf.h /usr/include/openssl/opensslconf.h; \
51-
fi
52-
5340
WORKDIR /configs
5441
ADD x86_64_config /configs/x86_64
5542
ADD arm64_config /configs/arm64

tools/docker/linux_headers_image/build_linux_headers.sh

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,56 +49,48 @@ mkdir -p "${WORKSPACE}"/src
4949
pushd "${WORKSPACE}"/src || exit
5050

5151
KERN_MAJ=$(echo "${KERN_VERSION}" | cut -d'.' -f1);
52-
KERN_MIN=$(echo "${KERN_VERSION}" | cut -d'.' -f2);
5352
wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v"${KERN_MAJ}".x/linux-"${KERN_VERSION}".tar.gz
5453

5554
tar zxf linux-"${KERN_VERSION}".tar.gz
5655

5756
pushd linux-"${KERN_VERSION}" || exit
5857

59-
cp /configs/"${ARCH}" .config
60-
make ARCH="${ARCH}" olddefconfig
61-
make ARCH="${ARCH}" clean
62-
6358
LOCALVERSION="-pl"
6459

65-
DEB_ARCH="${ARCH//x86_64/amd64}"
66-
# binary builds are required for non git trees after linux v6.3 (inclusive).
67-
# The .deb file suffix is also different.
68-
TARGET='bindeb-pkg'
69-
DEB_SUFFIX="-1_${DEB_ARCH}.deb"
70-
if [ "${KERN_MAJ}" -lt 6 ] || { [ "${KERN_MAJ}" -le 6 ] && [ "${KERN_MIN}" -lt 3 ]; }; then
71-
TARGET='deb-pkg'
72-
DEB_SUFFIX="${LOCALVERSION}-1_${DEB_ARCH}.deb"
73-
fi
74-
echo "Building ${TARGET} for ${KERN_VERSION}${LOCALVERSION} (${ARCH})"
60+
cp /configs/"${ARCH}" .config
61+
make ARCH="${ARCH}" olddefconfig
7562

76-
EXTRA_MAKE_ARGS=""
77-
if [ "${ARCH}" != "$(uname -m)" ]; then
78-
# Skip dpkg dependency checks when cross-compiling, since host packages
79-
# (e.g. libssl-dev) won't satisfy target arch requirements.
80-
EXTRA_MAKE_ARGS="DPKG_FLAGS=-d"
81-
fi
82-
make ARCH="${ARCH}" -j "$(nproc)" "${TARGET}" LOCALVERSION="${LOCALVERSION}" ${EXTRA_MAKE_ARGS}
63+
# Only generate headers — no kernel or module compilation needed.
64+
# 'make prepare' generates include/generated/ and arch/*/include/generated/
65+
# which are the only outputs we package.
66+
echo "Generating headers for ${KERN_VERSION}${LOCALVERSION} (${ARCH})"
67+
make ARCH="${ARCH}" prepare LOCALVERSION="${LOCALVERSION}"
8368

8469
popd || exit
8570
popd || exit
8671

87-
# Extract headers into a tarball
88-
dpkg -x src/linux-headers-"${KERN_VERSION}${LOCALVERSION}_${KERN_VERSION}${DEB_SUFFIX}" .
72+
# Package headers into the same directory structure the old deb-pkg approach produced
73+
# (usr/src/linux-headers-<version><localversion>/{include,arch}).
74+
KERNEL_ARCH="${ARCH//x86_64/x86}"
75+
HEADERS_DIR="usr/src/linux-headers-${KERN_VERSION}${LOCALVERSION}"
76+
77+
mkdir -p "${HEADERS_DIR}/arch"
78+
cp -a "src/linux-${KERN_VERSION}/include" "${HEADERS_DIR}/"
79+
cp -a "src/linux-${KERN_VERSION}/arch/${KERNEL_ARCH}" "${HEADERS_DIR}/arch/"
8980

9081
# Remove broken symlinks
91-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -xtype l -exec rm {} +
92-
93-
# Remove uneeded files to reduce size
94-
# Keep only:
95-
# - usr/src/linux-headers-x.x.x-pl/include
96-
# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH}
97-
# This reduces the size by a little over 2x.
98-
rm -rf usr/share
99-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \
100-
-exec rm -rf {} +
101-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}"/arch -maxdepth 1 -mindepth 1 ! -name "${ARCH//x86_64/x86}" -type d -exec rm -rf {} +
82+
find "${HEADERS_DIR}" -xtype l -exec rm {} +
83+
84+
# Remove non-header files from arch/ to reduce size.
85+
# Only headers (.h), Makefiles, Kconfigs, and Kbuilds are needed.
86+
find "${HEADERS_DIR}/arch" -type f \
87+
! -name '*.h' \
88+
! -name 'Makefile' \
89+
! -name 'Kconfig*' \
90+
! -name 'Kbuild*' \
91+
-delete
92+
# Clean up empty directories left behind.
93+
find "${HEADERS_DIR}/arch" -type d -empty -delete
10294

10395
tar zcf linux-headers-"${ARCH}"-"${KERN_VERSION}".tar.gz usr
10496

0 commit comments

Comments
 (0)