How to modify configuration files to enable booting with a newly compiled kernel in openEuler 25.09?

How to Modify Configuration Files to Boot the Newly Compiled Kernel on openEuler 25.09?

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

There are three methods of varying complexity—choose the one that best fits your needs.


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

This method is direct, safe, and recommended as the default approach. It modifies the GRUB configuration automatically without requiring you to know the exact kernel filenames.

  1. Verify the New Kernel Is in the Boot List
    After installing the new kernel, first check its index number in the GRUB menu. Index numbers start from 0.

    grubby --info=ALL | grep -E "^index|^title"
    

    The output will clearly list each boot entry’s index and corresponding kernel version.

  2. Set the New Kernel as Default
    Find the index of the new kernel (e.g., 0) and run the following command:

    sudo grubby --set-default-index=0
    
  3. Verify and Reboot
    Confirm the default has been set correctly, then reboot the system.

    grubby --default-index
    sudo reboot
    

Method 2: Editing the /etc/default/grub Configuration File (Most Universal)

This method is more general and suitable for users familiar with configuration files who want greater customization.

  1. Edit the Main Configuration File
    Use vim or nano to edit /etc/default/grub:

    sudo vim /etc/default/grub
    
  2. Modify the GRUB_DEFAULT Parameter

    • Option A (Recommended): Use the Exact Menu Title
      The newly compiled kernel will have a clear title in the GRUB menu. You can find it in the /boot/grub2/grub.cfg file. For example, if the title is 'openEuler (7.0.0) 25.09', set:

      GRUB_DEFAULT='openEuler (7.0.0) 25.09'
      
    • Option B: Use the Menu Item Index
      If you know the index number of the new kernel (counting from 0), you can use it directly. However, using the title is more reliable, as it is unaffected by changes in menu order.

  3. Save and Update GRUB Configuration
    After saving the file, run the following command to apply the changes:

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

    This command regenerates the GRUB configuration file based on your settings.


Method 3: Customizing the 40_custom File (Most Flexible)

Use this method if you want full manual control over the boot menu entries.

  1. Edit the Custom Template
    Edit /etc/grub.d/40_custom with root privileges:

    sudo vim /etc/grub.d/40_custom
    
  2. Add a Custom Boot Entry
    At the end of the file, add a new entry following the format of existing kernel entries. Example:

    menuentry 'My New Compiled Kernel' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt2'  # Adjust according to your actual partition layout
        linux /boot/vmlinuz-7.0.0 root=/dev/mapper/openeuler-root ro quiet
        initrd /boot/initramfs-7.0.0.img
    }
    
    • Replace 'My New Compiled Kernel' with the name you want to appear in the GRUB menu.
    • Critical: Replace vmlinuz-7.0.0 and initramfs-7.0.0.img with the actual filenames of your compiled kernel and initramfs.
    • Adjust set root='hd0,gpt2' and root=/dev/mapper/openeuler-root based on your actual disk and partition layout (use lsblk to verify).
  3. Grant Execution Permission and Update GRUB

    sudo chmod +x /etc/grub.d/40_custom
    sudo grub2-mkconfig -o /boot/grub2/grub.cfg
    

GRUB Configuration File Location

The location of the GRUB configuration file depends on your system’s boot mode:

  • UEFI Mode: Configuration file is typically located at /boot/efi/EFI/openEuler/grub.cfg.
  • Legacy BIOS Mode: Configuration file is typically located at /boot/grub2/grub.cfg.

Regardless of the mode, when using grub2-mkconfig -o, always specify the correct output path. For UEFI systems, the command should be:

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

Summary and Recommendations

  • Use grubby for the most straightforward and efficient way. If you only want the new kernel to boot by default, this is the strongly recommended method.
  • Use grub2-mkconfig for a more traditional and reliable approach. Always remember: if you modify /etc/default/grub, you must run sudo grub2-mkconfig -o <grub.cfg path> for changes to take effect.