- How to Install Kernel Headers in Ubuntu and Debian
- Install Kernel Headers in Ubuntu and Debian
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to install kernel headers on Debian
- Installing kernel headers on Debian 11:
- What is the Linux kernel?
- What are Linux Kernel Headers?
- Conclusion:
- About the author
- David Adams
- How to Install Kernel Headers in CentOS 7
- Install Kernel Headers in CentOS 7
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- ChapterВ 4.В Common kernel-related tasks
- 4.1.В Obtaining the Debian kernel source
- 4.2.В Rebuilding official Debian kernel packages
- 4.2.1.В Preparation
- 4.2.1.1.В Disk space requirements
- 4.2.2.В Simple patching and building
- 4.2.3.В Applying patches or configuration changes
- 4.2.4.В Building many packages
- 4.2.5.В Building packages for one flavour
- 4.3.В Building a development version of the Debian kernel package
- 4.4.В Generating orig tarball from newer upstream
- 4.5.В Building a custom kernel from Debian kernel source
- 4.6.В Building a custom kernel from the «pristine» kernel source
- 4.7.В Building out-of-tree kernel modules
How to Install Kernel Headers in Ubuntu and Debian
In our last article, we have explained how to install kernel headers in CentOS 7. Kernel Headers contain the C header files for the Linux kernel, which offers the various function and structure definitions required when compiling any code that interfaces with the kernel, such as kernel modules or device drivers and some user programs.
It is very important to note that the kernel headers package you install should match with the currently installed kernel version on your system. If your kernel version ships with the default distribution installation or you have upgraded your Kernel using dpkg or apt package manager from the Ubuntu or Debian base repositories, then you must install matching kernel headers using package manager only. And if you’ve compiled kernel from sources, you must also install kernel headers from sources.
In this article, we will explain how to install Kernel Headers in Ubuntu and Debian Linux distributions using default package manager.
Install Kernel Headers in Ubuntu and Debian
First check your installed kernel version as well as kernel header package that matches your kernel version using following commands.
Check Kernel Version and Kernel Headers in Ubuntu
On Debian, Ubuntu and their derivatives, all kernel header files can be found under /usr/src directory. You can check if the matching kernel headers for your kernel version are already installed on your system using the following command.
Check Kernel Headers in Ubuntu
From the above output, it’s clear that the matching kernel header directory doesn’t exist, meaning the package is not yet installed.
Before you can install the appropriate kernel headers, update your packages index, in order to grab information about the latest package releases, using the following command.
Then run the following command that follows to install the Linux Kernel headers package for your kernel version.
Install Kernel Headers in Ubuntu
Next, check if the matching kernel headers have been installed on your system using the following command
Verify Installed Kernel Headers in Ubuntu
That’s all! In this article, we have explained how to install kernel headers in Ubuntu and Debian Linux and other distributions in the Debian family tree.
Always keep in mind that to compile a kernel module, you will need the Linux kernel headers. If you have any quires, or thoughts to share, use the comment form below to reach us.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
How to install kernel headers on Debian
All instructions in this tutorial are also useful for other Debian-based Linux distributions such as Ubuntu.
Installing kernel headers on Debian 11:
First, update the information on your software using apt, as shown in the example below.
Check for available Linux kernel headers by running the following command.
For a different simple way to list available headers, run the command below.
To install the Linux kernel headers, run the command shown in the screenshot below.
Using Debian 11 x64 or using the second method to find the header, you can also run the following command.
In my case, the headers were installed in the previous example, so the output says it’s already properly installed.
What is the Linux kernel?
Some experts say the kernel is the core component of an Operating System; others disagree and say the kernel is not part of the OS but a vital component needed by any OS. The function of the kernel is to manage the device resources for them to interact with the operating system and applications. We can think about the kernel as a translator allowing communication between the hardware and the software. In order to manage resources properly, the kernel has full privileges. In some cases, the installed kernel may lack the proper code to allow the hardware and software interaction; that’s when we need to install kernel headers.
What are Linux Kernel Headers?
Linux kernel headers are components usually used to compile drivers and loadable modules adding support to the kernel. For this purpose, kernel headers include C headers with functions and structures needed to compile modules. Thanks to kernel headers, modules or drivers can interact with the kernel. It is important to clarify the kernel headers are part of the kernel, despite being distributed separately.
Dealing with kernel headers is easier than dealing with whole kernel sources. If you are looking for drivers for a device, you’ll use kernel headers, while to rebuild the whole kernel, you will need whole kernel sources. By default, some Linux distributions, including Debian, include the kernel headers to be used if needed (this tutorial assumes you discarded or removed the headers). If all your hardware works properly, you probably won’t need to deal with kernel headers.
Conclusion:
As you can see, installing Linux kernel headers on Debian or Ubuntu is pretty easy. Any Linux-level user should know the function of kernel headers and how to install them. Users must pay attention to the kernel headers they download that are compatible with their system, not only the architecture but also the version.
Thank you for reading this tutorial explaining how to install kernel headers on Debian. Keep following Linux Hint for additional Linux tips and tutorials.
About the author
David Adams
David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.
How to Install Kernel Headers in CentOS 7
When you compile a custom kernel module such as a device driver on a CentOS system, you need to have kernel header files installed on the system, which include the C header files for the Linux kernel. Kernel header files provide different kinds of function and structure definitions required when installing or compiling any code that interfaces with the kernel.
When you install Kernel Headers, make sure it matches with the currently installed kernel version on the system. If your Kernel version comes with the default distribution installation or you have upgraded your Kernel using yum package manager from system base repositories, then you must install matching kernel headers using package manager only. If you’ve compiled Kernel from sources, you can install kernel headers from sources only.
In this article, we will explain how to install Kernel Headers in CentOS/RHEL 7 and Fedora distributions using default package manager.
Install Kernel Headers in CentOS 7
First confirm that the matching kernel headers are already installed under /usr/src/kernels/ location on your system using following commands.
Check Kernel Headers in CentOS 7
If no matching kernel headers are located in the /usr/src/kernels/ directory, go ahead and install kernel headers, which is provided by the kernel-devel package that can be installed using default package manager as shown.
Install Kernel Headers in CentOS 7
After installing the kernel-devel package, you can find all the kernel headers files in /usr/src/kernels directory using following command.
Note on a VPS (for instance a Linode VPS), a kernel may have a customized version name, in such scenario, you have to identify the kernel version manually and check the installed kernel header files using following commands.
Check Kernel Version in CentOS 7
Sample Output
In addition, if you need header files for the Linux kernel for use by glibc, install the kernel-header package using following command.
Now you are good to go with compiling your own or existing kernel modules for software such as VirtualBox and many more.
That’s it! In this article, we have explained how to install kernel-devel and kernel-header packages in CentOS/RHEL 7 and Fedora systems. Remember that before you can compile kernel modules such as device driver on a Linux system, you should have necessary kernel header files installed. If you have queries, please use the comment form below to reach us.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
ChapterВ 4.В Common kernel-related tasks
Table of Contents
4.1.В Obtaining the Debian kernel source
To get the Debian kernel source at the current maximum patchlevel, it is sufficient to install the latest linux-source- version package and unpack the source, for example:
The unpacked source tree then will be available in linux-source-4.3 directory.
4.2.В Rebuilding official Debian kernel packages
You can build all or selected kernel packages by following these instructions. You may be asked to do this in order to test a potential bug fix.
4.2.1.В Preparation
Run the following commands:
This will install the packages required by the kernel build process.
$ apt-get source linux
This will download and unpack the linux source package, making the tree available in the linux- version directory. As always, the revision part of the version of this package (for example, 1 in 3.2.19-1) will determine its patchlevel with respect to the original upstream kernel source.
Enter the source directory.
4.2.1.1.В Disk space requirements
Building binary packages for a single kernel flavour requires up to 15В GB space in the package directory and 300В MB in /tmp (or $TMPDIR ).
Building with debug info disabled requires about 2В GB and 25В MB respectively. You can disable debug info by changing the value of debug-info to false in debian/config/defines (or debian/config/ arch /defines in older package versions).
Building all binary packages for i386 or amd64 currently requires about 50В GB space in the package directory. Other architectures with fewer drivers will require less space.
4.2.2.В Simple patching and building
The source package includes a script to simplify the process of building with extra patches. You can use this by running commands such as:
This script has options to control the flavour, featureset, etc. For a summary of the options, run:
However, if you need to change the configuration or make other changes, you should not use this script and should follow the instructions below.
4.2.3.В Applying patches or configuration changes
It is possible to apply extra patches to the source before starting the build. In the linux source package, the default (non-featureset) patches are automatically applied in the top level directory.
The patched source appears in the following directories.
source with featureset:
You should apply the extra patches in the appropriate directory. In the linux source package you can use the quilt utility to do this.
To change the configuration before building, for example for the 686-pae flavour on i386, run the commands:
If the patches or configuration changes alter type definitions for the kernel, you may need to change the ABI name; see Section 5.2.1, “The ABI name”.
4.2.4.В Building many packages
To build all possible packages for this architecture, run:
To build all architecture-dependent packages, run:
To build all architecture-independent packages, run:
4.2.5.В Building packages for one flavour
For example, to build only the binary packages for 686-pae flavour on i386 architecture, use the following commands:
The target in this command has the general form of target _ arch _ featureset _ flavour . Replace the featureset with none if you do not want any of the extra featuresets. This command will build the linux image and kernel headers packages. You may also need the linux-headers- version -common binary package, which can be built using the commands:
The target in this command has the general form of target _ arch _ featureset _ real
4.3.В Building a development version of the Debian kernel package
To build a kernel image based on the kernel team’s unreleased development version:
The last two commands will install the build dependencies required by the kernel build process.
$ git clone -b dist —single-branch https://salsa.debian.org/kernel-team/linux.git
This will check out the Debian packaging. dist is normally the distribution codename such as wheezy or sid (unstable). For the very latest version, usually based on an upstream release candidate, use master . Note that this will download several hundred megabytes of data.
$ apt-get source -d linux
This will download the linux upstream source (and the last released Debian patches). Depending on which version you are trying to build, you might need to override APT’s version selection or download a tarball from people.debian.org instead.
This unpacks the upstream source and merges it with the Debian packaging.
This generates a Debian package control file based on the current definitions of the various kernel flavours which can be built.
$ fakeroot debian/rules target
4.4.В Generating orig tarball from newer upstream
First you must add a changelog entry for the new upstream version. If the new version is a release candidate, change the string -rc to
rc . (In Debian package versions, a suffix beginning with
indicates a pre-release.)
The ‘orig’ tarball is generated by the genorig.py script. It takes either a tarball and optional patch from kernel.org, or a git repository. First ensure you have the necessary tools installed:
Then if you have a tarball, run a command such as:
Or if you have a git repository, pass the name of its directory:
Either of these will generate a file such as ../orig/linux_3.5
rc1.orig.tar.xz . You can then combine this tarball with the Debian packaging by running:
4.5.В Building a custom kernel from Debian kernel source
This section describes the simplest possible procedure to build a custom kernel the «Debian way». It is assumed that user is somewhat familiar with kernel configuration and build process. If that’s not the case, it is recommended to consult the kernel documentation and many excellent online resources dedicated to it.
The easiest way to build a custom kernel (the kernel with the configuration different from the one used in the official packages) from the Debian kernel source is to use the linux-source package and the make deb-pkg target. First, prepare the kernel tree:
The kernel now needs to be configured, that is you have to set the kernel options and select the drivers which are going to be included, either as built-in, or as external modules.
It is possible to reuse an old configuration file by placing it as a .config file in the top-level directory. Alternately, you can use the default configuration for the architecture ( make defconfig ) or generate a configuration based on the running kernel and the currently loaded modules ( make localmodconfig ).
If you reuse a Debian kernel config file, you may need to disable module signing ( scripts/config —disable MODULE_SIG ) or enable signing with an ephemeral key ( scripts/config —set-str MODULE_SIG_KEY certs/signing_key.pem ). The build will use less time and disk space (see SectionВ 4.2.1.1, “Disk space requirements”) if debug information is disabled ( scripts/config —disable DEBUG_INFO ). Debuginfo is only needed if you plan to use binary object tools like crash, kgdb, and SystemTap on the kernel.
The kernel build infrastructure offers a number of targets, which invoke different configuration frontends. For example, one can use console-based menu configuration by invoking the command
Instead of nconfig one can use oldconfig (text-based line-by-line configuration frontend) or xconfig (graphical configuration frontend). Note that different frontends may require different additional libraries and utilities to be installed to function properly. For example, the nconfig frontend requires the ncurses library, which at time of writing is provided by the libncurses5-dev package.
After the configuration process is finished, the new or updated kernel configuration will be stored in .config file in the top-level directory. The build is started using the commands
As a result of the build, a custom kernel package linux-image-3.2.19_3.2.19-1_i386.deb (name will reflect the version of the kernel and build number) will be created in the directory one level above the top of the tree. It may be installed using dpkg just as any other package:
This command will unpack the kernel, generate the initrd if necessary (see ChapterВ 7, Managing the initial ramfs (initramfs) archive for details), and configure the bootloader to make the newly installed kernel the default one. If this command completed without any problems, you can reboot using the
command to boot the new kernel.
For much more information about bootloaders and their configuration please check their documentation, which can be accessed using the commands man lilo , man lilo.conf , man grub , and so on. You can also look for documentation in the /usr/share/doc/ package directories, with package being the name of the package involved.
4.6.В Building a custom kernel from the «pristine» kernel source
Building a kernel from the «pristine» (also sometimes called «vanilla») kernel source, distributed from www.kernel.org and its mirrors, may be occasionally useful for debugging or in the situations when a newer kernel version is desired. The procedure differs only in obtaining the kernel source: instead of unpacking the kernel source from Debian packages, the «pristine» source is downloaded using your favourite browser or using wget, as follows:
The integrity of the downloaded archive may be verified by fetching the corresponding cryptographic signature
and running this command ( gnupg package must be installed):
Successful verification results in output similar to the one below:
After that the archive may be unpacked using
The unpacked kernel tree (in linux-4.3 ) can now be configured and built, in the same way described in the previous section.
4.7.В Building out-of-tree kernel modules
Some kernel modules are not included in the upstream or Debian kernel source, but are provided as third-party source packages. For some of the most popular out-of-tree modules, the binary Debian packages with modules built against the stock Debian kernels are provided. For example, if you are running stock Debian kernel 3.2.0-2-686-pae (use the uname -r command to verify the version) from the linux-image-3.2.0-2-686-pae package, and would like to use the squash filesystem, all you need to do is install squashfs-modules-3.2.0-2-686-pae binary package, which provides the necessary binary kernel modules.
If you are not so lucky, and there are no binary module packages in the archive, there is a fair chance that the Debian archive contains the packaged source for the kernel modules. Names of such packages typically end in -source , for example squashfs-source , thinkpad-source , rt2x00-source and many others. These packages contain debianized source code of the kernel modules, suitable for building using the module-assistant (or m-a ) script from the module-assistant package. Typical sequence to build a custom binary module package, matching a kernel 3.2.0-2-686-pae (as returned by uname -r ) from the debianized source consists of the following steps:
Install a set of kernel headers, matching the kernel for which the modules are going to be built:
Install the package containing the source:
Invoke module-assistant (aka m-a ) to do the heavy lifting:
As a result, a Debian package is going to be built and placed in /usr/src . It can be installed the usual way, using dpkg -i . Two last steps (building and installation) may be combined using the invocation
Check out the module-assistant documentation ( man module-assistant ) for other options and much more information on how to use it.
Finally, in some rare circumstances, you might need to build the kernel modules from the upstream source packages. In that case, follow the documentation included with the package to build the modules. If the build process will require you to specify the directory with the kernel headers, matching the currently running kernel, for stock Debian kernels this directory is /usr/src/linux-headers- uname , provided by the linux-headers- uname package. Here uname is the output of the uname -r command. If you are building and running your own custom kernels, it is a good idea to keep the original build tree around, as it also can be used for out-of-tree module building.