Build Debian Kernel Packages with make deb-pkg
Compiling a custom Linux kernel for Debian-based systems was
historically a tedious process involving external scripts and manual
packaging configurations. The upstream Linux kernel build system solves
this by integrating the make deb-pkg target, which
automates the end-to-end transformation of raw kernel source code into
standard Debian .deb packages. This article explains how
make deb-pkg streamlines the kernel compilation and
packaging workflow, enhances system stability, and integrates natively
with the Debian package management ecosystem.
Native Integration in the Kernel Source
Traditionally, building a custom Debian kernel required external
helper utilities such as make-kpkg (from the deprecated
kernel-package toolset) or complex, manual configurations
of dpkg-buildpackage. In contrast, deb-pkg is
maintained directly inside the upstream Linux kernel source tree within
the Kbuild infrastructure. Because it is natively supported, developers
and system administrators do not need to install specialized external
packaging wrappers. The build system creates a temporary
debian/ directory dynamically, populating control files,
changelogs, and installation rules based on the current kernel
configuration and Git version metadata.
End-to-End Build and Packaging Automation
Executing make deb-pkg combines compilation and package
generation into a single automated step. When run, the command executes
several tasks sequentially:
- Compilation: Compiles the kernel image, device tree
blobs (if applicable), and all enabled kernel modules according to your
.configsettings. - Metadata Generation: Automatically detects system architecture, kernel version tags, and generates appropriate Debian package dependencies.
- Module Installation: Gathers the compiled kernel
modules and system map, staging them within standard system paths
(
/lib/modules/<version>). - Artifact Creation: Generates a complete set of
.debfiles placed in the parent directory of the kernel source tree. These typically include:linux-image-<version>.deb: The runnable kernel binary and associated modules.linux-headers-<version>.deb: Kernel header files required to compile external out-of-tree modules (e.g., DKMS, proprietary graphics drivers, or custom networking drivers).linux-libc-dev.deb: Linux userspace API headers.
Safe Package Lifecycle and Bootloader Integration
Directly installing an unmanaged kernel via make install
copies binaries straight into /boot and
/lib/modules, bypassing Debian's package manager. This can
lead to unmonitored file overrides, difficulty rolling back changes, and
broken dependencies.
Using make deb-pkg packages the build into native Debian
archives. Installing these archives with dpkg -i guarantees
clean integration:
- Post-installation scripts automatically trigger
update-initramfsto generate an appropriate initial RAM disk. - Scripts invoke
update-grubto detect the new kernel and add it as an entry in the GRUB boot menu. - The package manager keeps precise tracking of all files, allowing
complete, clean removals using
apt removeordpkg -rwithout leaving orphaned files in the boot partition.
Accelerated Builds Using
bindeb-pkg
While make deb-pkg builds source packages
(.dsc and .tar.gz) alongside binary packages,
building source packages is often unnecessary for personal or internal
deployments. The kernel build system provides an optimized alternative:
make bindeb-pkg. This target skips the source packaging
phase and only compiles the binary packages, significantly reducing
build times while maintaining identical integration with Debian.