How to Build Linux Kernel From Scratch

How-to-Build-Linux-Kernel-From-Scratch

Today I’m going to show you in this article How to Build Linux Kernel From Scratch step-by-step, but Before start lets introduce Linux, Linux Kernel is a free open-source solid, secure, performing operating system kernel project created by Linus Torvald in 1991 for his personal computer after Linux kernel Adopted by GNU Project for create a new free open source (as a free swap) operating system against UNIX proprietary operating system. It has generated plenty of working frameworks, a collection of packages (called distribution OS) simply called Linux.

Today we learn, How to Build Linux Kernel From Scratch Step by Step

Requirements for Build Linux Kernel From Scratch ;

  • A Computer running Linux (Ubuntu, Fedora, OpenSUSE, etc.)
  • A user account with sudo/root privileges
  • 15GB of available space on the hard drive
  • internet connection and enough free time.

Building and Modifying Linux Kernel ;

we are going to walk behind some easy and some bit technical steps to build the kernel and compile, these processes need a lot of time to finish depending on your system performance and speed of compilation.


Note: If the version on the kernel website does not match the one from the steps below, use these commands and replace the kernel version number.

Step 1: Download the Source Code for www.Kernel.org ;

How to Build Linux Kernel From Scratch

Step 2: Open Download folder and Extract Linux-x.xx.tar.xz ;

Step 3: Install Required Packages ;

Install required additional packages for building and compiling a Linux kernel. Run this command:

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

The command we used above installs the following packages:

PackagePackage description
gitTracks and makes a record of all changes during development in the source code. It also allows reverting the changes.
fakerootPackaging tool that makes the fake root environment for building kernel.
build-essentialInstalls development tools such as C, C++, gcc, and g++.
ncurses-devProgramming library that provides API for the text-based terminals.
xz-utilsProvides fast file compression and decompression.
libssl-devSupports SSL and TSL that encrypt data and make the internet connection secure.
bc (Basic Calculator)A mathematical scripting language that supports the interactive execution of statements.
flex (Fast Lexical Analyzer Generator)Generates lexical analyzers that convert characters into tokens.
libelf-devIssues a shared library for managing ELF files (executable files, core dumps and object code)
bisonGNU parser generator that converts grammar description to a C program.
Required-additional-package-install

How to Install Mesa Drivers on Ubuntu 20.04 LTS


Step 4: Configure Kernel ;

1. Navigate to the linux-5.9.6. directory using the cd command:

cd linux-5.9.6

Or Navigate Trough File Manager;

2. Copy the existing configuration file using the cp command:

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

3. To make changes to the configuration file, run the make command:

make menuconfig

4. The configuration menu includes options such as firmware, file system, network adapters, and memory settings, drivers 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-build-window

Note: Changing settings for some options can lead to a non-functional kernel. If you don’t know what to exact change, leave the default settings as it is.


How to Install Mate Desktop on Ubuntu Linux


Step 5: Build the Kernel

1. Start building the kernel by running the following command it takes long time to compile so wait till complete process :

2. Install the required modules with this command:

sudo make modules_install

3. Finally, install the kernel by typing:

sudo make install 

And Finally You Have to Successfully Done to build your custom kernel from scratch.

Conclusion

In these how-tos tutorial guide, we learned how to build a Linux kernel from scratch and install the required packages.

If you follow the instructions and images carefully, the process will complete successfully on your Linux machine. error or any querries use comment section.

5 thoughts on “How to Build Linux Kernel From Scratch”

  1. Nice Article, Im always searching for these and finally found correct informatic article about building and recompiling Linux kernel, thank you

  2. Pingback: How to Fix GSConnect and KDE Connect Connecting issue - LinuxStoney

  3. Pingback: Recovering journal Error on Ubuntu boot up - LinuxStoney

  4. Pingback: How to install Pitivi Video Editor 2021.1 on Ubuntu Linux - LinuxStoney

  5. Pingback: NomadBSD 130R is Now Available to Download Based on FreeBSD 13.0 - itsfoss.net

Leave a Comment

Your email address will not be published. Required fields are marked *