Hello Everyone
I am here again with another interesting topic for technology enthusiastic community. From where exactly we can configure our Linux kernel as per our need, How to build our custom kernel once configuration is over and how to install our new kernel so that our Ubuntu uses new configured kernel.
Happy learning!
I am here again with another interesting topic for technology enthusiastic community. From where exactly we can configure our Linux kernel as per our need, How to build our custom kernel once configuration is over and how to install our new kernel so that our Ubuntu uses new configured kernel.
Procedure:
Step
1: Getting the dependencies:
abhi@vb:~$ sudo apt install install git build-essential kernel-package fakeroot
libncurses5-dev libssl-dev ccache git bison flex libelf-dev libncursesw5-dev
Step 2: Update the existing system:
abhi@vb:~$
sudo apt update
abhi@vb:~$
sudo apt upgrade
abhi@vb:~$
sudo apt dist-upgrade
Step
3: Getting
the Kernel Source
abhi@vb:~$
uname -r
4.4.0-124-generic
abhi@vb:~$
mkdir kernelbuild
abhi@vb:~$
cd kernelbuild/
abhi@vb:~$
git clone -b linux-4.11.y
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
abhi@vb:~$
cd linux-stable/
abhi@vb:~$
cp /boot/config-`uname -r` .config
abhi@vb:~$
yes '' | make oldconfig
abhi@vb:~$
make menuconfig
You
can configure your kernel as per requirement, where you can add some
features, select a particilar driver and remove few features, as
needed. Select
the option that you want and hit the Space bar. The Space bar cycles
between “M,” “*,” and empty. “M” signifies that the
feature will be built as a module that will be loaded if needed when
Ubuntu starts. “*” means that the feature will be built into the
kernel and always loaded. The script does not include blank options
in the final product.
When
you’re done setting things up, clean the directory.
abhi@vb:~/kernelbuild/linux-stable$
make clean
Now
your kernel is ready to build.
Step 4: Building Kernel Packages
abhi@vb:~/kernelbuild/linux-stable$
make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-custom
All
that line does is compile the kernel into .deb packages using the
amount of CPU cores on your system plus one. It also adds on “custom”
to the end of the package version to differentiate your custom kernel
from others.
It
takes 4-5 Hours to compile kernel on Core i3 processor with 8 GB RAM.
Step
5: Installing the Kernel
You’ll
find your new kernel packages one directory up. They’ll be easily
identifiable by their version number. You can use “dpkg” to
install them.
abhi@vb:~/kernelbuild/linux-stable$
cd ..
abhi@vb:~/kernelbuild$
sudo dpkg -i
linux-firmware-image-4.11.12-custom_4.11.12-custom-1_amd64.deb
abhi@vb:~/kernelbuild$ sudo dpkg -i linux-libc-dev_4.11.1-custom-1_amd64.deb
abhi@vb:~/kernelbuild$ sudo dpkg -i linux-headers-4.11.1-custom_4.11.1-custom-1_amd64.deb
abhi@vb:~/kernelbuild$ sudo dpkg -i linux-image-4.11.1-custom-dbg_4.11.1-custom-1_amd64.deb
abhi@vb:~/kernelbuild$ sudo dpkg -i linux-image-4.11.1-custom_4.11.1-custom-1_amd64.deb
When
the installation finishes, restart your computer. Ubuntu will
automatically boot into your new kernel. You can double-check that it
did by runing “uname -r” in a terminal when it starts up. If you
see your version, congratulations! You’re running your own custom
kernel.
abhi@vb:~$
uname -r
4.11.12-custom
Hope you enjoyed updating your kernel and learnt lot in this process.Happy learning!