Building and Packaging a Custom Linux Kernel on Debian

1. Install Required Packages

Before building a custom kernel, install the necessary build tools:

sudo apt-get install fakeroot kernel-package

For menu-based configuration, install ncurses development headers:

sudo apt-get install libncurses5-dev

2. Obtain the Kernel Source

Download the kernel source using:

apt-get source linux

Alternatively, if you have a tarball:

tar -xvJf linux-3.12.tar.xz
cd linux-3.12

3. Prepare the Kernel Configuration

To reuse your current system configuration:

cp /boot/config-$(uname -r) .config

Then open the configuration interface:

make menuconfig

Here you can enable or disable features, drivers, filesystems, etc.


4. Clean the Build Tree

Before packaging, clean the build environment:

make-kpkg clean

5. Build and Package the Kernel

Set the number of parallel jobs:

export CONCURRENCY_LEVEL=3

Then build the kernel and headers:

fakeroot make-kpkg --append-to-version "-customkernel" --revision "1" \
--initrd kernel_image kernel_headers

Explanation:

  • --append-to-version adds a custom suffix to the kernel version
  • --revision sets the Debian package revision number
  • --initrd generates an initrd image
  • kernel_image builds the kernel .deb package
  • kernel_headers builds the matching header package

After compilation, the generated .deb files will appear in the parent directory.


6. Install the Custom Kernel

Install the generated packages:

sudo dpkg -i linux-image-3.12.0-customkernel_1_i386.deb \
linux-headers-3.12.0-customkernel_1_i386.deb

After installation, update GRUB and reboot into the new kernel.


7. Remove a Non-Working Kernel

If the custom kernel does not boot correctly, you can remove it:

sudo apt-get remove linux-image-(non-working-kernel)

Always keep at least one known working kernel installed as a fallback.


Conclusion

Using make-kpkg simplifies kernel compilation by packaging the build into standard Debian packages. This approach integrates cleanly with the system’s package management, making installation, upgrades, and removal straightforward.

Building a custom kernel not only allows feature customization but also deepens understanding of Linux internals and configuration workflow.

← Previous Post
Next Post →

Leave a Comment