Readme
Cross-compiling the Linux kernel
x86 → arm64
1. Dependencies (Debian/Ubuntu)
bash
sudo apt install build-essential bc bison flex cpio kmod rsync \
libelf-dev libssl-dev dwarves git gcc-aarch64-linux-gnu
2. Sources
bash
git clone --depth 1 --branch v6.12 \
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
Or a tarball from kernel.org: tar xf linux-6.12.tar.xz.
3. Environment variables
bash
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
Or pass them to every make call. This is more reliable: variables get lost when you switch shells or use sudo.
4. Config
bash
make defconfig # default arm64 config
# or take a working config from the target machine:
# scp target:/boot/config-$(uname -r) .config
make olddefconfig # fill in new options
make menuconfig # manual tweaks if needed
Targeted edits without the menu:
bash
scripts/config --module CONFIG_KVM
scripts/config --disable CONFIG_LOCALVERSION_AUTO
scripts/config --set-str CONFIG_LOCALVERSION "-custom"
make olddefconfig
5. Build
bash
make -j$(nproc) Image modules dtbs
Outputs:
- kernel:
arch/arm64/boot/Image - modules:
*.koin the tree - device trees:
arch/arm64/boot/dts/
6. Installing artifacts
bash
make INSTALL_MOD_PATH=/tmp/rootfs modules_install
make INSTALL_DTBS_PATH=/tmp/rootfs/boot/dtbs dtbs_install
cp arch/arm64/boot/Image /tmp/rootfs/boot/vmlinuz-custom
Then copy to the target (rsync/scp), run depmod -a and update-initramfs/dracut, and add a bootloader entry.
Or build .deb packages (Debian targets):
bash
make -j$(nproc) bindeb-pkg LOCALVERSION=-custom
Output lands in the parent directory: linux-image-*.deb, linux-headers-*.deb. Unlike deb-pkg, bindeb-pkg does not require git.
7. Building a single module (without rebuilding the kernel)
bash
make modules_prepare
make M=drivers/gpu/drm/ast modules
The config and compiler version must match the running kernel, otherwise insmod fails with Invalid module format.
Common pitfalls
Invalid module format:vermagicmismatch (kernel version,-dirty/-g<hash>suffix, gcc version, config).asm/xxx.h not found:ARCH=was lost, or the.configcontains a foreign symbol.- Dirty tree:
make mrproper(wipes.config, back it up first). - Read the error above the tail: the final
Error 2means nothing; the cause is the first line witherror:. For debugging use-j1 V=1 2>&1 | tee build.log.