[Linux] Configure the system to start the kernel version by default

View the default boot kernel

insert image description here
This is a command line used in Linux systems through which the user can view and edit the GRUB2 boot loader environment variables. The specific meaning is as follows:

  • saved_entry=6752e052c66d4923aeeb3f42f123175e-4.18.0-348.7.1.el8_5.x86_64: The default startup entry currently set is ID "6752e052c66d4923aeeb3f42f123175e-4.18.0-348.7. 1.el8_5.x86_64" kernel image.
  • kernelopts=root=/dev/mapper/cl-root ro crashkernel=auto console=ttyS1,115200n8 printk.time=1 pci=hpiosize=0 ignore_loglevel resume=/dev/mapper/cl-swap iommu=pt rd.lvm.lv =cl/root rd.lvm.lv=cl/swap rhgb quiet memmap=32G$0x2050000000,1M$0x100000: Kernel startup parameters include root file system, kernel log printing level, PCI bus related settings, sleep wakeup and other configurations.
  • boot_success=0: The last successful boot flag, 0 means boot failure.
  • boot_indeterminate=0: The flag bit of the unknown boot state, 0 means that the boot state has been determined.

List the kernels available on the system

menuentry is the entry to start.
According to the listed content, it should not be BIOS boot boot, it may be UEFI
insert image description here

Configuration file description

insert image description hereIn the Linux system, GRUB (GNU GRand Unified Bootloader) is a commonly used bootloader for loading the operating system. GRUB provides several different configuration files, including:

  • /boot/grub2/grub.cfg: GRUB's main configuration file, used to define the content and style of the boot menu.
  • /boot/grub2/grub2-efi.cfg: EFI version configuration file of GRUB, used to define the boot menu of UEFI system.
  • /boot/grub2/grubenv: GRUB environment variable file, used to store some system configuration information, such as default boot items, timeout, etc.

Therefore, /boot/grub2/grub.cfg and /boot/grub2/grub2-efi.cfg are both GRUB configuration files, but they are used to boot BIOS and UEFI systems respectively. If your system is in BIOS boot mode, GRUB will use the /boot/grub2/grub.cfg file; if it is UEFI boot mode, GRUB will use the /boot/grub2/grub2-efi.cfg file.

Determine whether to boot from BIOS or UEFI

To determine whether the system boots using UEFI or BIOS, the following command can be used:

$ ls /sys/firmware/efi

If the command returns a directory listing, the system is UEFI booted. If the command returns "No such file or directory" or a similar error message, the system is booted using BIOS.

In addition, you can also check the hardware information of the system to determine whether the system uses UEFI or BIOS to boot. If your computer is new, it's most likely booted with UEFI; if your computer is older, it's most likely booted with BIOS.
insert image description here

How to modify the boot method of UEFI

insert image description here
When you find that this is the case in the configuration file, you need to change the next-entry to 1 or the number you want. The number can be seen at startup, and the number starts from 0 in order.

explain parameters

GRUB next_entryvariables are set in the GRUB environment variable file. By default, this file is located in /boot/grub2/grubenv.

When you select a different boot entry in the GRUB menu, GRUB stores the number of the selected boot entry in next_entrya variable . Then, when the computer restarts, GRUB will automatically load the variable and use set default="${next_entry}"the command to set the default boot entry to the boot entry number stored in the variable.

However, if you want to revert to the default set default="${next_entry}", you need to set default=1change to set default="${next_entry}". After modification, the contents of this ifblock will be executed according to the default behavior.

It is also possible to directly modify the parameters, but the main UUID value
insert image description here
is not recommended to directly modify the contents of /boot/grub2/grubenvthe file , because this file contains GRUB environment variables, not GRUB configuration files. If you modify this file directly, it may cause GRUB to fail to boot.

If you want to modify the default startup items, you can modify the GRUB configuration file according to the previous answer. If you want to modify the kernel boot parameters, you can follow the steps below:

  1. Open GRUB's configuration file:
sudo vi /etc/default/grub
  1. Find GRUB_CMDLINE_LINUXthe variable and add your desired kernel boot parameters after it. For example, if you want to add nomodeseta parameter , modify the variable to:
GRUB_CMDLINE_LINUX="rhgb quiet nomodeset"
  1. Save the file and exit the editor.

  2. Update GRUB's configuration file:

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

This command will regenerate GRUB's configuration file and include the added kernel boot parameters.

  1. Restart the computer, and you will see that the kernel boot parameters have been modified to the parameters you added.

Note that before editing GRUB's configuration file, be sure to back up the file in case something unexpected happens.

another way

There is no next_enty variable in my configuration environment variable, so I directly modify the else branch.
This file is /etc/default/grubautomatically generated here. etc/default/grub
insert image description hereAfter modifying here to save the changes, run to update the GRUB configuration file: sudo grub2-mkconfig -o /boot/efi/EFI /fedora/grub.cfg (Please replace the path according to the system and distribution)

Reboot the computer and see if the specified kernel version was successfully used

insert image description here

Guess you like

Origin blog.csdn.net/qq_21688871/article/details/130699118