If you read this tutorial it's because you are curious about how to compile a Linux kernel.
There is plenty of reasons you might want to learn this procedure.
Even if you are a beginner, you will understand each step for building your first Linux kernel.
To compile a Linux kernel, you have to have a Linux distribution installed on your computer.
So if you don't know how, I recommend to start by using a virtual machine, such as VirtualBox.
And if you want to follow this tutorial, with the same distribution, I'd suggest you install Ubuntu on this virtual machine.
Indeed, using a virtual machine is a safe way to try and fail with no impact on your machine.
OK, we assume now that you have a Ubuntu Linux distribution on your virtual machine.
Let's start by downloading the famous kernel from the official website:
Currently, the last stable is the 4.8.7 version.
It changes quite often, so take the version you want to use (4.8.7 recommended for this tutorial).
Once downloaded, you have to go where there is the file such as:
You are going now to extract it with the following command:
tar xvf linux-4.8.7.tar.xz
You should see all files extracted one by one on your favorite terminal.
You can now enter in the brand new directory linux-4.8.7 that you have just extracted.
We are going to set our kernel with exactly options we want.
So it's a very important step essential to build a kernel.
But, in order to have this command working on Ubuntu, we have to install the ncurses library.
sudo apt-get install ncurses-dev
As these packages don't exist, the apt tool suggests you another package called libncurses5-dev.
So it's exactly the same as if you had typed this:
sudo apt-get install libncurses5-dev
It's up to you, both commands are correct as they do the same process.
Accept to download it by typing Y when the tool asks you to continue.
To have the SSL development libraries:
sudo apt-get install libssl-dev
Here we are.
Now type the following command:
make menuconfig
Once saved, your modifications of the kernel configuration will be written to a specific file:
You can just save the kernel configuration without modifying anything, the resul will be the same, the new .config file will be generated.
You could open this file an see that there are more than 4,000 lines.
So it's quite huge file with a lots of configuration elements.
Do not modify this file by hand, but instead always use the menuconfig.
Because this file will be automatically generated each time you will save a config from the menuconfig, and then overwrite the old .config file.
Once the .config has been generated, it's time to compile the kernel.
The command for that is simply:
make
Then be prepared to at least a few hours of compilation (yeah it takes a very long time), depending of your system.
It wasn't finally such a big deal!
But essential steps have to be respected, that's why this kernel tutorial has to be seen as an Hello World Linux kernel compilation.
The next step will be to understand how to load this Linux image from your bootloader in order to use it.
But it's another story.
Good job, you did it.
Add new comment