2016-04-09

Install Full Kernel Source on Debian

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".

If "Can't drop privileges for downloading as file ... by user '_apt'. - pkgAcquire::Run (13: 13: Permission denied)." happens, please check owner & group of current directory.



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.