Random Bits

Technical Log from Didik Setiawan

Build Custom Linux Kernel

Install Custom Linux Kernel

To build this custom Linux Kernel, I use Ubuntu 14.04 64 bit operating system. At first, ensure all the required utilities installed correctly.

$ sudo apt-get install gcc make git libssl-dev libncurses5-dev

Download source from Linux Kernel Archives, for example, I use version 4.4.

Extract the tarball file.

$ tar xJf linux-4.4.tar.xz
$ cd linux-4.4

We need to change configuration parameters to determine which settings and modules we need to build. Use make *config command as follow. Choose one that match to your favor. I usually use number 2.

1. Use default kernel configuration.

This settings comes from the kernel maintainer.

$ make defconfig

2. Use our existing configuration.

Just press “Enter” when asked for configuration options.

$ make localmodconfig

3. Manual selection with graphical menu.

$ make menuconfig

4. Duplicate our current config.

$ sudo cp /boot/config-`uname -r`* .config

Then, compile source, this process can take a while.

$ make -j4

The parameter “4” is based on processor specification. Set this at your own favor.
Install modules.

$ sudo make modules_install

Bootloader setup.

$ sudo make install

Double check bootloader setup.

$ sudo update-grub2

Reboot the system. We can check our new installed kernel with this command.

$ uname -a

Uninstall Custom Linux Kernel

Find out the version of custom kernel.
Update filesystem search index.

$ sudo updatedb

In this example, I want to remove kernel version 3.16.0-30-generic.

$ CUSTOM_KERNEL_VERSION="3.16.0-30-generic"

Ensure our system has other kernel installed beside $CUSTOM_KERNEL_VERSION.
Then, delete all files & folders which contain $CUSTOM_KERNEL_VERSION name.

$ sudo rm /boot/vmlinuz-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/initrd.img-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/System.map-$CUSTOM_KERNEL_VERSION
$ sudo rm /boot/config-$CUSTOM_KERNEL_VERSION
$ sudo rm -rf /lib/modules/$CUSTOM_KERNEL_VERSION/
$ sudo rm /var/lib/initramfs-tools/$CUSTOM_KERNEL_VERSION

Do some cleaning.

$ sudo update-initramfs -k all -u
$ sudo update-grub2

Finish. Our custom kernel has been uninstalled from our system.