How to Build Linux Kernel

How to Build Linux Kernel

- 3 mins

Introduction

In this guide , I will build a kernel and also I will Update the Bootloader for using my own kernel.


Prerequisites

1- A system running Linux / I will use Debian buster VM 2- 12GB of available space on the hard drive

Download the Source Code

So We will start with choosing a existing kernel and We will modify it. We can find current kernel verisons in kernel.org and dowload the lastest kernle version. The file is compressed source code of kernel. I will use kernel 6.8.7 which is latest kernel on 04/26/2024.

1- Visit the link and chekc kernel versions.

kernel

2- We decided our kernel version so , We need to download it to our VM , We can use wget to dowload kernel.

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.8.7.tar.xz

kernel

3- The output shows the “saved” message when the download completes.

Extract the Source Code

1- Since We have compressed file as .tar, We should extact the file.

2- Run the tar command to extract the source code

tar xvf linux-6.8.7.tar.xz

kernel

Install Required Packages

1- Before building new kernel We need to install required packages You can install any package you want to add to the new kernel.

2- Let’s use apt for installing reiqured packages.

apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison -y

3- If You want to know What the packages do, You can check the below:

kernel

Configure Kernel

1- The Linux kernel source code comes with the default configuration. However, You can adjust it to your needs.

2- Change your directory to kernel’s folder.

cd linux-6.8.7

3- Copy the existing Linux config file using the cp command

cp -v /boot/config-$(uname -r) .config

kernel

4- To make changes to the configuration file, We should run make menu config.

make menuconfig

5- The command launches several scripts that open the configuration menu.

kernel

6- The configuration menu includes options such as firmware, file system, network, and memory settings. Use the arrows to make a selection or choose Help to learn more about the options. When you finish making the changes, select Save, and then exit the menu.

kernel

kernel

kernel

7- You may change your configureation and sanve it. I just click save to show you but I did not do any change on my configuration.

Build the Kernel

1- We are ready to build our kernel after We done configuration of new kernel.

2- Start building the kernel by running make command

make

3- The process of building and compiling the Linux kernel may takes time.

4- The terminal lists all Linux kernel components: memory management, hardware device drivers, filesystem drivers, network drivers, and process management.

kernel

6- Install the required modules after build completed.

make install

7- Once is done You will see done output on the terminal.

Update the Bootloader

1- We successfully builded new kernel. We can test it with changing our grub bootloader.

2- The GRUB bootloader is the first program that runs when the system powers on.

3- The make install command performs this process automatically, but you can also do it manually.

4- Update the initramfs to the installed kernel version.

update-initramfs -c -k 6.8.7

5- Update the GRUB bootloader.

update-grub

6- The terminal prints out the process and confirmation message

Reboot and Verify Kernel Version

1- When you complete the steps above, reboot the machine. When the system boots up, verify the kernel version using the uname command.

uname -mrs




:+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1:


Guneycan Sanli.


Guneycan Sanli

Guneycan Sanli

A person who like learning, music, travelling and sports.

comments powered by Disqus