Hi, today we are going to compile Linux kernel. you can think that compiling kernel is very complicated and hard for you. But it is not. It is more easy to compile than a lot of other projects. Because Linux kernel has no dependency to a library or other tools. It needs just ncurses development library which is used for module configuration.
Download Linux Kernel Source Code
Linux Kernel is an open-source project which is can be used anyone without any fee and freely. Linux Kernel source code is provided by http://www.kernel.org . First we will download the latest mainline kernel source code.
$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.4.tar.xz
Extract Linux Kernel
Then decompress it. The postfix of file like xz, gz is not important they are just different compression algorithms all ingredients are the same
$ tar xvf linux-3.16-rc4.tar.xz
Enter the decompress directory
$ cd linux-3.16-rc4/
Run module configuration menu for the kernel. Here you need ncurses devel library for C programming language.
Ubuntu, Debian, Mint, Kali
$ sudo apt install bison libncurses-dev flex
Fedora, CentOS, RedHat
$ sudo yum install ncurses-devel.x86_64 bison flex
Kernel Build Configuration
We will run the kernel configuration tool with the following command.
$ make menuconfig
You can configure the file system module from here. If you have space constraint you can remove unneeded file system modules or add required file system modules
Here are driver modules. As I said above you can remove unneeded modules or add drivers you need.
Virtualization modules can be configured with this menu. Say you have AMD CPU you do not have to compile Intel drivers.
After applying all settings you can save them and exit
Now we are ready to compile process. There is a lot of compile options but I am gonna show you some of them. If you want to see all off them run make help
$ make help
Compiling Linux Kernel As ISO Image
We can compile the Linux Kernel with the
isoimage option which will make ISO files to boot the kernel. This ISO can be burned into a CD too.
$ make -j8 isoimage
After compilation, you can find your image in arch/x86/boot/image.iso
Compile Linux As Binary
Linux kernel can be compiled with the
make command. By providing the
-j8 compilation will be done in a multi-threat way.
$ make -j8
Install Linux Kernel
We can install compiled Linux kernel like below. This will change the current kernel of the Linux distribution and boot next time with this kernel.
$ make install
1 thought on “How To Compile Linux Kernel From Source Code?”