Rate This Document
Findability
Accuracy
Completeness
Readability

OS Kernel Source Code Compilation

  1. Query the current kernel version and OS image source.
    [root@localhost ~]# uname -a
    Linux localhost.localdomain 4.14.0-115.el7a.0.1.aarch64 #1 SMP Sun Nov 25 20:54:21 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux
    [root@localhost ~]# cat /etc/os-release
    NAME="CentOS Linux"
    VERSION="7 (AltArch)"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="7"
    PRETTY_NAME="CentOS Linux 7 (AltArch)"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:centos:centos:7"
    HOME_URL="https://www.centos.org/"
    BUG_REPORT_URL="https://bugs.centos.org/"
    
    CENTOS_MANTISBT_PROJECT="CentOS-7"
    CENTOS_MANTISBT_PROJECT_VERSION="7"
    REDHAT_SUPPORT_PRODUCT="centos"
    REDHAT_SUPPORT_PRODUCT_VERSION="7"

    The current OS vendor is CentOS-7. Kernel version: 4.14.0-115.el7a.0.1

  2. Download the RPM package kernel-alt-4.14.0-115.el7a.0.1.src.rpm from http://vault.centos.org/7.6.1810/os/Source/SPackages/.
  3. Before compiling the kernel, install the basic tools for compiling the kernel.
    If the following error is displayed:
    1
    2
    3
    4
    5
    error: Failed build dependencies:
            xmlto is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64
            asciidoc is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64
            newt-devel is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64
            pciutils-devel is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64
    

    Run the following command to solve the problem:

    1
    yum install –y xmlto  asciidoc newt-devel pciutils-devel
    

    Required tools:

    1
    2
    3
    sudo yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmlto
    sudo yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel
    sudo yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel
    
  4. Before compilation, ensure that the mockbuild user and the group to which the mockbuild user belongs are valid.
    1
    2
    groupadd mockbuild
    useradd mockbuild -g mockbuild
    
  5. Install the RPM package. The RPM package is actually an rpmbuild project.
    1
    rpm -ivh kernel-alt-4.14.0-115.el7a.0.1.src.rpm
    

    After the installation is complete, the rpmbuild project is automatically deployed in the following directories:

    /root/rpmbuild/SPECS

    /root/rpmbuild/SOURCES

  6. Perform RPM build. Full kernel code (including patches) is automatically downloaded.
    1
    2
    cd /root/rpmbuild/SPECS
    rpmbuild -bp --target=$(uname -m) kernel-alt.spec
    
  7. After the build is complete, obtain the full kernel source code from the following path:
    1
    cd  /root/rpmbuild/BUILD/kernel-alt-4.14.0-115.el7a/linux-4.14.0-115.el7.0.1.aarch64
    
  8. Compile the kernel.
    1
    make -j 64
    
  9. (Optional) Install the driver.
    1
    make modules_install
    
  10. (Optional) Install the kernel.
    1
    make install
    
  11. (Optional) Restart the server and select the corresponding kernel.