- How to install full kernel source on Debian or Ubuntu
- Install Full Kernel Source on Debian
- Install Full Kernel Source on Ubuntu
- Support Xmodulo
- Debian install linux sources
- Install the Required Packages
- Extracting the Kernel Source
- Configuring the Kernel
- Using your current Debian kernel configuration as a starting point
- Building the Debian Package
- See also
How to install full kernel source on Debian or Ubuntu
Question: I need to download and install a full kernel source tree to compile a custom kernel for my Debian or Ubuntu system. What is a proper way to download full kernel source on Debian or Ubuntu?
Before installing full kernel source on your Linux system, ask yourself whether you really need the full kernel source. If you are trying to compile a kernel module or a custom driver for your kernel, you do not need the full kernel source. You only need to install matching kernel header files, and that’s it.
You need the full kernel source tree only if you want to build a custom kernel after modifying the kernel code in any way and/or tweaking default kernel options.
Here is how to download and install full kernel source tree from Debian or Ubuntu repositories. While you can download the official kernel source code from https://www.kernel.org/pub/linux/kernel/, using distro’s repositories allows you to download a kernel source with the maintainer’s patches applied to it.
Install Full Kernel Source on Debian
Before downloading kernel source, install dpkg-dev , which contains a suite of development tools needed to build Debian source packages. Among other things, dpkg-dev contains dpgk-source tool which can extract a Debian source package and automatically apply patches.
$ sudo apt-get install dpkg-dev
Next, run the following command to download full kernel source.
$ apt-get source linux-image-$(uname -r)
Along with the full kernel source ( linux_X.X.XX.orig.tar.xz ), any available kernel patches ( linux_X.X.X+XXX.debian.tar.xz ) and source control file ( linux_XXXX.dsc ) will also be downloaded and stored in the current directory. The .dsc file instructs how the patches are applied to the kernel sources.
Upon the completion of download, the above command will automatically invoke dpkg-source tool, which will unpack the downloaded kernel source in the current directory, and apply downloaded patches according to .dsc file.
The final full kernel source tree will be available in the current directory as linux-X.X.XX .
Install Full Kernel Source on Ubuntu
If you want to install full kernel source, the Debian way described above should work on Ubuntu as well.
There is another way to download full kernel source on Ubuntu. You can actually check out the kernel source tree maintained by Canonical for different Ubuntu releases.
$ sudo apt-get install git $ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-$(lsb_release --codename | cut -f2).git
For example, if you are using Ubuntu 14.04, the above command will check out code from » ubuntu-trusty » Git repository.
Once you check out the Git repository, use the following command to install necessary development packages to meet the build dependencies for the kernel source tree.
$ sudo apt-get build-dep linux-image-$(uname -r)
Support Xmodulo
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Debian install linux sources
This is an obsolete now guide on how to build the Linux Kernel into a .deb package. Don’t use this, or take with a grain of salt. Instead, see https://kernel-team.pages.debian.net/kernel-handbook/ch-common-tasks.html#s-common-official
Install the Required Packages
- build-essential — Essential packages required for compiling.
- linux-source — The Linux Kernel Source
- libncurses5-dev — Development files for ncurses5. Optional for using curses based menu driven configuration.
- sudo apt-get install build-essential linux-source bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison
Extracting the Kernel Source
Under /usr/src you will find a file looking like linux-source-x.x.tar.xz. Please note that x.x will match the current Linux Kernel source for your release of Debian. In this example we will be using the 4.15 Kernel under Sid.
Configuring the Kernel
Using your current Debian kernel configuration as a starting point
Alternatively, you can use the configuration from a Debian-built kernel that you already have installed by copying the /boot/config-* file to .config and then running make oldconfig to only answer new questions.
If you do this, ensure that you modify the configuration to set:
CONFIG_SYSTEM_TRUSTED_KEYS = ""
otherwise the build may fail:
make[4]: *** No rule to make target 'debian/certs/test-signing-certs.pem', needed by 'certs/x509_certificate_list'. Stop. make[4]: *** Waiting for unfinished jobs.
Building the Debian Package
This will take quite some time and it’s worth noting that it doesn’t necessarily have to be done on the target machine (or even the target architecture, search in your engine of choice for kernel cross-compiling if you want to set it up). Choosing your most powerful machine may reduce the time of this operation from many hours to under 1.
It’s also worth noting that if you’re using not much of a deviation from the default configuration that ships with debian, you’ll need upwards of about 7GB or so of space to do this operation.
The first one will replace your current default menulist item in grub upon installation. This means that if you install it then next time you reboot, you’ll boot into that kernel.
The second are debug symbols for the first. This is useful if say, you want to do kernel debugging. It’s worth noting that when extracted the debug symbols are about 5GB.
See also
The «Compiling a Kernel» section in the Debian Administrator’s Guide (WARNING: outdated)