Preparation
Install Dependencies
Downloading source and local setup
It is recommended to create a separate build directory for your kernel(s). In this example, the directory kernelbuild will be created in the home directory:
Goto kernel.org and download kernel source
Note: you can verify signature of the downloaded tarball if you want
Extract tarball
Check
Kernel configuration
To finalise the preparation, ensure that the kernel tree is absolutely clean; do not rely on the source tree being clean after unpacking. To do so, first change into the new kernel source directory created, and then run the make mrproper command:
copy config file
make sure all configuration options have values that are required
Another option(not recommended)
automatically detect the hardware and creates config based on just that downside is that its not gonna detect anything which is not currently connected
Menu driven configuration utility(best option)
This should look somewhat like:
Here is the main part of research and knowing your hardware, Good Luck 👍 with that.
When all the required configurations are done, save your configurations in
.config
file.
Build the kernel
We can use -j flag to use multiple cores of cpu while compiling
This process will normally take some time so grab a cup of coffee(it took around 1 hour for me)
Installation
Install the modules
Once the kernel has been compiled, the modules for it must follow. First build the modules:
Change to root user
Then install the modules.
This will copy the compiled modules into /lib/modules/<kernel_version>-<config_local_version>
. For example, for kernel version 5.14 installed above, they would be copied to /lib/modules/5.14.5-ARCH
. This keeps the modules for individual kernels used separated.
Copy the kernel to /boot directory
The kernel compilation process will generate a compressed bzImage
(big zImage) of that kernel, which must be copied to the /boot directory and renamed in the process. Provided the name is prefixed with vmlinuz-
, you may name the kernel as you wish.
Make initial RAM disk
Generate initramfs image file
You are free to name the initramfs image file whatever you wish when generating it. However, it is recommended to use the linux<major_revision><minor_revision>
convention. For example, the name ’linux514’ was given as ‘5’ is the major revision and ‘14’ is the minor revision of the 5.14 kernel. This convention will make it easier to maintain multiple kernels, regularly use mkinitcpio, and build third-party modules.
Copy System.map file
The System.map
file is not required for booting Linux. It is a type of “phone directory” list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses.
Copy System.map
to /boot
, appending your kernel’s name to the destination file. Then create a symlink from /boot/System.map
to point to /boot/System.map-<kernel_name>
:
Summary
After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot
directory along with any other previously existing files:
- Kernel:
vmlinuz-<kernel_name>
- Initramfs:
Initramfs-<kernel_name>.img
- System Map:
System.map-<kernel_name>
- System Map kernel symlink