All Products
Search
Document Center

Alibaba Cloud Linux:Modify and build Alibaba Cloud Linux kernel RPM packages

Last Updated:Jun 03, 2026

Build custom Alibaba Cloud Linux kernel RPM packages to enable or disable specific kernel features. This topic describes how to modify kernel source code and rebuild RPM packages in a Docker container on an ECS instance.

Prerequisites

An ECS instance that runs Alibaba Cloud Linux. For more information, see Create an instance with Custom Launch.

  • Image: Alibaba Cloud Linux 2 or Alibaba Cloud Linux 3.

  • Instance type: 32 vCPUs or more recommended.

    Note

    Kernel builds are resource-intensive. Use an instance with 32 or more vCPUs to reduce build time.

Step 1: Prepare the environment

  1. Connect to your ECS instance.

    For more information, see Log on to a Linux instance using Workbench.

  2. Download the Docker image and start the container.

    #Install Docker.
    sudo yum install -y docker
    #Pull a Docker image.
    sudo docker pull <image_url>
    #Start the Docker container.
    sudo docker run -itd --net host --name alinux-build <image_url> bash
    #Access the Docker container.
    sudo docker exec -it alinux-build bash

    Replace <image_url> with the URL for your Alibaba Cloud Linux version.

    Image

    Docker image URL

    Alibaba Cloud Linux 2

    alibaba-cloud-linux-2-registry.cn-hangzhou.cr.aliyuncs.com/alinux2/alinux2

    Alibaba Cloud Linux 3

    alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3

    This example uses the Docker image for Alibaba Cloud Linux 3.

    sudo yum install -y docker
    sudo docker pull alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3
    sudo docker run -itd --net host --name alinux-build alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3 bash
    sudo docker exec -it alinux-build bash

Step 2: Download the source code

Download and install the source RPM package.

# Download the source code package.
yum install -y wget
wget <rpm_url>/<src.rpm_name>
# Install the source code package.
rpm -ivh <src.rpm_name>

This example downloads the kernel-5.10.134-13.1.al8.src.rpm package for Alibaba Cloud Linux 3.

yum install -y wget
wget https://mirrors.aliyun.com/alinux/3/plus/source/SRPMS/kernels/kernel-5.10.134-13.1.al8.src.rpm
rpm -ivh kernel-5.10.134-13.1.al8.src.rpm

The files are installed to the /root/rpmbuild directory. Run ls /root/rpmbuild to verify:

image

Step 3: Modify the source code

  1. Install build dependencies.

    yum install -y rpm-build yum-utils
    yum-builddep -y <src.rpm_name>

    Replace <src.rpm_name> with your source RPM package name. Example: kernel-5.10.134-13.1.al8.src.rpm.

    yum install -y rpm-build yum-utils
    yum-builddep -y kernel-5.10.134-13.1.al8.src.rpm
  2. Extract the source package.

    # Enter the source code directory.
    cd /root/rpmbuild/SOURCES
    # Decompress the source code package.
    tar xf <Name of the compressed source code package>

    In this example, <source_archive_name> is linux-5.10.134-13.1.al8.tar.xz.

    cd /root/rpmbuild/SOURCES
    tar xf linux-5.10.134-13.1.al8.tar.xz
  3. Go to the extracted directory.

    cd <Name of the decompressed source code package>

    In this example, <extracted_source_directory_name> is linux-5.10.134-13.1.al8.

    cd linux-5.10.134-13.1.al8
  4. (Optional) Modify the configuration files.

    You can modify the source code or a config file. The following steps show how to modify a config file.

    1. List the available configuration files.

      ls /root/rpmbuild/SOURCES

      image

      The /root/rpmbuild/SOURCES directory contains four config files.

      config file

      Description

      kernel-5.10.134-aarch64.config

      Arm architecture, release version.

      kernel-5.10.134-aarch64-debug.config

      Arm architecture, debug version. For testing only.

      kernel-5.10.134-x86_64.config

      x86 architecture, release version.

      kernel-5.10.134-x86_64-debug.config

      x86 architecture, debug version. For testing only.

      Select the file that matches your architecture. You can modify both platforms if needed.

    2. Modify the configuration file.

      This example uses the kernel-5.10.134-x86_64.config file for the x86 architecture.

      1. Copy the configuration file to the source directory.

        cd /root/rpmbuild/SOURCES
        cp kernel-5.10.134-x86_64.config linux-5.10.134-13.1.al8/.config
      2. Go to the source directory.

        cd linux-5.10.134-13.1.al8
      3. Apply default values for any new configuration options.

        make olddefconfig
      4. Use make menuconfig to modify kernel options. This handles configuration dependencies automatically.

        make menuconfig

        In the menuconfig interface, press / to search for options.

        image

      5. Copy the modified configuration back to overwrite the original.

        cp .config ../kernel-5.10.134-x86_64.config
      6. Return to the parent directory.

        cd ..
      Note

      You can use the same method to modify the configuration file for the Arm architecture.

  5. Update the version number in the spec file.

    cd /root/rpmbuild/SPECS
    vi kernel.spec

    Press I to enter Insert mode. When you are finished, press Esc, type :wq, and press Enter to save and exit.

    Versioning recommendations: Update the version number to distinguish your build from official releases. For example:

    • Change a major version like 5.10.134-12 to 5.10.134-12.0.1.

    • Change a minor version like 5.10.134-13.1 to 5.10.134-13.1.1.

    This example updates the version number from 5.10.134-13.1 to 5.10.134-13.1.1.

    In the file, find the %define pkgrelease %{?KREL:%{KREL}}%{?!KREL:13.1} line and update it to %define pkgrelease %{?KREL:%{KREL}}%{?!KREL:13.1.1}.1

    You can also describe your changes in the changelog section of the kernel.spec file. 2

Step 4: Rebuild the RPM packages

  1. Recompress the modified source code.

    In this example, the source directory name is linux-5.10.134-13.1.al8.

    1. Go to the SOURCES directory.

      cd /root/rpmbuild/SOURCES/
    2. Rename the source directory.

      In the previous step, the version number was updated from 5.10.134-13.1 to 5.10.134-13.1.1. Therefore, rename the source directory to linux-5.10.134-13.1.1.al8.

      mv linux-5.10.134-13.1.al8 linux-5.10.134-13.1.1.al8
    3. Recompress the directory into a tarball.

      tar cJf linux-5.10.134-13.1.1.al8.tar.xz linux-5.10.134-13.1.1.al8
    4. Remove the original source directory and the old tarball.

      rm -rf linux-5.10.134-13.1.al8
      rm -f linux-5.10.134-13.1.al8.tar.xz
  2. Rebuild the source RPM package.

    cd /root
    rpmbuild -bs rpmbuild/SPECS/kernel.spec

    The output shows the rebuilt package location: /root/rpmbuild/SRPMS/kernel-5.10.134-13.1.1.al8.src.rpm.

    image

  3. (Optional) Downgrade the dwarves package.

    If your installed source RPM kernel version is 5.10.134-13.1.al8 or earlier, the build requires dwarves-1.22-1.al8 to prevent errors.

    yum downgrade dwarves-1.22-1.al8 -y
  4. Rebuild the RPM packages.

    rpmbuild --rebuild /root/rpmbuild/SRPMS/<src.rpm_name>

    Replace <src.rpm_name> with your modified source RPM package name. Example: kernel-5.10.134-13.1.1.al8.src.rpm.

    rpmbuild --rebuild /root/rpmbuild/SRPMS/kernel-5.10.134-13.1.1.al8.src.rpm

    The build takes significant time. The following output indicates success. 1