Docker image for cross-compiling the Linux kernel.
Check the requirements before proceeding.
Put the archives containing the Linux Kernel source code and the toolchain in
the files directory.
Here is an example showing how to download Linux Kernel 3.15.37 from kernel.org and a toolchain provided by Bootlin for arm64 architecture.
curl --output files/kernel.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.37.tar.xz
curl --output files/toolchain.tar.bz2 https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--glibc--stable-2021.11-1.tar.bz2See the documentation for more examples and an automated way to download both the Kernel source code and the toolchain.
Edit file config.env and modify the following variables:
- LK_ARCHIVE_NAME: name of the archive containing the Linux Kernel source code
placed in
filesdirectory; - TC_ARCHIVE_NAME: name of the archive containing the toolchain placed in
filesdirectory; - LK_ARCH: name of the target architecture (must match the used toolchain).
Examples are
arm,arm64andmips
Building the Docker image is a two steps process. At first, a permanent volume containing both the toolchain and the kernel source code must be created with:
./scripts/docker_create_volume.shThen, the actual Docker image can be built with:
./scripts/docker_build.shIt is possible to invoke any available make target on the kernel source code by
using the script scripts/make.sh. For example, the following command will
print the kernel make help message:
./scripts/make.sh helpNOTE: the first time the container is executed it will take more time because a script will take care of extracting the kernel source code and the toolchain contained in the permanent volume.
The kernel can be configured as usual. Here are a few examples:
- Use the default configuration for the target architecture:
./scripts/make.sh defconfig- Configure the kernel manually using a menu based program:
./scripts/make.sh menuconfig- Use an existing configuration: save the existing configuration in
shared/.configand then run:
./scripts/make_olddefconfig.sh- Configure the tiniest possible kernel for the target architecture (with this configuration kernel modules are usually disabled):
./scripts/make.sh tinyconfigBuild the kernel with:
./scripts/make_all_install_retrieve.shat the end of the build process, the output artifacts will be placed in
shared/install. Here you will find the kernel image (vmlinux), the symbol
table (System.map), the used configuration, the kernel headers (in include
directory) and the kernel modules (in lib directory).
The kernel build directory can be cleaned as usual using the clean target or
the mrproper target (for removing also the configuration file). E.g.,
./scripts/make.sh mrproperIn order to start from scratch (remove the permanent volume, the Docker
image and the content of shared directory), you can remove everything with:
./scripts/docker_remove_all.sh- Add script for building out-of-tree kernel modules;
- Add support for building Busybox for quick testing in Qemu;
- Add support for building the kernel with CLANG;
- Add support for building experimental Rust based kernel modules.