Use mainline to switch between Linux kernels

From RidgeRun Developer Wiki

Intro

This wiki describes the process to setup mainline tool in order to change the kernel version on Ubuntu. This tool can be useful in setups where the HW requires a version of Ubuntu that is too new or too old. For example a new laptop that requires newer kernel but due to package restrictions you need an older Ubuntu.

Mainline setup

sudo add-apt-repository ppa:cappelikan/ppa
sudo apt update
sudo apt install mainline 

After install you an open it and you will see something like:

This will list the current installed kernels and all the possible installs. Beware and do some previous investigation before moving to another version since the kernel is usually coupled to glibc, libc and other important system libraries. So big jumps can break api compatibility and if done without proper preparation can require that you do some recovery work on the OS.

Use mainline to fix compatibility issues

In my setup, due to packages I need for projects I cannot use latest Ubuntu, that version has the kernel that supports the iGPU, and after installing Ubuntu 22.04, the laptop was stuck in the Ubuntu screen.

After some research the culprit seemed to be the iGPU drivers, and broken kernel drivers. So the work around was to boot into recovery using a live Ubuntu USB and set safe graphics mode by default.

Setting safe graphics mode

In order to at least boot with the incompatible version, you need to change the boot config to use the safe graphics mode. This makes sure the generic drivers are loaded, the OS can be used as is, but you can expect scaling problems, weird resolutions and also problems with screen-sharing as such. So the idea is to use it in safe mode just to install the proper drivers.
You do not need this in case you are able to at least made it to the splash screen where you can boot into safe graphics or recovery mode, in my case not even that was working.

  • Boot into live Ubuntu, and select try Ubuntu instead of install
  • Check the disk that has the os you want to modify, in my case its /dev/nvme0n1p2 for the rootfs and /dev/nvme0n1p1 for the boot partition:
nvme0n1     259:0    0 953,9G  0 disk 
├─nvme0n1p1 259:1    0 513,1M  0 part /boot/efi
└─nvme0n1p2 259:2    0   931G  0 part /
  • Mount them
sudo mount /dev/nvme0n1p2 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
sudo mount /dev/nvme0n1p1 /mnt/boot/efi
  • Then change root
    sudo chroot /mnt
  • Change the boot config file at /etc/default/grub, add "nomodeset" to GRUB_CMDLINE_LINUX_DEFAULT
  • Save the change and run sudo update-grub
  • umount the drives and reboot, this should enable you to boot into the 'incompatible' Ubuntu

Upgrade the kernel

This process is fairly simple, install mainline using the above steps and in my case 'core ultra 7 155u' the kernel that is not that far from the current one and is compatible with the major libraries and also brings support to the iGPU is 6.9.

  1. Select the kernel on mainline, in this case 6.9
  1. Hit Install and wait for it to finish
  2. If all went fine, exit mainline and run
    sudo apt-get update && sudo apt-get upgrade
    to fix any orphaned libraries and if need be, run
     sudo apt --fix-broken install 
  3. Use it for a bit and make sure nothing is broken. And reboot
  4. After boot double check nothing is broken and if not, revert the change on /etc/default/grub, since we are fully booted in the target OS we can do it without the live Ubuntu USB.
  5. Run sudo update-grub
  6. Reboot and you should be able to boot normally with the proper iGPU support