Linux kernel build and install manual

Linux kernel

The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel.

Linux commands are of the Debian family.
Linux version is 5.15 or later

How to build linux kernel

Download requirements

# apt-get install build-essential bc bison flex libssl-dev # or yum

Download source code

# git clone --depth=1 -b v5.15 https://github.com/torvalds/linux.git

When you download only the version you want, you only need to modify the 5.15 part.
The reason for downloading this is that the linux source has a very large capacity. It’s to save time.

Kernel build

# cd linux
# make ARCH="$(arch)" defconfig
# make -j"$(nproc)"

When you load architectural information, the arch value
and the Linux target name might not match.
Then, run make ARCH=$(dpkg –print-architecture) defconfig
Optional, you can add make option O=out, If so, the rest of the processes must run cd out and proceed.

cross-compile

If the architecture of the build machine and the target is different, try cross-compile.

Download source code

# git clone --depth=1 -b v5.15 https://github.com/torvalds/linux.git

When you download only the version you want, you only need to modify the 5.15 part.
The reason for downloading this is that the linux source has a very large capacity. It’s to save time.

Kernel cross-compile build

# cd linux
# make ARCH="your_target_archtecture" defconfig
# make CROSS_COMPILE="your_target_toolchain" -j"$(nproc)"
arch toolchain
arm arm-linux-gnueabi- /
arm-linux-gnueabihf-
arm64 aarch64-linux-gnu-
x86 x86_64-linux-gnu-
etc

Optional, you can add make option O=out, If so, the rest of the processes must run cd out and proceed.

How to install linux kernel

If you did nothing and followed well, pwd -P is $prefix/linux . Most likely ~/linux .
If you had cross-compiled, mount the target’s file system.
And you should add option INSTALL_DTBS_PATH=”target’s rootfs” or INSTALL_MOD_PATH=”target’s rootfs” depends on installation type. (except image)
There are three main types of installation.

Kernel install: device-tree-blob(overlays)

# make dtbs_install

Kernel install: kernel-modules

# make modules_install

Kernel install: kernel-image (built-in)

# cp arch/${ARCH}/boot/Image.gz /boot/vmlinuz-$(uname -r) # target's vmlinuz

Example

There is a Linux kernel build & install example.

Updated:

Leave a comment