cancel
Showing results for 
Search instead for 
Did you mean: 
vsolodkyi
Sisense Team Member
Sisense Team Member

Some OS related issues could be fixed by installing a different Linux Kernel. In this article we will review how to install a new kernel and make it bootable by default.

Installing a new kernel

  1. Display version of currently running Kernel: uname -r
     Example output: 4.15.0-76-generic
  2. Update current packages sudo apt update
  3. List available for installation kernels: sudo apt list linux-*image-* | grep generic  
    Note: if you don’t see an image that you are looking for, it is probably because that image cannot be installed in the current installation.  In that event, you’ll need to upgrade to one of the available kernels.  Once installed, you can run apt list again to see higher level kernel images.
    Example output: 

Listing... Done

linux-image-4.15.0-101-generic/bionic-updates,bionic-security 4.15.0-101.102 amd64

linux-image-4.15.0-106-generic/bionic-updates,bionic-security 4.15.0-106.107 amd64

linux-image-4.15.0-108-generic/bionic-updates,bionic-security 4.15.0-108.109 amd64

linux-image-4.15.0-109-generic/bionic-updates,bionic-security 4.15.0-109.110 amd64

linux-image-4.15.0-111-generic/bionic-updates,bionic-security 4.15.0-111.112 amd64

From the output we can see different types of kernels which could be used under different circumstances. Let’s imagine that the fix for our issue is contained in linux-image-5.4.0-137-generic kernel.

4. Install selected kernel with sudo apt -fix-broken install linux-image-5.4.0-137-generic The –fix-broken switch corrects any broken dependencies.  It will take some time to install, however successful run should be ended with done.

5. Check installed kernels with dpkg --list | grep linux-image     Example output:  

hi  linux-image-4.15.0-76-generic         4.15.0-76.86                                    amd64        Signed kernel image generic

ii  linux-image-5.4.0-137-generic         5.4.0-137.154~18.04.1                           amd64        Signed kernel image generic

ii  linux-image-generic                   4.15.0.76.78                                    amd64        Generic Linux kernel image

We can see our new kernel in the list now. 

 

Booting system with a new kernel

Please note that it could be dangerous and the system can get stuck at the load, so be sure that you have all backups and snapshots created before the procedure.
The instructions below are only relevant if the machine/VM does not boot to the new kernel

To activate a new kernel we should reboot the machine and select a newly installed kernel, 

However in case if we don’t have access to the bare metal or hypervisor we can manually “hardcode” the new kernel in GRUB.

  1. We need to find a few entrances from /boot/grub/grub.cfg :
  • Get the $menuentry_id_option with grep submenu /boot/grub/grub.cfg 

Example output: submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66' {

Here 'gnulinux-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66'  is what we are looking for.

  • Get the specific kernel option with grep gnulinux-5.4.0 /boot/grub/grub.cfg 

Example output: menuentry 'Ubuntu, with Linux 5.4.0-137-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-137-generic-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66' {

menuentry 'Ubuntu, with Linux 5.4.0-137-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-137-generic-recovery-88f56154-7603-4a3f-86d1-5ed1459cef66' {

Here 'gnulinux-5.4.0-137-generic-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66' is what we are looking for.  

2. Set GRUB_DEFAULT in /etc/default/grub/

  • Join two previously obtained strings by ‘>’, for GRUB_DEFAULT variable. Example:  GRUB_DEFAULT=’gnulinux-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66>gnulinux-5.4.0-137-generic-advanced-88f56154-7603-4a3f-86d1-5ed1459cef66

3. Update GRUB with sudo update-grub

4. Reboot the machine - now the system should boot up with a new kernel. In case of any errors please revert back all changes using the snapshot or grub-rescue CLI. 


 

Rate this article:
Version history
Last update:
‎04-15-2024 05:32 PM
Updated by: