From time to time it's required to compile some Linux kernel specific software on your CentOS/RedHat Linux system. Most often it's some kind of kernel module specific to a software that requires deep integration with your operating system.
Install Kernel Sources and Headers in RedHat/CentOS
You need to install two packages: kernel sources from kernel-develop and header files from kernel-headers:
root@centos:~ # yum install kernel-devel kernel-headers Loaded plugins: fastestmirror, langpacks Determining fastest mirrors epel/x86_64/metalink | 28 kB 00:00:00 * base: centos.quelquesmots.fr * epel: mirror.in2p3.fr * extras: centos.crazyfrogs.org * updates: centos.quelquesmots.fr base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): epel/x86_64/updateinfo | 998 kB 00:00:00 (2/4): extras/7/x86_64/primary_db | 201 kB 00:00:00 (3/4): updates/7/x86_64/primary_db | 5.0 MB 00:00:00 (4/4): epel/x86_64/primary_db | 6.7 MB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package kernel-devel.x86_64 0:3.10.0-957.12.2.el7 will be installed ---> Package kernel-headers.x86_64 0:3.10.0-957.12.2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================ Package Arch Version Repository Size ============================================================================ Installing: kernel-devel x86_64 3.10.0-957.12.2.el7 updates 17 M kernel-headers x86_64 3.10.0-957.12.2.el7 updates 8.0 M Transaction Summary ============================================================================ Install 2 Packages Total download size: 25 M Installed size: 41 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/2): kernel-headers-3.10.0-957.12.2.el7.x86_64.rpm | 8.0 MB 00:00:00 (2/2): kernel-devel-3.10.0-957.12.2.el7.x86_64.rpm | 17 MB 00:00:00 ------------------------------------------------------------------------------------------------------------------------ Total 55 MB/s | 25 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : kernel-devel-3.10.0-957.12.2.el7.x86_64 1/2 Installing : kernel-headers-3.10.0-957.12.2.el7.x86_64 2/2 Verifying : kernel-headers-3.10.0-957.12.2.el7.x86_64 1/2 Verifying : kernel-devel-3.10.0-957.12.2.el7.x86_64 2/2 Installed: kernel-devel.x86_64 0:3.10.0-957.12.2.el7 kernel-headers.x86_64 0:3.10.0-957.12.2.el7 Complete!
I just realised that the same packages will most obviously be needed if you ever decide to compile your Linux kernel.
Why Kernel Source is Old Version in Your OS
Most Linux distros lag quite a big behing the latest Linux kernel version: this is expected, because their maintainers need time to download and complile the latest kernel and to also complete the full suite of integratory tests. This is done so that most of key software running in a particular distro will still function. Quite possibly, lots of kernel modules specific to a distro are re-compiled at that stage.
What this means is that your Linux distro will not have the latest branch of Kernel sources (5.1 as of May 2019). In this example today, my CentOS 7.6 system is using and downloading Linux Kernel 3.10.0.
Verify If You Have Kernel Sources Installed
Simply look in the /usr/src/kernels directory: you will at least have the just-installed packages but quite possibly older versions as well:
root@s2:~ # ls /usr/src/kernels/
3.10.0-957.12.2.el7.x86_64
root@s2:~ # ls /usr/src/kernels/3.10.0-957.12.2.el7.x86_64/
arch drivers include Kconfig Makefile Module.symvers scripts System.map virt
block firmware init kernel Makefile.qlock net security tools vmlinux.id
crypto fs ipc lib mm samples sound usr
That's quite a bit of source codes:
root@s2:~ # du -sh /usr/src/kernels/3.10.0-957.12.2.el7.x86_64 74M /usr/src/kernels/3.10.0-957.12.2.el7.x86_64
See Also
- Linux Kernel
- Official Linux Kernel website: Kernel.org
- Red Hat Linux
Leave a Reply