How To change the default kernel in GRUB for RHEL and CentOS » History » Version 1
Viacheslav Anzhiganov, 02/18/2025 08:53 PM
1 | 1 | Viacheslav Anzhiganov | # How To change the default kernel in GRUB for RHEL and CentOS |
---|---|---|---|
2 | |||
3 | This article answers common questions such as “How to set default boot kernel in linux?”, “How to change the default boot entry for kernel?”, “How to boot with old kernel version?” and “How to revert to previous kernel version?”. |
||
4 | |||
5 | GRUB2 is the version of GRUB currently in use, at the time of publishing this article. The software was rewritten to allow plugins and expand features available in the menu system. GRUB legacy and GRUB2 are otherwise fairly similar. |
||
6 | |||
7 | Let’s continue on how you can easily change the default kernel in GRUB on your Linux RHEL or CentOS 7 Server. |
||
8 | |||
9 | |||
10 | ## Step 1. Get list of installed kernels |
||
11 | |||
12 | ``` |
||
13 | awk -F\' /^menuentry/{print\$2} /etc/grub2.cfg |
||
14 | ``` |
||
15 | |||
16 | Output: |
||
17 | |||
18 | ``` |
||
19 | 0- Red Hat Enterprise Linux Server (3.10.0-1062.7.1.el7.x86_64) 7.7 (Maipo) |
||
20 | 1- Red Hat Enterprise Linux Server (3.10.0-1062.1.2.el7.x86_64) 7.7 (Maipo) |
||
21 | 2- Red Hat Enterprise Linux Server (3.10.0-693.el7.x86_64) 7.4 (Maipo) |
||
22 | 3- Red Hat Enterprise Linux Server (0-rescue-39228403a82a4e29afb7e5ca1a869adb) 7.4 (Maipo) |
||
23 | ``` |
||
24 | |||
25 | ## Step 2. Set a default kernel |
||
26 | |||
27 | ``` |
||
28 | grub2-set-default 1 |
||
29 | ``` |
||
30 | |||
31 | ## Step 3. Verify new default kernel |
||
32 | |||
33 | ``` |
||
34 | cat /boot/grub2/grubenv | grep saved |
||
35 | ``` |
||
36 | |||
37 | Output: |
||
38 | |||
39 | ``` |
||
40 | saved_entry=1 |
||
41 | ``` |
||
42 | |||
43 | ## Step 4. Rebuild GRUB Config File |
||
44 | |||
45 | BIOS-based: |
||
46 | |||
47 | ``` |
||
48 | grub2-mkconfig -o /boot/grub2/grub.cfg |
||
49 | ``` |
||
50 | |||
51 | UEFI-based: |
||
52 | |||
53 | ``` |
||
54 | grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg |
||
55 | ``` |
||
56 | |||
57 | ## Step 4. Reboot Server |
||
58 | |||
59 | All done! You can now reboot your Linux Server to have it booted with your new default kernel. |
||
60 | |||
61 | ``` |
||
62 | shutdown -r now |
||
63 | ``` |