Centos 7.1 get kernel source code
In centos 7.1, the default kernel source code path is/usr/src/uname -r
But it does not contain the source code. It only contains Kconfig and Makefile.
View system kernel version
Uname-r // view the system kernel cat/etc/redhat-release // operating system version
Output result kernel version: 3.10.0-229. el7.x86 _ 64 operating system version: CentOS Linux release 7.1.1503 (Core)
Download the corresponding version of the kernel source code package
Download address http://vault.centos.org/find the corresponding system version, enter for example: 7.1.1503 in the Web http://vault.centos.org/7.1.1503/updates/Source/SPackages/ download the corresponding version kernel source package: kernel-3.10.0-229.20.1.el7.src.rpm
Environment Configuration
1. First install (upgrade) Some Dependent packages
sudo yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmltosudo yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-develsudo yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel bison
2. Create a directory tree for source code compilation.
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
3 install to the compilation directory in the directory where the kernel-3.10.0-229.20.1.el7.src.rpm is located
rpm -i kernel-3.10.0-229.20.1.el7.src.rpm 2>&1 | grep -v existcd ~/rpmbuild/SPECSrpmbuild -bp --target=$(uname -m) kernel.spec
The final kernel source code should be in the directory below
~/rpmbuild/BUILD/kernel-*/linux-*/