Low-level tasks such as the memory, disk, task management, etc are done by the kernel and provide an interface between system hardware components and the user/system processes. A separate protected area of memory is provided for the kernel called Kernel Space and Kernel Space is not available for other applications of the system so that the kernel is safely loaded in this Kernel Space.
Often times you are put up to the task to compile the kernel and there can be a bunch of reasons as to why you can compile the kernel and some of them are:
- Simply want to test how it’s done
- enable/disable certain options of kernel
- Enable hardware support that might not be available in the standard kernel
- Using a distribution for which compiling kernel is required
- Given an assignment in school/college
So in this article, we will install and compile the kernel on Ubuntu 20.04. And without wasting any more time let’s get into it.
Step1: Download Kernel
The first step involves downloading the source code of the Linux kernel from the following link:
Click on the yellow button that says Latest Stable Kernel shown in the above screenshot.
You can also download via command line by executing the below command in your terminal by replacing version 5.14.3 with your latest version:
Step2: Installing requirements
This step involves installing all the requirements for the kernel to compile and can be achieved by executing a single command:
It should be noted that there should be at least 12 GB of free space on your hard drive so that the kernel compilation may take place smoothly.
Step3: Source Extraction
This step involves extracting the downloaded file which can be done by executing with the below command in your Ubuntu terminal:
Let us now change our directory to the newly created directory via the following command:
Step4: Kernel Configuration
Let us now configure our Kernel so that we know which modules to include for which first we have to copy the config file for which execute the following command:
Now that we have copied the config file we can make changes to this file and execute the make menuconfig command which will open up a configuration tool and will show us every module and whether to enable or disable it:
Step5: Compiling Kernel
Now that we are done with configuring Kernel let us start compiling the Kernel for which we will use a single command where the first part will be compiling the kernel with the make command and the second part will be installing the kernel modules. To achieve the second task execute make modules_install. Then comes the third part where make install will copy the Kernel and .config file to the /boot folder hence generating the system. map file.
The above questions involve which kernel you are upgrading from and which kernel you are upgrading to so based on your kernel answer the questions.
The -j option is used to assign more cores to the process so that the process speeds up.
To know the number of cores available, use the “nproc” command:
After knowing the number of cores, you can mention the number cores as shown below to the make command as well:
Let us now install all the modules that you enabled during the step4 for which we will execute the following command:
Step6: Install Kernel
After installing the modules we need to install Kernel by executing the below command:
Step7: Enable Kernel for boot
Once you are done with installing Kernel, then we have to enable Kernel for a boot, for which execute the below command:
Remember to replace the version in the above command with your version of the kernel you just compiled.
The next step is to update-grub for which type or copy the following command in your Ubuntu terminal and then press enter:
Step8: Reboot System
This step involves rebooting your system for which execute the reboot command in your terminal:
Step9: Verification of Linux Kernel
This last step involves verifying the new Linux Kernel version which can be achieved with the following command:
Conclusion
A kernel being the heart of the operating system controls everything that the operating system controls and handles, running processes, and manages hardware devices. The kernel is loaded in the protected Kernel Space and the Kernel remains in the memory of the operating system until the OS is shut down.
We completed our process of compiling and installing Kernel on Ubuntu in this article and hopes that you were successful. If you’re having trouble, go back to the beginning and make sure you’re following each step carefully.