### Example of starting a container with environment variables Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md This example demonstrates how to start a container and set environment variables using the `start_container.sh` script. It shows both a space-separated list of variables and individual `-e` flags. ```bash $ export VAR=something $ ./start_container.sh gcc-7 $(pwd) /tmp -e "FOO=BAR FOOBAR= VAR=$VAR" -- /usr/bin/env Hey, we gonna use sudo for running docker Starting "kernel-build-container:gcc-7" Source code directory "/mnt/example/kernel-build-containers" is mounted at "~/src" Build output directory "/tmp" is mounted at "~/out" Container environment: -e FOO=BAR -e FOOBAR= -e VAR=something Run docker in interactive mode Gonna run "/usr/bin/env" PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=e769fbdf9d72 FOO=BAR FOOBAR= VAR=something ``` ```bash ./start_container.sh gcc-7 $(pwd) /tmp -e "FOO=BAR" -e "FOOBAR=" -e "VAR=$VAR" -- /usr/bin/env ``` -------------------------------- ### LLVM Build Configuration Example Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md An example of how to configure the make command to use specific LLVM tools for building the kernel, including clang for the C compiler and various llvm-* utilities for linking, archiving, and object file manipulation. ```shell make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \ OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \ HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld ``` -------------------------------- ### Get help for start_container.sh Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Displays the usage information for the start_container.sh script, outlining available options and their purposes. ```console $ bash start_container.sh usage: start_container.sh compiler src_dir out_dir [-h] [-d | -p] [-n] [-e VAR] [-v] [-- cmd with args] -h print this help -d force to use the Docker container engine (default) -p force to use the Podman container engine instead of default Docker -n launch container in non-interactive mode -e add environment variable in the container (may be used multiple times) -v enable debug output If cmd is empty, we will start an interactive bash in the container. ``` -------------------------------- ### Get help for manage_images.py Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Displays the usage and available options for the manage_images.py script. ```console $ python3 manage_images.py -h usage: manage_images.py [-h] [-d] [-p] [-l] [-b [compiler]] [-q] [-r [compiler]] Manage the images for kernel-build-containers options: -h, --help show this help message and exit -d, --docker force to use the Docker container engine (default) -p, --podman force to use the Podman container engine instead of default Docker -l, --list show the container images and their IDs -b, --build [compiler] build a container image providing: clang-5 / clang-6 / clang-7 / clang-8 / clang-9 / clang-10 / clang-11 / clang-12 / clang-13 / clang-14 / clang-15 / clang-16 / clang-17 / clang-18 / clang-19 / clang-20 / clang-21 / gcc-4.9 / gcc-5 / gcc-6 / gcc-7 / gcc-8 / gcc-9 / gcc-10 / gcc-11 / gcc-12 / gcc-13 / gcc-14 / gcc-15 / all ("all" is default, the tool will build all images if no compiler is specified) -q, --quiet suppress the container image build output (for using with --build) -r, --remove [compiler] remove container images providing: clang-5 / clang-6 / clang-7 / clang-8 / clang-9 / clang-10 / clang-11 / clang-12 / clang-13 / clang-14 / clang-15 / clang-16 / clang-17 / clang-18 / clang-19 / clang-20 / clang-21 / gcc-4.9 / gcc-5 / gcc-6 / gcc-7 / gcc-8 / gcc-9 / gcc-10 / gcc-11 / gcc-12 / gcc-13 / gcc-14 / gcc-15 / all ("all" is default, the tool will remove all images if no compiler is specified) ``` -------------------------------- ### Run the container for kernel build Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example command to run the kernel build container with specified toolchain, source, and output directories, including cross-compilation arguments. ```bash bash /home/a13x/kernel-build-containers/start_container.sh gcc-13 /home/a13x/linux-stable/linux-stable /home/a13x/linux-stable/build_out/experiment__arm64__gcc-13 --docker -n -- make O=../out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 6 ``` -------------------------------- ### Docker images created Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example output of the 'docker images' command showing the newly created kernel-build-container images. ```console $ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE kernel-build-container clang-21 dc9408fe5e57 8 seconds ago 2.55GB kernel-build-container gcc-15 dc9408fe5e57 8 seconds ago 2.55GB kernel-build-container clang-20 1d60452476af 29 seconds ago 2.6GB kernel-build-container clang-19 02ce18c03133 52 seconds ago 2.5GB kernel-build-container clang-18 7915eeb58d81 2 minutes ago 2.54GB kernel-build-container gcc-14 7915eeb58d81 2 minutes ago 2.54GB kernel-build-container clang-17 dc7862ae9f4d 2 minutes ago 2.49GB ``` -------------------------------- ### Expected output after building all images Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example output showing the status of all Docker container images after a full build. ```console Current status: -------------------------------------------- Ubuntu | Clang | GCC | Docker Image ID -------------------------------------------- 16.04 | 5 | 4.9 | 84de06274519 16.04 | 6 | 5 | 9f1a2dd62fdd 18.04 | 7 | 6 | 112aac42ce4c 18.04 | 8 | 7 | 9aba209703da 20.04 | 9 | 8 | c1e7857ea7b9 20.04 | 10 | 9 | 70773f4ade91 20.04 | 11 | 10 | 794661e2251e 22.04 | 12 | 11 | a3edfb04cb59 22.04 | 13 | 12 | fd3d31b4b29b 22.04 | 14 | 12 | 9f78a073c0a2 24.04 | 15 | 13 | a48106dc194e 24.04 | 16 | 14 | 1c0aba835f6c 24.04 | 17 | 14 | 18f5a5c70571 24.04 | 18 | 14 | 3094501608ca 25.10 | 19 | 15 | b92832c98d2e 25.10 | 20 | 15 | 6cca70656bf3 25.10 | 21 | 15 | 9b3a8c479067 -------------------------------------------- ``` -------------------------------- ### Kernel Build Example with Clang Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Demonstrates how to use the make_linux.py utility to build the Linux kernel with clang-12 support, including specifying architecture, configuration, sources, output directory, and parallel jobs. ```console $ python3 make_linux.py -a aarch64 -k ~/linux/experiment.config -s ~/linux/linux -o ~/linux/build_out -c clang-12 -- -j5 ``` -------------------------------- ### In-place build with defconfig Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example command for an in-place build of the Linux kernel using a specific toolchain and the 'defconfig' target, without specifying separate source and output directories. ```console python3 build_linux.py -c clang-16 -a x86_64 -s ~/linux-stable/linux-stable -- defconfig ``` -------------------------------- ### Python Syntax Error Example Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md An example of a SyntaxError in Python related to f-string formatting. ```python File "./manage_containers.py", line 124 print(f'\n{'Ubuntu':<6} | {'GCC':<6} | {'Clang':<6} | {'Status':<6}') ^ SyntaxError: invalid syntax ``` -------------------------------- ### Configure Linux kernel with menuconfig Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example command to configure the Linux kernel using menuconfig within a Docker container, specifying architecture, kconfig, source, output, and compiler. ```console $ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13 -- menuconfig Docker container engine is chosen (default) Going to build the Linux kernel for arm64 Going to build with gcc-13 Using "/home/a13x/linux-stable/experiment.config" as kernel config Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory Using "/home/a13x/linux-stable/build_out" as build output directory Have additional arguments for 'make': menuconfig Going to run 'make' on 6 CPUs Output subdirectory for this build: /home/a13x/linux-stable/build_out/experiment__arm64__gcc-13 Output subdirectory doesn't exist, create it No ".config", copy "/home/a13x/linux-stable/experiment.config" to "/home/a13x/linux-stable/build_out/experiment__arm64__gcc-13/.config" Going to run the container in the interactive mode (without build log) Add arguments for cross-compilation: ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Run the container: bash /home/a13x/kernel-build-containers/start_container.sh gcc-13 /home/a13x/linux-stable/linux-stable /home/a13x/linux-stable/build_out/experiment__arm64__gcc-13 --docker -- make O=../out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 6 menuconfig Force to use the Docker container engine Hey, we gonna use sudo for running the container Starting "kernel-build-container:gcc-13" Gonna run the container in interactive mode Mount source code directory "/home/a13x/linux-stable/linux-stable" at "/src" Mount build output directory "/home/a13x/linux-stable/build_out/experiment__arm64__gcc-13" at "/out" Gonna run command "make O=../out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 6 menuconfig" make[1]: Entering directory '/out' GEN Makefile ... *** End of the configuration. *** Execute 'make' to start the build or try 'make help'. make[1]: Leaving directory '/out' The container returned 0 Finish building the kernel Only remove the container id file: Search "container.id" file in build output directory "/home/a13x/linux-stable/build_out/experiment__arm64__gcc-13" NO such file, nothing to do, exit The finish_container.sh script returned 2 [+] Done, see the results ``` -------------------------------- ### Run interactive bash in the container Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Starts a container and launches an interactive bash session within it, mounting source and build directories. ```console $ bash start_container.sh gcc-12 ~/linux-stable/linux-stable/ ~/linux-stable/build_out/ Docker container engine is chosen (default) Hey, we gonna use sudo for running the container Starting "kernel-build-container:gcc-12" Gonna run the container in interactive mode Mount source code directory "/home/a13x/linux-stable/linux-stable/" at "/src" Mount build output directory "/home/a13x/linux-stable/build_out/" at "/out" Gonna run bash a13x@38f63939b504:~/src$ ``` -------------------------------- ### Package Installation Output Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Output from setting up various clang and llvm packages, followed by a 'permission denied' error when trying to mount binfmt_misc. ```bash Setting up clang-6.0 (1:6.0-1ubuntu2~16.04.1) ... Setting up clang-tools-6.0 (1:6.0-1ubuntu2~16.04.1) ... Setting up libffi-dev:amd64 (3.2.1-4) ... Setting up llvm-6.0-runtime (1:6.0-1ubuntu2~16.04.1) ... mount: permission denied update-binfmts: warning: Couldn't mount the binfmt_misc filesystem on /proc/sys/fs/binfmt_misc. Setting up llvm-6.0 (1:6.0-1ubuntu2~16.04.1) ... Setting up llvm-6.0-dev (1:6.0-1ubuntu2~16.04.1) ... Setting up lld-6.0 (1:6.0-1ubuntu2~16.04.1) ... Setting up libomp5:amd64 (3.7.0-3) ... Setting up libomp-dev (3.7.0-3) ... ``` -------------------------------- ### Expected output when containers are not running Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example output showing the status of container images when no containers are running. ```console [+] Docker container engine is chosen (default) [!] INFO: We need "sudo" for working with Docker containers Current status: -------------------------------------------- Ubuntu | Clang | GCC | Docker Image ID -------------------------------------------- 16.04 | 5 | 4.9 | - 16.04 | 6 | 5 | - 18.04 | 7 | 6 | - 18.04 | 8 | 7 | - 20.04 | 9 | 8 | - 20.04 | 10 | 9 | - 20.04 | 11 | 10 | - 22.04 | 12 | 11 | - 22.04 | 13 | 12 | - 22.04 | 14 | 12 | - 24.04 | 15 | 13 | - 24.04 | 16 | 14 | - 24.04 | 17 | 14 | - 24.04 | 18 | 14 | - 25.10 | 19 | 15 | - 25.10 | 20 | 15 | - 25.10 | 21 | 15 | - -------------------------------------------- ``` -------------------------------- ### Expected output when containers are running Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example output indicating that removing an image failed because some containers are using it. ```console ... Remove the container image 907c031bb9f6 providing Clang 15 and GCC 13 [!] WARNING: Removing the image 907c031bb9f6 failed, some containers use it ... [!] WARNING: failed to remove 1 container image(s), see the log above Current status: -------------------------------------------- Ubuntu | Clang | GCC | Docker Image ID -------------------------------------------- 16.04 | 5 | 4.9 | - 16.04 | 6 | 5 | - 18.04 | 7 | 6 | - 18.04 | 8 | 7 | - 20.04 | 9 | 8 | - 20.04 | 10 | 9 | - 20.04 | 11 | 10 | - 22.04 | 12 | 11 | - 22.04 | 13 | 12 | - 22.04 | 14 | 12 | - 24.04 | 15 | 13 | 907c031bb9f6 24.04 | 16 | 14 | - 24.04 | 17 | 14 | - 24.04 | 18 | 14 | - 25.10 | 19 | 15 | - 25.10 | 20 | 15 | - 25.10 | 21 | 15 | - -------------------------------------------- ``` -------------------------------- ### In-place Linux Kernel Build Example Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Demonstrates how to perform an in-place build of the Linux kernel using build_linux.py, specifying clang-16 and x86_64 architecture, and allowing the build to occur at the root of the kernel source tree. ```console $ python3 build_linux.py -c clang-16 -a x86_64 -s ~/linux-stable/linux-stable -- defconfig Going to build the Linux kernel for x86_64 Going to build with clang-16 Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory Have additional arguments for 'make': defconfig Going to run 'make' on 6 CPUs No '-k' and '-o' arguments; skip creating an output subdirectory to allow in-place build Output subdirectory for this build: /home/a13x/linux-stable/linux-stable Output subdirectory already exists, use it (no cleaning!) No kconfig to copy to the output subdirectory Going to write the build log to "/home/a13x/linux-stable/linux-stable/build_log.txt" Going to build the kernel in-place (without 'O=') Add arguments for compiling with clang: CC=clang Run the container: bash /home/a13x/kernel-build-containers/start_container.sh clang-16 /home/a13x/linux-stable/linux-stable /home/a13x/linux-stable/linux-stable -n -- make CC=clang -j 6 defconfig Hey, we gonna use sudo for running docker Run docker in NON-interactive mode Starting "kernel-build-container:clang-16" Mount source code directory "/home/a13x/linux-stable/linux-stable" at "/src" Mount build output directory "/home/a13x/linux-stable/linux-stable" at "/out" Gonna run command "make CC=clang -j 6 defconfig" HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o ... *** Default configuration is based on 'x86_64_defconfig' # # configuration written to .config # The container returned 0 Finish building the kernel Only remove the container id file: Hey, we gonna use sudo for running docker Search "container.id" file in build output directory "/home/a13x/linux-stable/linux-stable" OK, "container.id" file exists, removing it OK, container 17e85692f36973a4e641fd5052bd2f33ce7d1f9f76ea8a73893b557f395d80cc doesn't run The finish_container.sh script returned 0 See the build log: /home/a13x/linux-stable/linux-stable/build_log.txt [+] Done, see the results ``` -------------------------------- ### Build Linux kernel saving output to a separate directory Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Example command to build the Linux kernel within a Docker container, specifying architecture, kconfig, source, output, and compiler, and saving the build output to a designated directory. ```console $ python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13 Docker container engine is chosen (default) Going to build the Linux kernel for arm64 Going to build with gcc-13 Using "/home/a13x/linux-stable/experiment.config" as kernel config Using "/home/a13x/linux-stable/linux-stable" as Linux kernel sources directory Using "/home/a13x/linux-stable/build_out" as build output directory Going to run 'make' on 6 CPUs ``` -------------------------------- ### Build Failure Example Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Illustrates a scenario where a kernel build fails, showing the error message from 'make' and the container's return code, contrasting with successful build output. ```log LD [M] fs/nfs/flexfilelayout/nfs_layout_flexfiles.o AR fs/nfs/built-in.a AR fs/built-in.a make[1]: Leaving directory '/home/user/out' make: *** [Makefile:185: __sub-make] Error 2 Running the container returned 2 See build log: .../build_log.txt [+] Done, see the results ``` -------------------------------- ### Dockerfile Modifications for LLVM/Clang Binaries Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md This diff shows the addition of update-alternatives commands to install various LLVM and Clang binaries, ensuring they are correctly linked and accessible. ```diff diff --git a/Dockerfile b/Dockerfile index 5e4b38c..cfe7e14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,13 @@ RUN set -ex; \ update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 100; \ update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${CLANG_VERSION} 100; \ update-alternatives --install /usr/bin/lld lld /usr/bin/lld-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/ld.lld ld.lld /usr/bin/lld-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-strip llvm-strip /usr/bin/llvm-strip-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-objcopy llvm-objcopy /usr/bin/llvm-objcopy-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-objdump llvm-objdump /usr/bin/llvm-objdump-${CLANG_VERSION} 100; \ + update-alternatives --install /usr/bin/llvm-readelf llvm-readelf /usr/bin/llvm-readelf-${CLANG_VERSION} 100; \ fi ARG UNAME ``` -------------------------------- ### Build Failure due to missing linker Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md This snippet shows the output of a failed `make` command when the 'ld.lld' linker is not found, followed by the installation of LLVM and LLD, and a successful subsequent `make` command. ```bash d@c8eb62a7a1c8:/src/exploit_env/drill$ make mrproper d@c8eb62a7a1c8:/src/exploit_env/drill$ cp config .config d@c8eb62a7a1c8:/src/exploit_env/drill$ make LLVM=1 -j16 SYNC include/config/auto.conf.cmd HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.[ch] HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTCC scripts/kconfig/util.o HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/parser.tab.o HOSTLD scripts/kconfig/conf scripts/Kconfig.include:40: linker 'ld.lld' not found make[2]: *** [scripts/kconfig/Makefile:71: syncconfig] Error 1 make[1]: *** [Makefile:603: syncconfig] Error 2 make: *** [Makefile:712: include/config/auto.conf.cmd] Error 2 d@c8eb62a7a1c8:/src/exploit_env/drill$ sudo apt install llvm lld Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: llvm-runtime The following NEW packages will be installed: lld llvm llvm-runtime 0 upgraded, 3 newly installed, 0 to remove and 8 not upgraded. Need to get 10.1 kB of archives. After this operation, 137 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 lld amd64 1:14.0-55~exp2 [3178 B] Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 llvm-runtime amd64 1:14.0-55~exp2 [3204 B] Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 llvm amd64 1:14.0-55~exp2 [3758 B] Fetched 10.1 kB in 11s (883 B/s) Selecting previously unselected package lld:amd64. (Reading database ... 32905 files and directories currently installed.) Preparing to unpack .../lld_1%3a14.0-55~exp2_amd64.deb ... Unpacking lld:amd64 (1:14.0-55~exp2) ... Selecting previously unselected package llvm-runtime:amd64. Preparing to unpack .../llvm-runtime_1%3a14.0-55~exp2_amd64.deb ... Unpacking llvm-runtime:amd64 (1:14.0-55~exp2) ... Selecting previously unselected package llvm. Preparing to unpack .../llvm_1%3a14.0-55~exp2_amd64.deb ... Unpacking llvm (1:14.0-55~exp2) ... Setting up lld:amd64 (1:14.0-55~exp2) ... Setting up llvm-runtime:amd64 (1:14.0-55~exp2) ... Setting up llvm (1:14.0-55~exp2) ... d@c8eb62a7a1c8:/src/exploit_env/drill$ make LLVM=1 -j16 SYNC include/config/auto.conf.cmd SYSTBL arch/x86/include/generated/asm/syscalls_32.h SYSHDR arch/x86/include/generated/asm/unistd_32_ia32.h SYSHDR arch/x86/include/generated/asm/unistd_64_x32.h SYSTBL arch/x86/include/generated/asm/syscalls_64.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_32.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_64.h SYSHDR arch/x86/include/generated/uapi/asm/unistd_x32.h WRAP arch/x86/include/generated/uapi/asm/bpf_perf_event.h WRAP arch/x86/include/generated/uapi/asm/errno.h WRAP arch/x86/include/generated/uapi/asm/fcntl.h WRAP arch/x86/include/generated/uapi/asm/ioctl.h WRAP arch/x86/include/generated/uapi/asm/ioctls.h WRAP arch/x86/include/generated/uapi/asm/ipcbuf.h WRAP arch/x86/include/generated/uapi/asm/param.h WRAP arch/x86/include/generated/uapi/asm/poll.h WRAP arch/x86/include/generated/uapi/asm/resource.h WRAP arch/x86/include/generated/uapi/asm/socket.h WRAP arch/x86/include/generated/uapi/asm/sockios.h WRAP arch/x86/include/generated/uapi/asm/termbits.h WRAP arch/x86/include/generated/uapi/asm/termios.h WRAP arch/x86/include/generated/uapi/asm/types.h HOSTCC arch/x86/tools/relocs_32.o HOSTCC arch/x86/tools/relocs_64.o HOSTCC arch/x86/tools/relocs_common.o WRAP arch/x86/include/generated/asm/early_ioremap.h [...] ``` -------------------------------- ### Help command for build_linux.py Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Displays the usage and available options for the build_linux.py script, including architecture, compiler, source, and output directories. ```console $ python3 build_linux.py --help usage: build_linux.py [-h] [-d] [-p] -a ARCH -c COMPILER [-k KCONFIG] -s SRC [-o OUT] [-q] [-t] ... Build Linux kernel using kernel-build-containers positional arguments: ... additional arguments for 'make', can be separated by -- delimiter options: -h, --help show this help message and exit -d, --docker force to use the Docker container engine (default) -p, --podman force to use the Podman container engine instead of default Docker -a, --arch ARCH build target architecture (x86_64 / i386 / arm64 / arm / riscv / powerpc / powerpc64 / powerpc64le) -c, --compiler COMPILER compiler for building (clang-5 / clang-6 / clang-7 / clang-8 / clang-9 / clang-10 / clang-11 / clang-12 / clang-13 / clang-14 / clang-15 / clang-16 / clang-17 / clang-18 / clang-19 / clang-20 / clang-21 / gcc-4.9 / gcc-5 / gcc-6 / gcc-7 / gcc-8 / gcc-9 / gcc-10 / gcc-11 / gcc-12 / gcc-13 / gcc-14 / gcc-15) -k, --kconfig KCONFIG path to kernel kconfig file (optional argument) -s, --src SRC Linux kernel sources directory -o, --out OUT build output directory, where the output subdirectory "kconfig__arch__compiler" is created. Without '-k', the output subdirectory name format is "arch__compiler". For in-place building of Linux at the root of the kernel source tree, you can specify the same '-s' and '-o' path without '-k' or simply run the tool without '-o' and '-k' arguments. -q, --quiet for running `make` in quiet mode -t, --single-thread for running `make` in single-threaded mode (multi-threaded by default) ``` -------------------------------- ### Build Linux kernel with specified configuration and output Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to build the Linux kernel using a specific configuration file and output directory, demonstrating error handling when kconfig files differ. ```console python3 build_linux.py -a arm64 -k ~/linux-stable/experiment.config -s ~/linux-stable/linux-stable -o ~/linux-stable/build_out -c gcc-13 ``` -------------------------------- ### Build all container images Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Commands to build all available container images using Docker. ```console $ python3 manage_images.py -d -b all ``` ```console # or simply run: $ python3 manage_images.py -d -b ``` -------------------------------- ### Kernel Build Process Log Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md This snippet shows the output log of the kernel build process, including container startup, build commands, and completion messages. ```bash Starting "kernel-build-container:clang-16" Mount source code directory "/home/a13x/linux-stable/linux-stable" at "/src" Mount build output directory "/home/a13x/linux-stable/linux-stable" at "/out" Gonna run command "make CC=clang -j 6 defconfig" HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o ... *** Default configuration is based on 'x86_64_defconfig' # # configuration written to .config # The container returned 0 Finish building the kernel Only remove the container id file: Search "container.id" file in build output directory "/home/a13x/linux-stable/linux-stable" Hey, we gonna use sudo for running the container OK, "container.id" file exists, removing it OK, container 02851894aa6a6f5c1b1e0c72cbd3917e2e82349f8ffb3281dc36454abb98391a doesn't run The finish_container.sh script returned 0 See the build log: /home/a13x/linux-stable/linux-stable/build_log.txt [+] Done, see the results ``` -------------------------------- ### Build a single Podman container image Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to build a specific GCC version container image using Podman. ```console $ python3 manage_images.py -p -b gcc-12 ``` -------------------------------- ### Synchronize Kconfig files Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Commands to diff and copy Kconfig files when they differ, to resolve build errors. ```bash diff ~/linux-stable/experiment.config ~/linux-stable/build_out/experiment__arm64__gcc-13/.config cp ~/linux-stable/build_out/experiment__arm64__gcc-13/.config ~/linux-stable/experiment.config ``` -------------------------------- ### Execute a command in the container Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Executes a specific command (e.g., 'make defconfig') within a container after mounting source and build directories. ```console $ bash start_container.sh clang-15 ~/linux-stable/linux-stable/ ~/linux-stable/build_out/ -- make defconfig Docker container engine is chosen (default) Hey, we gonna use sudo for running the container Starting "kernel-build-container:clang-15" Gonna run the container in interactive mode Mount source code directory "/home/a13x/linux-stable/linux-stable/" at "/src" Mount build output directory "/home/a13x/linux-stable/build_out/" at "/out" Gonna run command "make defconfig" *** Default configuration is based on 'x86_64_defconfig' ... ``` -------------------------------- ### List container images for Podman Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to list available container images for the Podman engine, showing their status and Image IDs. ```console $ python3 manage_images.py -p -l ``` -------------------------------- ### Build a single Docker container image Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to build a specific GCC version container image using Docker. ```console $ python3 manage_images.py -d -b gcc-12 ``` ```console # or simply run (Docker is the default engine): $ python3 manage_images.py -b gcc-12 ``` -------------------------------- ### Run container for in-place build Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to run the container for an in-place kernel build with clang, specifying the source directory and additional make arguments. ```bash bash /home/a13x/kernel-build-containers/start_container.sh clang-16 /home/a13x/linux-stable/linux-stable /home/a13x/linux-stable/linux-stable --docker -n -- make CC=clang -j 6 defconfig ``` -------------------------------- ### Build a container image quietly Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Command to build a specific Clang version container image using Docker without showing build output. ```console $ python3 manage_images.py -d -b clang-11 -q ``` -------------------------------- ### Run tests after changing Python scripts Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Commands to run tests for manage_images.py and build_linux.py after making changes to these scripts. ```bash bash tests_for_manage_images.sh ``` ```bash bash tests_for_build_linux.sh ``` -------------------------------- ### Kernel build script execution and output Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Demonstrates the execution of the make_linux.py script with specific arguments and the subsequent build process within a Docker container, including handling of keyboard interrupts. ```bash $ ./make_linux.py -a aarch64 -k ~/develop_local/linux/experiment.config -s ~/develop_local/linux/linux -o ~/develop_local/linux/build_out -c gcc-8 -- -j5 [+] Going to build the Linux kernel for aarch64 [+] Using "/home/a13x/develop_local/linux/experiment.config" as kernel config [+] Using "/home/a13x/develop_local/linux/linux" as Linux kernel sources directory [+] Using "/home/a13x/develop_local/linux/build_out" as build output directory [+] Going to build with: gcc-8 [+] Have additional arguments for 'make': -j5 === Building with gcc-8 === Output subdirectory for this build: /home/a13x/develop_local/linux/build_out/experiment__aarch64__gcc-8 Output subdirectory already exists, use it (no cleaning!) Copy kconfig to output subdirectory as ".config" Going to save build log to "build_log.txt" in output subdirectory Create additional arguments for cross-compilation: ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Run the container: bash ./start_container.sh gcc-8 /home/a13x/develop_local/linux/linux /home/a13x/develop_local/linux/build_out/experiment__aarch64__gcc-8 -n make O=~/out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j5 2>&1 Hey, we gonna use sudo for running docker Starting "kernel-build-container:gcc-8" Source code directory "/home/a13x/develop_local/linux/linux" is mounted at "~/src" Build output directory "/home/a13x/develop_local/linux/build_out/experiment__aarch64__gcc-8" is mounted at "~/out" Run docker in NON-interactive mode Gonna run "make O=~/out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j5 2>&1" [sudo] пароль для a13x: make[1]: Entering directory '/home/a13x/out' GEN Makefile scripts/kconfig/conf --syncconfig Kconfig GEN Makefile CALL /home/a13x/src/scripts/atomic/check-atomics.sh CALL /home/a13x/src/scripts/checksyscalls.sh CC arch/arm64/mm/dma-mapping.o CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o CC kernel/time/alarmtimer.o CC mm/shmem.o OBJCOPY arch/arm64/kernel/efi-entry.stub.o AR init/built-in.a CC arch/arm64/net/bpf_jit_comp.o CC arch/arm64/kernel/mte.o CC arch/arm64/mm/extable.o CC kernel/time/posix-timers.o CC arch/arm64/mm/fault.o ^C[!] Got keyboard interrupt, stopping build process... Kill the container and remove the container id file: Hey, we gonna use sudo for running docker Search "container.id" file in build output directory "/home/a13x/develop_local/linux/build_out/experiment__aarch64__gcc-8" OK, "container.id" file exists, removing it Killing the docker container 0463bef60bc7b295dbd9c84a5639693b5dd7768113037d4a8c0bd10e3062ad4c 0463bef60bc7b295dbd9c84a5639693b5dd7768113037d4a8c0bd10e3062ad4c Container 0463bef60bc7b295dbd9c84a5639693b5dd7768113037d4a8c0bd10e3062ad4c is killed Finished with the container [!] Early exit $ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ ``` -------------------------------- ### Check Docker build cache usage Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Command to display Docker build cache usage statistics. ```bash docker system df ``` -------------------------------- ### Container Build Log Snippet Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md An excerpt from a build log showing the steps involved in compiling the Linux kernel within a container using clang-12, including Docker commands and make output. ```log [+] Going to build the Linux kernel for aarch64 [+] Using "/home/a13x/linux/experiment.config" as kernel config [+] Using "/home/a13x/linux/linux" as Linux kernel sources directory [+] Using "/home/a13x/linux/build_out" as build output directory [+] Going to build with: clang-12 [+] Have additional arguments for 'make': -j5 === Building with clang-12 === Output subdirectory for this build: /home/a13x/linux/build_out/experiment__aarch64__clang-12 Output subdirectory already exists, use it (no cleaning!) Copy kconfig to output subdirectory as ".config" Going to save build log to "build_log.txt" in output subdirectory Compiling with clang requires 'CC=clang' Add arguments for cross-compilation: ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Run the container: bash ./start_container.sh clang-12 /home/a13x/linux/linux /home/a13x/linux/build_out/experiment__aarch64__clang-12 -n make O=~/out/ CC=clang ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j5 2>&1 Hey, we gonna use sudo for running docker Starting "kernel-build-container:clang-12" Source code directory "/home/a13x/linux/linux" is mounted at "~/src" Build output directory "/home/a13x/linux/build_out/experiment__aarch64__clang-12" is mounted at "~/out" Run docker in NON-interactive mode Gonna run "make O=~/out/ CC=clang ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j5 2>&1" make[1]: Entering directory '/home/a13x/out' SYNC include/config/auto.conf.cmd GEN Makefile ... make[1]: Leaving directory '/home/a13x/out' The container returned 0 See build log: /home/a13x/linux/build_out/experiment__aarch64__clang-12/build_log.txt Only remove the container id file: Hey, we gonna use sudo for running docker Search "container.id" file in build output directory "/home/a13x/linux/build_out/experiment__aarch64__clang-12" OK, "container.id" file exists, removing it OK, container 48a25a340a1ceb3d1ee4baa4eafb1b44ad98c6a70bd105f0376cffb2ba21bd2e doesn't run Finished with the container [+] Done, see the results ``` -------------------------------- ### Remove all created container images Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/README.md Commands to remove all created container images. ```console $ python3 manage_images.py -r all ``` ```console $ python3 manage_images.py -r ``` -------------------------------- ### Run image cleanup script Source: https://github.com/a13xp0p0v/kernel-build-containers.git/blob/master/issues.md Command to run a Python script for managing Docker images. ```bash python3 manage_images.py -r ```