how to configure the grub.cfg file on redhat 7 in order to boot from specific kernel

15,900

Solution 1

How the change GRUB kernel on redhat 7 version

To list all the menu entries that will be displayed at system boot, issue the following command:

 # awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
 0 : Red Hat Enterprise Linux Server (3.10.0-327.18.2.el7.x86_64) 7.2 (Maipo)
 1 : Red Hat Enterprise Linux Server (3.10.0-327.10.1.el7.x86_64) 7.2 (Maipo)
 2 : Red Hat Enterprise Linux Server, with Linux 0-rescue- b2c5e6a1c5ea4cb5be82100bd7dc3469

How to verify what is the current entry (the current kernel from /etc/default/grub )

# grub2-editenv list
  saved_entry=1

This mean the current kernel version from grub configuration is: 3.10.0-327.10.1.el7.x86_64

let’s check what is the current kernel version on the machine:

# uname -r
  3.10.0-327.10.1.el7.x86_64

Now let’s changes the kernel version from GRUB configuration so Linux will boot with the higher kernel - 3.10.0-327.18.2.el7.x86_64 ,

remember from the awk command we get entrie number 0

So the setting should be as the following

 # grub2-set-default 0

Now we check the new GRUB configuration by

 # grub2-editenv list
   saved_entry=0

so now the new GRUB configuration is set to kernel version: 3.10.0-327.18.2.el7.x86_64

Now we reboot the machine

 # Reboot

After reboot Linux was up with the new kernel

 # uname -r
   3.10.0-327.18.2.el7.x86_64

Solution 2

change GRUB_DEFAULT=0 in /etc/default/grub to the number that you want, now you need to regenarate the grub2 config using grub2-mkconfig -o /boot/grub2/grub.cfg

Share:
15,900

Related videos on Youtube

dandan
Author by

dandan

Updated on September 18, 2022

Comments

  • dandan
    dandan over 1 year

    In Red Hat EL versions 5 and 6 we can easily to update the /etc/grub.conf in case we want to change the kernel by default variable

     For example , grub.conf on redhat 5
     default=0
     timeout=5
     #splashimage=(hd0,0)/grub/splash.xpm.gz
     #hiddenmenu
      title Red Hat Enterprise Linux Server (2.6.18-410.el5)
       root (hd0,0)
       kernel /vmlinuz-2.6.18-410.el5 ro root=/dev/rootvg/slash
       initrd /initrd-2.6.18-410.el5.img
      title Red Hat Enterprise Linux Server (2.6.18-409.el5)
        root (hd0,0)
       kernel /vmlinuz-2.6.18-409.el5 ro root=/dev/rootvg/slash
       initrd /initrd-2.6.18-409.el5.img
    

    From this /etc/grub.conf if we want to boot from kernel 2.6.18-409 version then we just change the default=1. So on the next boot, the OS will start with the old kernel

    RHEL7 is very different. I find in the RHEL7 the /boot/grub2/grub.cfg But I don't understand how to change the file in order to boot from other kernel as I do it on RHEL5.

  • dandan
    dandan almost 8 years
    just one remark - I not find the GRUB_DEFAULT in the file grub.cfg , cat /boot/grub2/grub.cfg|grep GRUB_DEFAULT , this variable exist in other file?
  • c4f4t0r
    c4f4t0r almost 8 years
    @dandan was my foul, I edited my answer with the filename that you need to edit
  • dandan
    dandan almost 8 years
    I think the seting of the default shuld be by the command - grub2-set-default N , while N is the entrie from awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
  • c4f4t0r
    c4f4t0r almost 8 years
    @dandan don't edit that file by hand.
  • dandan
    dandan almost 8 years
    please see my post , what you think about ?
  • c4f4t0r
    c4f4t0r almost 8 years
    @dandan is another way to change the default kernel, better then edit the file manually..
  • Prabhat Kumar Singh
    Prabhat Kumar Singh over 6 years
    May be you need to enter one more command after grub2-set-default 0 where 0 is the no. of the desired kernel. And then grub2-mkconfig -o /boot/grub2/grub.cfg