Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Kali Linux Kernel Source: Where to Find and Build It

· 6 min read · Home Tech

In this article
  1. Where Kali’s kernel source comes from
  2. Get source with APT
  3. Clone the Kali kernel packaging repository
  4. Build, configure, or modify a kernel
  5. Common source and build problems
  6. Upstream Linux source versus Kali source
  7. Frequently Asked Questions

Kali Linux’s kernel source is maintained in Kali’s Git repositories and is also available through its configured APT source repositories. For most users, the simplest route is to install the matching source package with APT; developers can clone the Kali kernel packaging repository to inspect or modify how Kali builds its kernels.

Where Kali’s kernel source comes from

Kali is based on Debian, but it maintains its own packages and kernel builds for its security-focused distribution. The Linux kernel itself is an upstream project; Kali’s kernel packages combine a particular upstream kernel version with Debian and Kali packaging changes, configuration, and patches. Consequently, “the Kali kernel source” can mean either the upstream Linux source or the complete packaging repository used to produce Kali’s kernel packages.

The Kali Linux development team publishes its kernel packaging work on the official Kali GitLab instance. The project is commonly named kernel and is available at https://gitlab.com/kalilinux/packages/kernel. Check the project’s current branches and instructions before building: the branch and build details can change as Kali updates its kernel.

For the source corresponding to an installed kernel, APT is usually more reliable than selecting a random branch from GitLab. Kernel versions and package names change over time, and a source package should match the binary package you intend to study or rebuild.

Get source with APT

First check which kernel is running and which kernel package is installed:

  • Run uname -r to display the running kernel’s release string.
  • Run dpkg -l 'linux-image*' to inspect installed Linux image packages.
  • Use apt-cache search linux-source to see source packages available from your configured repositories.

On a current Kali installation, you can install the available kernel source package with:

sudo apt update
sudo apt install linux-source

APT places the source archive under /usr/src, commonly as a compressed tar archive. The exact package version and filename depend on the repositories enabled and the packages currently published. List the directory with ls /usr/src, then extract the archive using an appropriate tool, such as tar -xf for a tar archive.

If you need the source package for a specific installed kernel rather than the newest source package offered by APT, identify the corresponding package version and check whether that version is still available in your configured repositories. Kali is a rolling distribution, so an older version may no longer be offered on the active branch. Avoid assuming that a package called linux-source will always contain source identical to every installed kernel image.

Clone the Kali kernel packaging repository

To examine Kali’s build packaging or contribute changes, clone the official repository:

git clone https://gitlab.com/kalilinux/packages/kernel.git

The repository contains Debian-style packaging files and build instructions, and may include patches or configuration relevant to Kali’s kernel packages. It is not necessarily a ready-to-use copy of the complete upstream Linux source tree: packaging can fetch or refer to upstream source separately. Read the project’s README and packaging metadata, and select the branch or revision appropriate to the version you are investigating.

For reproducible investigation, record the Git commit, package version, and kernel release you use. A repository’s default branch typically moves forward; checking out a specific tag or commit helps ensure that your notes and build refer to a stable point in the project’s history.

Build, configure, or modify a kernel

Obtaining source does not by itself install a kernel or change the one your system boots. Building a kernel requires development tools, the appropriate source and configuration, and enough disk space and time. Kali’s packaging workflow is generally preferable when your goal is to produce a Kali-style package, because it incorporates the distribution’s packaging conventions.

For package builds, consult the repository’s current instructions and install the build dependencies it specifies. Debian packaging tools commonly used in such workflows include dpkg-buildpackage and apt build-dep, but the precise commands depend on the checked-out packaging version and repository configuration. Do not copy build commands from an unrelated kernel version without checking their instructions.

If you only need to compile an external kernel module, you may not need the full kernel source tree. Install headers matching the running kernel, commonly with:

sudo apt install linux-headers-$(uname -r)

Headers provide the interfaces and build files needed by many out-of-tree modules; they are not a substitute for the complete kernel source when you want to read or modify kernel implementation code. If APT cannot find the exact headers package, verify that the system is updated and that the repository has a package for the running kernel.

Common source and build problems

  • “Unable to locate package linux-source”: Check that Kali’s official repositories are configured correctly, run sudo apt update, and search with apt-cache search linux-source. Package availability can vary by release and repository state.
  • Source and kernel versions do not match: Compare package versions rather than relying only on a broad kernel version number. A newer source package may not reproduce an older installed kernel.
  • Headers are missing: Kernel headers are version-specific. Check uname -r and install headers for that release if they are available.
  • A custom kernel will not boot: Keep a known-working kernel installed and available in the boot menu. Confirm the new package’s configuration and initramfs before removing old kernels.
  • Secure Boot rejects a custom kernel or module: Secure Boot policies may require signing and enrolling a key. The exact procedure depends on the machine’s firmware and configuration.

Kernel experiments can make a machine temporarily unbootable, especially if storage, filesystem, or boot configuration support is omitted. Back up important data and test changes on a disposable virtual machine when practical.

Upstream Linux source versus Kali source

The official upstream Linux source is hosted by the Linux kernel project, including the repository at https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git. It is the right reference for general kernel development and upstream history. Kali’s packaging repository is more relevant when you want to understand how Kali adapts, configures, and packages its kernel.

These sources are related but not interchangeable. A plain upstream checkout may lack Kali’s packaging metadata and distribution-specific changes. Conversely, a Kali packaging repository may point to a particular upstream release rather than containing every source file directly. Choose based on the question you are asking: upstream behavior, Kali’s build process, or the exact source associated with a particular package.

Frequently Asked Questions

Is Kali Linux kernel source code free?
Yes. Linux kernel source is distributed under the GNU General Public License, version 2, and Kali publishes its kernel packaging work publicly. Individual components may have their own licensing terms, so check the license files for the specific source you use.

Where is the Kali kernel source directory after installation?
Installing the linux-source package generally places a compressed source archive in /usr/src. You must extract it to work with the files as a directory.

Does uname -r tell me which source package to install?
It identifies the running kernel release, not necessarily the exact APT source package name or version. Use it alongside installed-package information from dpkg and APT’s available package list.

Do I need full source to build a Wi-Fi or other kernel module?
Often, no. Many external modules build against matching kernel headers. Full source is mainly needed when the module’s instructions require it or when you are changing kernel code itself.

Can I use Ubuntu or Debian kernel source on Kali?
You can inspect or experiment with other distributions’ source, but it may not match Kali’s kernel version, configuration, patches, or packaging. For a Kali system, start with Kali’s repositories and documentation unless you have a specific reason to use another source.