How do I obtain kernel headers on GKE ContainerOS image?
I need the kernel headers but there is no /lib/modules/[kernel version]/build
or /usr/src/[kernel version]
. I'm assuming they ripped those out to trim down the image.
My use case: I am using bpftrace
to trace the kernel using kprobes and tracepoints and it needs to know certain struct definitions in order to know the memory layout of args/ret values.
Is there an easy way to download the headers for the kernel I am running? I am running 1.10.7-gke.6 ALPHA (linux 4.14.65+)
.
Solution 1:
Looks like:
https://chromium.googlesource.com/chromiumos/third_party/kernel/+/linux/v4.14.65
have been led there via:
https://cloud.google.com/container-optimized-os/docs/resources/sources
Solution 2:
Here is the script I used to download the source for the current kernel, extract it, and print out the environment variable export to get bpftrace
to read from that location. This was needed since /lib/modules
is read only.
#!/bin/bash
set -Eeuo pipefail
kversion=v"$(uname -r | sed -E 's/\+*$//')"
wget "https://chromium.googlesource.com/chromiumos/third_party/kernel/+archive/$kversion.tar.gz"
mkdir kernel
tar xzf "$kversion.tar.gz" -C kernel
echo "export BPFTRACE_KERNEL_SOURCE=$PWD/kernel"