The .deb Packages
This guide is for Debian/Ubuntu only, and only for mainline kernels (not distribution kernels).
After following this guide, you will end up with three .deb packages:
linux-headers-(version)-(arch).debThis package contains all the kernel headers that can be used to compile out-of-tree modules as well as DKMS. On Ubuntu this package corresponds to these two:
linux-image-(version)-(arch).debThis package contains the kernel image (
vmlinuz), as well as all the in-tree modules compiled as modules. When this package is installed, it will also update postinstall scripts, such as refreshing DKMS, initramfs, and Grub bootloader config. On Ubuntu this package corresponds to all of these three:
linux-libc-dev-(version)-(arch).debThis package contains the development headers for user-space modules. Typically this package can be different from the running kernel version as long as the version difference is not that large.
This guide is not for cross compiling: the resulting kernel architecture will be the same as the architecture of the machine that you used to build the kernel. This guide allows the kernel to be compiled in parallel.
If you’re building in Ubuntu, the required dependencies can be installed by the following steps:
apt build-dep linux-image-XXXWhere the
linux-image-XXXis any Linux kernel image available in your repository. For instance, the first entry of the
apt list | fgrep linux-image | fgrep genericcommand will do.
apt install coreutils bison flex libncurses-dev bc rsync kmod cpio libelf-dev libssl-dev lz4
Note that you might need to enable source repositories (
deb-src) to be able to install these packages.
Building the Packages
Now let’s the fun begins! In recent mainline Linux kernel versions, it is very simple to make those aforementioned debian packages. Just follow these steps:
- Download and extract or clone the kernel sources from https://kernel.org (or you can clone using git via
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git).
- Clean the kernel source tree (e.g.
make mrproper, more on this later).
- Configure the kernel. Copy your
.configfile to the source root, or
make -j$(nproc) menuconfig.
make -j$(nproc) deb-pkg.
And that’s it!
For cleaning the source tree, Linux has 3 levels for cleaning:
distclean. Information regarding these options are available right in the
Makefile itself. This is a quote from the Makefile:
Cleaning targets: clean - Remove most generated files but keep the config and enough build support to build external modules mrproper - Remove all generated files + config + various backup files distclean - mrproper + remove editor backup and patch files