Zahi Abow
Zahi Abow

Reputation: 49

Linux Kernel Headers are missing on EKS cluster

I have developed an eBPF code that needs to be compiled with kernel headers. My code is working properly on top of AKS however on an EKS cluster I couldn't find the kernel headers.

The kernel version of my vms on EKS is: "5.4.117-58.216.amzn2.x86_64".
Running "apt install linux-headers-$(uname -r)" result: enter image description here

What is the right way to get kernel headers in case they don't exist in apt?

Upvotes: 1

Views: 1408

Answers (2)

leodido
leodido

Reputation: 922

You can find kernel headers for Amazon Linux 2 kernels by searching into their packages' SQLite databases.

In your case, following procedure too:

  1. Download the mirror list
wget amazonlinux.us-east-1.amazonaws.com/2/extras/kernel-5.4/latest/x86_64/mirror.list

Notice that for other kernel versions you may want to substitute "extras/kernel-5.4/latest" with "core/latest" or "core/2.0".

It should contain one (or more) URL(s) like this one:

http://amazonlinux.us-east-1.amazonaws.com/2/extras/kernel-5.4/stable/x86_64/be95e4ca87d6c3b5eb71edeaded5b3b9b216d7cdd330d44f1489008dc4039789

  1. Append the suffix repodata/primary.sqlite.gz to the URL(s) and download the SQLite database(s)
wget "$(head -1 mirror.list)/repodata/primary.sqlite.gz"

Notice the URL(s) may contain the placeholder "$basearch". If that's the case, substitute it with the target architecture (eg., x86_64).

  1. Unarchive it
gzip -d primary.sqlite.gz
  1. Query it for finding where to download your kernel-headers package.
sqlite3 primary.sqlite \
  "SELECT location_href FROM packages WHERE name LIKE 'kernel%' AND name NOT LIKE '%tools%' AND name NOT LIKE '%doc%' AND version='5.4.117' AND release='58.216.amzn2'" | \
  sed 's#\.\./##g'

You'll obtain these:

blobstore/e12d27ecb4df92edc6bf25936a732c93f55291f7c732b83f4f37dd2aeaad5dd4/kernel-headers-5.4.117-58.216.amzn2.x86_64.rpm
blobstore/248b2b078145c4cc7c925850fc56ec0e3f0da141fb1b269fd0c2ebadfd8d41cd/kernel-devel-5.4.117-58.216.amzn2.x86_64.rpm
blobstore/7d82d21a61fa03af4b3afd5fcf2309d5b6a1f5a01909a1b6190e8ddae8a67b89/kernel-5.4.117-58.216.amzn2.x86_64.rpm
  1. Download the package you want by appending its segment to the initial base URL

Like so:

wget amazonlinux.us-east-1.amazonaws.com/blobstore/e12d27ecb4df92edc6bf25936a732c93f55291f7c732b83f4f37dd2aeaad5dd4/kernel-headers-5.4.117-58.216.amzn2.x86_64.rpm

A similar procedure can be used for Amazon Linux 1 kernel headers.

Upvotes: 2

Qeole
Qeole

Reputation: 9134

I don't know if it's an ideal solution, but you could always download the kernel sources and install the headers from there.

$ git clone --depth 1 -b v5.4.117 \
        git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
$ cd linux
# make headers_install

The headers you get from the stable branch are likely close enough to those of your kernel for your eBPF program to work. I don't know if there's a way to retrieve the header files used for building EKS' kernel.

Upvotes: 0

Related Questions