Steps to compiling the Linux kernel

Steps to compiling the Linux kernel

STEP 1: Switch to root user

This is needed because we are working in the /usr/src directory which requires root access

sudo su

STEP 2: Download kernel source code from https://www.kernel.org  and move to /usr/src

This is usually tar.xz or tar.gz file

cd /usr/src 
wget <kernel_download_URL_link>

STEP 3: Extract contents from tar file

For tar.xz:

tar xvf <kernel_download_file>

For tar.gz:

tar xvzf <kernel_download_file>

STEP 4: create symbolic link from /usr/src/<kernel_download_file> /usr/src/linux and change directory to /usr/src/linux

ln -s /usr/src/<kernel_download_file> /usr/src/linux
cd /usr/src/linux

STEP 5: Install Dependencies

apt-get install make
apt-get install libncurses5-dev
apt-get install openssl
apt-get install libssl-dev
apt-get install bc

STEP 6: Customize kernel

You can now customize the kernel, which is pretty much the main reason you might want to compile the kernel.

make menuconfig

This will open a GUI like interface where you can select various aspects of the system to be installed into the kernel [*] , install as kernel module <M> or not install [  ], it looks like this:

STEP 7: The final step is the type make to install the kernel

This will install the kernel, the initramfs and configure grub for you which means you are now done. However, this process takes a long, long time to complete it took about 3-4 hours for me to compile the kernel, but it depends on your system.