Forum Stats

  • 3,728,470 Users
  • 2,245,631 Discussions
  • 7,853,548 Comments

Discussions

Oracle Linux - How to Change Default Kernel

Oracle Linux comes with a choice of two kernels, the Unbreakable Enterprise Kernel (UEK), which is installed and enabled by default, and the Red Hat Compatible Kernel (RHCK).

In this tutorial, we use Oracle Linux instances in Oracle Cloud Infrastructure to illustrate how you change the default kernel (UEK) and boot into an old kernel such as RHCK. To launch an Oracle Linux instance in Oracle Cloud Infrastructure, please follow Getting Started Guide.

Change Default Kernel in Oracle Linux 6 and 5

Oracle Linux 6 and 5 use the GRUB boot loader. To change the default boot kernel, you modify the GRUB configuration file, /etc/grub.conf.

The default directive specifies the kernel entry that GRUB should boot by default. GRUB counts the kernel entries in the configuration file starting at 0. The directive default=0 means that GRUB boots the first kernel entry by default, unless you override this action. The UEK is configured as the first entry, and the RHCK is configured as the second entry. Changing the value of default to 1 (other value) would cause GRUB to boot the RHCK (or another kernel) by default.

Here's an Oracle Linux 6.10 instance in Oracle Cloud Infrastructure. It has the UEK and RHCK installed. The UEK is the default running kernel.

[[email protected] opc]# rpm -qa kernel-uek<p>kernel-uek-4.1.12-124.18.5.el6uek.x86_64</p><p>[[email protected] opc]# rpm -qa kernel</p><p>kernel-2.6.32-754.el6.x86_64</p><p>kernel-2.6.32-754.2.1.el6.x86_64</p><p>[[email protected] opc]# uname -a</p><p>Linux honsu-ol6-vm2 4.1.12-124.18.5.el6uek.x86_64 #2 SMP Mon Aug 13 16:18:59 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux</p>

Next you modify the default directive of the GRUB configuration file, /etc/grub.conf.

# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE:  You do not have a /boot partition.  This means that#          all kernel and initrd paths are relative to /, eg.#          root (hd0,2)#          kernel /boot/vmlinuz-version ro root=/dev/sda3#          initrd /boot/initrd-[generic-]version.img#boot=/dev/sda1device (hd0) HD(1,800,64000,d2fcf22a-4d03-4e56-a262-8974772642e2)default=1timeout=5serial --unit=0 --speed=9600terminal --timeout=5 serial consoletitle Oracle Linux Server Unbreakable Enterprise Kernel (4.1.12-124.18.5.el6uek.x86_64)        root (hd0,2)        kernel /boot/vmlinuz-4.1.12-124.18.5.el6uek.x86_64 ro root=UUID=974abb96-e711-42fa-b371-388abd421ff0 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto ip=dhcp netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 biosdevname=1 nvme_core.shutdown_timeout=10 libiscsi.debug_libiscsi_eh=1 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0 rd_NO_LVM rd_NO_DM irqpoll console=tty0 console=ttyS0,9600        initrd /boot/initramfs-4.1.12-124.18.5.el6uek.x86_64.imgtitle Oracle Linux Server Red Hat Compatible Kernel (2.6.32-754.2.1.el6.x86_64)        root (hd0,2)        kernel /boot/vmlinuz-2.6.32-754.2.1.el6.x86_64 ro root=UUID=974abb96-e711-42fa-b371-388abd421ff0 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto ip=dhcp netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 biosdevname=1 nvme_core.shutdown_timeout=10 libiscsi.debug_libiscsi_eh=1 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0 rd_NO_LVM rd_NO_DM irqpoll console=tty0 console=ttyS0,9600        initrd /boot/initramfs-2.6.32-754.2.1.el6.x86_64.imgtitle Oracle Linux Server Red Hat Compatible Kernel (2.6.32-754.el6.x86_64)        root (hd0,2)        kernel /boot/vmlinuz-2.6.32-754.el6.x86_64 ro root=UUID=974abb96-e711-42fa-b371-388abd421ff0 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto ip=dhcp netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 biosdevname=1 nvme_core.shutdown_timeout=10 libiscsi.debug_libiscsi_eh=1 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0 rd_NO_LVM rd_NO_DM irqpoll console=tty0 console=ttyS0,9600        initrd /boot/initramfs-2.6.32-754.el6.x86_64.img

