Building a custom kernel

In this tutorial I am going to show how to make a custom kernel. While I use a distribution coming from the Debian family the process of making a kernel remains quite similar in other distributions until the final step. For further details consult the manuals of your distribution. The steps below are done inside a terminal client.

1. Installing the needed programs for kernel compilation as a root or a sudo.

sudo apt-get install fakeroot build-essential kernel-package devscripts ncurses-dev

2. Settings the folder permissions correctly. You can of course use some local folder in your home directory but personally I have always found /usr/src useful since it eliminates some common dangers of accidentally deleting the kernel sources.

cd /usr/src

sudo su

sudo chown -hR tester /usr/src

The above line sets the permissions of the folder in such a fashion that a normal user can modify the content without sudo or root rights. This step is needed because we use fakeroot program to make our new kernel. If a root account would be used to compile the new kernel it could lead to system errors resulting from malfunctional (and too powerful) build-time rights.

After the steps above you should exit sudo or root mode before continuing any further.

3. Getting the kernel sources (We will be downloading the long-term kernel).


4. Decompress the kernel sources and start customizing them.

tar xvfJ linux-3.12.21.tar.xz

Wait a moment while the archive gets decompressed.

cd linux-3.12.21

ln -s linux-3.12.21 linux

You could omit the step above as it only creates a link folder called linux inside /usr/src. The advantage is that by doing this step you can cd into kernel sources by going to /usr/src/linux instead of typing /usr/src/linux-3.12.21

cp /boot/config-`uname -r` ./.config

Copy our current kernel’s config file. You can and probably should use it as a template.

make menuconfig

Configure the kernel with menuconfig program.


The choices I made during my trials are marked with # (for example: #disabled or #enabled).

Enable the block layer –> support for large 2tb+ block devices and files  #disabled.

Processor type and features –>Toshiba laptop support     #disabled (if you do not own Toshiba).

Processor type and features –>Dell laptop support     #disabled ( if you do not own Dell).

Processor type and features –>memtest      #disabled.

Processor type and features –>Processor family–> Pentium 4. #Check your processor type to optimize performance.

Processor type and features –>Preemption Model–> Low latency. desktop      #This option should produce better efficiency.

Processor type and features –>Processor family–> Timer frequency 1000hz.     #Use all of your computer’s speed and power.

Processor type and features –>Processor family–> kexec system call disabled.     #Disabled if you are not using kexec-tools. If you do not know what kexec is you can probably disable this.

Networking support –> Amateur Radio support  #disabled.

The case of Wireless

The most common problem that goes around and pops up in almost every kernel discussion seems to relate to enabling wireless networking devices. When you compile your kernel do make
sure that you wireless device is actually enabled before you start building things. For example, I enabled atheros devices via menuconfig so that my Wlan was able to get the drivers
it needed to get itself working correctly.

Device drivers –> Network device support –> Wireless Lan #Check options for Wlan.

Further tweaks

Device Drivers –> Accessibility support     #disabled.

Device drivers –> block devices: normal floppy disk support  #disabled. Enable this if you are still using floppy disks.

Device drivers input device support –> tablets     #disabled.
Device drivers input device support –> touchscreens     #disabled.

Kernel hacking –> Kernel debugging  #disabled. You would need debugging in kernel development.

Virtualization  #disabled. Enable if you are going to run an operation system virtually within your operation system.

64 bit kernel #disable if you do not need one.

5. Building the kernel

make-kpkg clean

Up to this step everything remains quite universal among Linux distributions. However the final command below is Debian family specific as it creates .deb packages.

fakeroot make-kpkg –initrd –append-to-version=-686 – -revision=3.12.21 kernel_image kernel_headers

There should be no space between – –

Additional notes.

Installing modules afterwards: for example NVIDIA non-free modules (install nvidia-kernel package first).

sudo apt-get install module-assistant
sudo m-a a i

and select Nvidia options from the menus that open.

Tip. Your customized kernel .config file should be found inside your /usr/src/linux directory as a hidden  file. You can copy it for further usage.