How To Compile Linux Kernel From Source Code?
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 other projects. Because Linux kernel has no dependency to library or other tools. It needs just ncurses development library which is used for module configuration. Lets start the process.
Download Linux Kernel Source Code
Linux Kernel is a open source project which is can be used any one without any fee and freely. Linux Kernel source code is provided by http://www.kernel.org . First we will download 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 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 kernel configuration tool with the following command.
$ make menuconfig
You can configure file system module from here. If you have space constraint you can remove unneeded file system modules or add required file system modules
Here is 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 compile with the
make command. By providing the
-j8 compilation will done in multi threat way.
$ make -j8
Install Linux Kernel
We can install compiled Linux kernel like below
$ make install