Wednesday, April 29, 2015

Building a Custom Debian Kernel

Introduction

This entry is about building a custom Debian kernel. I've never done this before and I have some need for it. The instructions I'm basing this on are found at:

https://www.debian.org/releases/stable/i386/ch08s06.html.en

I'm not sure if this is a good place to start; it's what this article is based upon. You must have root privileges

What Kernel am I using?

The current kernel can be found simply by querying:

> uname -r

This returned back:

3.2.0-4-amd64

There are several ways to query the version of the kernel. I found them at the following website:

http://www.linfo.org/find_kernel_version.html

Command Line

> sudo apt-get install fakeroot
> sudo apt-get install  kernel-package
> sudo apt-get install linux-source-2.6
> sudo apt-get install ncurses-dev
> cd ~
> mkdir kernel
> cp /usr/src/linux-source-*.tar.bz2 .
> cd kernel
> make menuconfig
> make-kpkg clean
> fakeroot make-kpkg --initrd --revision=1.0 kernel_image
> sudo dpkg -i ../linux-image-3.2.65_1.0_amd64.deb
> sudo shutdown -r now


After a reboot, if you do the following you should now see the updated kernel version:


> uname -r

Now it returned back:

3.2.65

Interesting that it did not return back the architecture.

fakeroot

From what I can gather about fakeroot, its primary purpose is to allow non-root users a way to produce files that have "root permissions/ownership" [3]. Essentially it gets rid of the requirement that the developer building the kernel needs to be root to build files with root ownership.

kernel-package

If make-kpkg is missing then kernel-package has not been installed.

linux-source-2.6

This is the source code for the kernel. When installing this package, it will pull down the source code into /usr/src/linux-source-X.X.tar.bz2. The sequence of commands above shows that we copy the tarball into a local directory called "kernel".

make menuconfig

This step is pretty cool because it allows the developer to customize what features to enable/disable and which files should be built in versus built into modules. Doing it this way requires that ncurses be installed (see the installation lines for details). It's a pretty self-explanatory user interface.


REFERENCES

[1] https://www.debian.org/releases/stable/i386/ch08s06.html.en

[2] http://www.linfo.org/find_kernel_version.html

[3] http://unix.stackexchange.com/questions/9714/what-is-the-need-for-fakeroot-command-in-linux