Last updated November 11, 2022 at 08:25 AM
In this tutorial we will apprendre how to compile and update your linux kernel on Ubuntu.
This tutorial is based on my favorite linux distro. This is Ubuntu 16.04 LTS which I'm really lazy to change. So how have I survived the updates since its release in April 2016 (almost 5 years already)?
You will find out here in this tutorial.
[bctt tweet=”Linux kernel – How to compile and update it on Ubuntu – tutorial” username=”tedidevblog”]
Compiling the linux kernel
By repeating the process of building and installing linux kernel, I ended up developing a script that will allow us to go faster.
The shell script will allow us to automatically install the libraries we need and assist us in the process of compiling and installing the Linux kernel.
To start we will proceed with the compilation.
- Create a folder in which you will work
This folder can have any name. This will just avoid having the files scattered around our Office.
- Created the kernel_compilation.sh file
Footnotes: We just chose the name by convention. You can change it as long as you remember it when running the script.
You will copy this shell script and paste it into the file kernel_compilation.sh.
#bin/bash sudo apt-get install bison git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache flex libelf-dev echo "go to the kernel in $1"; cd $1; echo ""; echo "kernel config"; make oldconfig; make menuconfig; echo ""; echo "kernel compilation...go to chat..."; make all; echo "modules compiling...almost finished"; make modules;
Once done, save and close your file. The next step is the downloading from the linux kernel.
- Download and unzip the linux kernel in the same folder as the script
You will find the latest version of the linux kernel on the kernel.org site.
The kernels you find are often much newer than those shipped with the distributions. ubuntu by default (even after an update).
We recommend downloading kernels that have [ stable ] next to them. The reason is that it contains the latest bugs fixed until the next mainstream kernel [main stream ].
- Rename the folder extracted from the kernel to "linux"
- Run the kernel_compilation.sh script
Before running our script, we should first make it executable.
-
- Open your terminal from your working folder and run this script
chmod + x kernel_compilation.sh
-
- Now we are ready to run our linux kernel compilation script.
sudo ./kernel_compilation.sh ./linux
Note: You will probably have to enter your administrator password to complete the execution of the script. So be careful.
- Kernel configuration
In the terminal, the system will ask you to answer some questions to configure the new kernel features to compile.
Appuyez Starter to keep the kernel parameters to override. This would be ideal to be sure that your linux distro (ubuntu in our case) will work without compatibility issues.
I recommend it especially when you have no knowledge of what you are being asked to configure.
You will come to an interface like this after several Starter :
Don't change absolutely nothing unless you know what you're doing. Use the arrows on your keyboard then press exit with the button Starter
I have already played around with the kernel configurations and found a lot of interesting things there. Like google modules and functions that can turn the kernel into a wifi router.
This part is ideal if you want to configure the kernel for systems other than your own. Like for example embedded systems.
If you find the window below, press again Exit
- Compilation
Finally it is the long-awaited phase. After leaving the previous window, the program will start compiling your new linux kernel.
During this time, try to take a break or keep busy. The compilation took a few hours at my place.
Installing the linux kernel
The compilation of source code of the linux kernel took about 1 hour for us. Now it's time to move on to the process.
We are going to create another script that will allow us to easily install the linux kernel. We will resume the script creation process.
- Created the kernel_installation.sh file
With your favorite text editor, create the file kernel_installation.sh with the following script as content:
# bin / bash echo "installation in $ 1"; cd $ 1; echo ""; echo "installation modules"; sudo make modules_install install; echo ""; echo "kernel installation"; sudo make install; echo "update grub"; sudo update-grub; # sudo update-grub2; echo "finish";
Footnotes: You may have noticed that we put the line of code “ sudo update-grub 2 ” in the comments. In the original script this portion of code is not commented.
We did this while writing this tutorial because there is no difference between “ sudo update-grub "And" sudo update-grub 2 ” and especially to avoid replacing the new kernel by itself.
Which will take up unnecessary space.
After saving the file with the previous shell script, we will run it.
- Run the kernel_installation.sh script
To execute the script file, we are going to chain two commands which consist in making the file executable and executing it.
-
- Open your terminal from your working folder and run this following script:
chmod + x kernel_installation.sh; ./kernel_installation.sh linux
Note: You will probably have to enter your administrator password to complete the execution of the script. So be careful.
Linux is the folder where we compiled the kernel. Your terminal will look like the image below:
Once the installation is complete, you can restart your computer to test your new kernel. It is the kernel that will launch by default for your ubuntu.
Last updated November 11, 2022 at 08:25 AM