Linux Kernel Cross-compilation

This short post illustrates how to cross-compile the Linux kernel using docker-linux-kernel-builder.

Setup

Assuming Docker is installed on your machine and configured to run without sudo (if not, see here and here), proceed by cloning the project repository:

git clone https://github.com/0xor0ne/docker-linux-kernel-builder.git
cd docker-linux-kernel-build

then edit config.env and set the following variables:

For this example we are going to build Linux kernel 5.15.37 for arm64 (aarch64) by setting the above variables with the following values:

LK_ARCH="arm64"
LK_DOWNLOAD_LINK=https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.37.tar.xz
TC_DOWNLOAD_LINK=https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--glibc--stable-2021.11-1.tar.bz2

At this point, download the kernel source and the toolchain by running the following script:

./scripts/download_lk_tc.sh

For additional details and for using customized kernel source code see the official project README.

Docker Image

Build the docker image:

./scripts/docker_create_volume.sh && ./scripts/docker_build.sh

Kernel Configuration

Use the default kernel configuration for the target architecture with:

./scripts/make.sh defconfig

For instructions on how to use a customized kernel configuration see the project README.

Kernel Build

Finally, build the kernel with (this might take a while):

./scripts/make_all_install_retrieve.sh

the output artifacts will be placed in shared/install.

>>> ls shared/install
config-5.15.37  include  lib  System.map-5.15.37  vmlinuz-5.15.37

- The End -