Detailed process for compiling the latest kernel version v7.0.9 on openEuler 24.03 SP3

Detailed Process for Compiling the Latest Kernel Version v7.0.9 on openEuler 24.03 SP3

1. System Environment

The openEuler 24.03 SP3 system already has the UKUI graphical interface installed. Now, install the required compilation dependencies as needed.

dnf groupinstall -y "Development Tools"
dnf install -y rpm-build openssl-devel bc rsync gcc gcc-c++ flex bison m4 elfutils-libelf-devel
dnf install -y ncurses-devel elfutils-libelf-devel bc openssl-devel bison flex

2. Download, Compile, and Install the Kernel

  1. Download and Extract the Kernel
cd /opt
wget https://mirrors.nju.edu.cn/kernel.org/linux/kernel/v7.x/linux-7.0.9.tar.gz
tar -zxvf linux-7.0.9.tar.gz
  1. Enter the Kernel Directory
cd linux-7.0.9
  1. Configure Kernel Options

Reusing the current system configuration and making minor adjustments ensures the new kernel includes all necessary drivers and features from the current system, simplifying customization.

  • Reuse current configuration: Copy the configuration file of the currently running kernel into the source directory as the base configuration.
cp /boot/config-$(uname -r) .config
sed -i 's|CONFIG_SYSTEM_TRUSTED_KEYS=.*|CONFIG_SYSTEM_TRUSTED_KEYS=""|' .config
sed -i 's|CONFIG_SYSTEM_EXTRA_CERTIFICATE=.*|CONFIG_SYSTEM_EXTRA_CERTIFICATE=""|' .config
  • Run make olddefconfig to apply the configuration changes. This step is essential to avoid compilation errors.
  1. Compile the Kernel

After configuration, start the compilation process. The -j$(nproc) parameter uses all available CPU cores for parallel compilation, significantly speeding up the process.

make -j$(nproc)

Note: The compilation process may take from half an hour to several hours. If an error occurs during compilation, try removing the -j parameter to get clearer error messages for debugging.

  1. Install Kernel and Modules

After successful compilation, install the kernel image, modules, and other files to the system directories.

  • Install kernel modules to /lib/modules/:
sudo make modules_install
  • Install kernel files (e.g., vmlinuz, System.map) to /boot, and automatically update the GRUB configuration:
sudo make install
  • Copy the .config file to /boot for future reference:
cp .config /boot/config-7.0.9

After running sudo make install, the system automatically:

  • Copies the kernel image to /boot
  • Generates the corresponding initramfs
  • Adds a new boot entry for the kernel in the GRUB boot menu
  1. Update Boot Configuration and Reboot for Validation

Manually update GRUB to ensure the new configuration takes effect, then reboot the system to load the new kernel.

sudo grubby --set-default-index=0

Update GRUB Configuration:

  • For UEFI systems, the GRUB configuration file is typically located at /boot/efi/EFI/openEuler/grub.cfg. If unsure, check the actual directory name under /boot/efi/EFI/.

Replace the path with your actual GRUB configuration file path:

sudo grub2-mkconfig -o /boot/efi/EFI/openEuler/grub.cfg

For traditional BIOS systems, use:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot the system:

sudo reboot

After rebooting, select the newly compiled 7.0.9 kernel from the GRUB boot menu.

Login and Verify:
Once logged in, run the following command. If the output is 7.0.9, the new kernel is successfully running.

uname -r

In openEuler, to set the newly compiled kernel as the default boot option, the core idea is to make GRUB2 aware of the new kernel and designate it as the default boot entry.

Here are three methods of varying complexity. Choose the one that best fits your needs.

:wrench: Method 1: Using the grubby Command (Simplest and Most Efficient)

This is the recommended default method — direct, safe, and requires no manual handling of kernel filenames.

  1. Confirm the New Kernel Is in the Boot List
    After installation, check the index number of the new kernel in the GRUB menu. Index numbers start from 0.
grubby --info=ALL | grep -E "^index|^title"

The output will clearly list each boot entry with its index and corresponding kernel version.

  1. Set the New Kernel as Default
    Find the index of the new kernel (e.g., 0), then run:
sudo grubby --set-default-index=0
  1. Verify and Reboot
    Confirm the default entry was set correctly, then reboot:
grubby --default-index
sudo reboot