How To Download, Compile and Install Custom Linux Kernel Manually In Ubuntu, Debian, Mint, Kali, CentOS?
Linux is a Operating System kernel and user space applications will create different distributions like CentOS, Ubuntu, Mint, Kali around this kernel. Kernel can be downloaded freely and used without any license fee. In this tutorial we will learn how to download Linux Kernel from kernel.org and compiling with GCC . An the last step installing or upgrading the kernel.
Download Kernel Source Code
Kernel source code is originally maintained in the kernel.org . But there are a lot of mirrors which serve to download the kernel source code. In this step we will download kernel source code by using
wget command like below. Current stable version of the Linux Kernel is
$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.6.tar.xz
Install GCC and Other Requirements
GCC is most popular compiler for C and C++ source codes in Linux environment. We will use GCC in order to compile and create binaries for Linux Kernel . We will install
gcc with the following command for different distributions.
Ubunt, Debian, Mint, Kali:
$ sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
$ sudo yum install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
Extract Kernel Source Code
Kernel source code has a lot of text type data which may take a lot of disk space and bandwith. So Linux Kernel code is distributed in compressed formats like
tar.gz etc. We download Kernel Source code as
xz so we need to extract source code with the
tar command like below.
$ tar xvf linux-4.17.6.tar.xz
Create Compile Configuration
We will create a configuration which will used to compile required modules and kernel features.
$ make menuconfig
Compile Linux Kernel Source Code with GCC and Make
We will use
make command wich will run compile process according to the configuration we have created with the
make menuconfig command.
Compile Linux Kernel Faster
By default make command will make compile with a single thread . But as modern CPU’s have multiple cores which gives ability to use multiple threads we can run parallel compile with
-j option of the
make command. In this case we specify 4 threads
$ make -j 4