Then you reboot the instance.

[[email protected] opc]# reboot

After the instance is up and running, you verify the running kernel which is RHCK.

[[email protected] ~]$ uname -aLinux honsu-ol6-vm2 2.6.32-754.2.1.el6.x86_64 #1 SMP Tue Jul 10 12:24:15 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux

The same instructions apply to Oracle Linux 5. Or if you are running Red Hat Enterprise Linux / CentOS 6 or 5, you can follow the same method of changing the default kernel by modifying the default directive of the GRUB configuration file, /etc/grub.conf.

Change Default Kernel in Oracle Linux 7

Oracle Linux 7 uses the GRUB 2 boot loader, which is different from the GRUB boot loader in Oracle Linux 6 and 5.

The default menu entry is determined by the value of the GRUB_DEFAULT parameter in /etc/default/grub. The value saved allows you to use the grub2-set-default and grub2-reboot commands to specify the default entry. grub2-set-default sets the default entry for all subsequent reboots and grub2-reboot sets the default entry for the next reboot only.

[[email protected] ~]$ cat /etc/default/grubGRUB_TIMEOUT=5GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_DISABLE_RECOVERY="true"GRUB_TERMINAL="console"GRUB_CMDLINE_LINUX="crashkernel=auto LANG=en_US.UTF-8 transparent_hugepage=never console=tty0 console=ttyS0,9600 rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0 ip=dhcp netroot=iscsi:169.254.0.2:::1:iqn.2015-02.oracle.boot:uefi iscsi_param=node.session.timeo.replacement_timeout=6000 net.ifnames=1 nvme_core.shutdown_timeout=10 ipmi_si.tryacpi=0 ipmi_si.trydmi=0 ipmi_si.trydefaults=0"

The instance below is running Oracle Linux 7.5 which was upgraded from an Oracle Linux 7.4 image in Oracle Cloud Infrastructure. The OS has multiple UEK and RHCK installed. The UEK Release 5 is the default running kernel.

[[email protected] grub2]# uname -aLinux honsu-ol7-vm1 4.14.35-1818.0.14.el7uek.x86_64 #2 SMP Sat Aug 4 17:55:46 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux[[email protected] grub2]# rpm -qa kernel-uekkernel-uek-4.1.12-112.14.15.el7uek.x86_64kernel-uek-4.14.35-1818.0.14.el7uek.x86_64kernel-uek-4.1.12-112.16.4.el7uek.x86_64[[email protected] grub2]# rpm -qa kernelkernel-3.10.0-862.9.1.el7.x86_64kernel-3.10.0-693.el7.x86_64kernel-3.10.0-693.17.1.el7.x86_64

Generate the GRUB 2 configuration file (/boot/grub2/grub.cfg) if it has never been created.

[[email protected] opc]# grub2-mkconfig -o /boot/grub2/grub.cfgGenerating grub configuration file ...Found linux image: /boot/vmlinuz-4.14.35-1818.0.14.el7uek.x86_64Found initrd image: /boot/initramfs-4.14.35-1818.0.14.el7uek.x86_64.imgFound linux image: /boot/vmlinuz-4.1.12-112.16.4.el7uek.x86_64Found initrd image: /boot/initramfs-4.1.12-112.16.4.el7uek.x86_64.imgFound linux image: /boot/vmlinuz-4.1.12-112.14.15.el7uek.x86_64Found initrd image: /boot/initramfs-4.1.12-112.14.15.el7uek.x86_64.imgFound linux image: /boot/vmlinuz-3.10.0-862.9.1.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-862.9.1.el7.x86_64.imgFound linux image: /boot/vmlinuz-3.10.0-693.17.1.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-693.17.1.el7.x86_64.imgFound linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.imgFound linux image: /boot/vmlinuz-0-rescue-84bd95291187463cb75fc62b80a6a6caFound initrd image: /boot/initramfs-0-rescue-84bd95291187463cb75fc62b80a6a6ca.imgFound linux image: /boot/vmlinuz-0-rescue-3e5a2d0d105b47278b9f57145d68fb22Found initrd image: /boot/initramfs-0-rescue-3e5a2d0d105b47278b9f57145d68fb22.imgdone

Display the menu entries that are defined in the configuration file, for example:

[[email protected] opc]# awk -F\' /^menuentry/{print\$2} /etc/grub2.cfgOracle Linux Server (4.14.35-1818.0.14.el7uek.x86_64 with Unbreakable Enterprise Kernel) 7.5Oracle Linux Server (4.1.12-112.16.4.el7uek.x86_64 with Unbreakable Enterprise Kernel) 7.5Oracle Linux Server (4.1.12-112.14.15.el7uek.x86_64 with Unbreakable Enterprise Kernel) 7.5Oracle Linux Server (3.10.0-862.9.1.el7.x86_64 with Linux) 7.5Oracle Linux Server (3.10.0-693.17.1.el7.x86_64 with Linux) 7.5Oracle Linux Server (3.10.0-693.el7.x86_64 with Linux) 7.5Oracle Linux Server (0-rescue-84bd95291187463cb75fc62b80a6a6ca with Linux) 7.5Oracle Linux Server (0-rescue-3e5a2d0d105b47278b9f57145d68fb22 with Linux) 7.5

Pick the kernel you want to run at the next reboot. For example, I'm choosing the RHCK 3.10.0-862.9.1.el7.x86_64 as the kernel to run at the next reboot.

[[email protected] opc]# grub2-set-default 'Oracle Linux Server (3.10.0-862.9.1.el7.x86_64 with Linux) 7.5'[[email protected] opc]# grub2-mkconfig -o /boot/grub2/grub.cfg[[email protected] opc]# reboot

After the OS instance rebooted and comes back, it's running the kernel that you just picked.

[[email protected] ~]$ uname -aLinux honsu-ol7-vm1 3.10.0-862.9.1.el7.x86_64 #1 SMP Mon Jul 16 10:10:11 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux

Change Default Kernel in Oracle Linux 8

In Oracle Linux 8, you can use the grubby command to manage your boot requirements.

The instance below is running Oracle Linux 8.1 and it has the UEK and RHCK installed.

[[email protected] opc]# ls -l /boot/vmlinuz*-rwxr-xr-x. 1 root root 8108272 Nov 21  2019 /boot/vmlinuz-4.18.0-147.0.3.el8_1.x86_64-rwxr-xr-x. 1 root root 9230576 Jun 10 01:30 /boot/vmlinuz-4.18.0-193.6.3.el8_2.x86_64-rwxr-xr-x. 1 root root 8915200 Jun 27 18:20 /boot/vmlinuz-5.4.17-2011.4.4.el8uek.x86_64

Use the grubby --default-kernel command to view the current default kernel. In this case, the RHCK is the default running kernel.

[[email protected] opc]# grubby --default-kernel/boot/vmlinuz-4.18.0-193.6.3.el8_2.x86_64

The grubby --set-default command can be used to change the default kernel to the one you specify. Here, the default kernel is being changed to UEK Release 6.

[[email protected] opc]# grubby --set-default /boot/vmlinuz-5.4.17-2011.4.4.el8uek.x86_64The default is /boot/loader/entries/ed37772a50f14ee9b06ea020527e8d1e-5.4.17-2011.4.4.el8uek.x86_64.conf with index 2 and kernel /boot/vmlinuz-5.4.17-2011.4.4.el8uek.x86_64

Your changes are immediately reflected and after rebooting your instance will be running the kernel you chose.

[[email protected] opc]# grubby --default-kernel/boot/vmlinuz-5.4.17-2011.4.4.el8uek.x86_64[[email protected] opc]# uname -aLinux leojim-ol8-vm1 5.4.17-2011.4.4.el8uek.x86_64 #2 SMP Sat Jun 27 11:14:55 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux

References







Comments

Sign In or Register to comment.