Install mainline Linux kernel on Ubuntu-based distribution.

Add a PPA to your system’s software sources.

$ sudo add-apt-repository ppa:cappelikan/ppa                                             

Update package index.

$ sudo apt update

Inspect mainline package.

$ apt info mainline
Package: mainline
Version: 1.0.14-0~202109142035~ubuntu21.04.1
Priority: extra
Section: utils
Maintainer: Brian K. White <b.kenyon.w@gmail.com>
Installed-Size: 775 kB
Depends: libc6 (>= 2.4), libgdk-pixbuf-2.0-0 (>= 2.22.0), libgee-0.8-2 (>= 0.8.3), libglib2.0-0 (>= 2.37.3), libgtk-3-0 (>= 3.16.2), libjson-glib-1.0-0 (>= 1.5.2), libvte-2.91-0, aptitude, aria2, lsb-release
Download-Size: 151 kB
APT-Manual-Installed: yes
APT-Sources: http://ppa.launchpad.net/cappelikan/ppa/ubuntu hirsute/main amd64 Packages
Description: Kernel Update Utility for Ubuntu-based distributions
 Utility for installing mainline Linux kernels on Ubuntu-based distributions.
 Downloads and installs kernel packages from kernel.ubuntu.com.
 .
 This is a fork and continuation of the final GPL version of the original author's package "ukuu".

Install mainline package.

$ sudo apt install mainline                                                                                                                                                 

Display help information.

$ mainline                                                                                                                                                        
mainline 1.0.15                                                                                                                                                             
Distribution: Ubuntu 21.04                                                                                                                                                  
Architecture: amd64                                                                                                                                                         
Running kernel: 5.11.0-34-generic                                                                                                                                           
                                                                                                                                                                            
mainline 1.0.15 - Ubuntu Mainline Kernel Installer                                                                                                                          
                                                                                                                                                                            
Syntax: mainline <command> [options]                                                                                                                                        
                                                                                                                                                                            
Commands:                                                                                                                                                                   
                                                                                                                                                                            
  --check             Check for kernel updates                                                                                                                              
  --notify            Check for kernel updates and notify current user                                                                                                      
  --list              List all available mainline kernels                                                                                                                   
  --list-installed    List installed kernels                                                                                                                                
  --install-latest    Install latest mainline kernel                                                                                                                        
  --install-point     Install latest point update for current series                                                                                                        
  --install <name>    Install specified mainline kernel(1)                                                                                                                  
  --uninstall <name>  Uninstall specified kernel(2)                                                                                                                         
  --uninstall-old     Uninstall kernels older than the running kernel                                                                                                       
  --download <name>   Download specified kernels(2)                                                                                                                         
  --clean-cache       Remove files from application cache                                                                                                                   
                                                                                                                                                                            
Options:                                                                                                                                                                    
                                                                                                                                                                            
  --include-unstable  Include unstable and RC releases                                                                                                                      
  --hide-unstable     Hide unstable and RC releases                                                                                                                         
  --debug           Enable verbose debugging output                                                                                                                         
  --yes             Assume Yes for all prompts (non-interactive mode)                 
  --user            Override user          

Notes:                                     
(1) A version string taken from the output of --list                                  
(2) One or more version strings (comma-separated) taken from the output of --list     

Check kernel updates.

$ mainline --check                  
mainline 1.0.15
Distribution: Ubuntu 21.04
Architecture: amd64
Running kernel: 5.11.0-34-generic
Fetching index from kernel.ubuntu.com...
OK
----------------------------------------------------------------------
Found installed: 5.11.0-31.33
Found installed: 5.11.0-22.23
Found installed: 5.11.0.34.36
Found installed: 5.11.0-34.36
----------------------------------------------------------------------
----------------------------------------------------------------------
Latest update: 5.14.5
Latest point update: 5.11.20
----------------------------------------------------------------------

List available kernels.

❯ mainline --list                
mainline 1.0.15                  
Distribution: Ubuntu 21.04       
Architecture: amd64                     
Running kernel: 5.11.0-34-generic         
Fetching index from kernel.ubuntu.com...                                              
OK                                        
----------------------------------------------------------------------                
Found installed: 5.11.0-31.33    
Found installed: 5.11.0-22.23    
Found installed: 5.11.0.34.36                                                         
Found installed: 5.11.0-34.36                                                         
----------------------------------------------------------------------                
----------------------------------------------------------------------                
                                           
======================================================================                
Available Kernels                       
======================================================================                
5.14.5                           
5.14.4                           
5.14.3                                                                                
5.14.2                                                                                
5.14.1                           
5.14.0                           
[...]
5.11.2                           
5.11.1                                  
5.11.0.34.36                     Installed
5.11.0.31.33                     Installed                                            
5.11.0.22.23                     Installed
5.11.0                                                                                
5.10.66                          
5.10.65                          
5.10.64                                                                               
[...]
5.0.16                           
5.0.15                           
5.0.14                           
5.0.13                                                                                
5.0.12                                                                                
5.0.10                           
5.0.5                            
5.0.0                            

Install latest mainline, latest point update or specific kernel.

❯ sudo mainline --install-latest
❯ sudo mainline --install-point
❯ sudo mainline --install 5.11.20
mainline 1.0.15                                                                                                                                                             
Distribution: Ubuntu 21.04                                                            
Architecture: amd64                                                                   
Running kernel: 5.11.0-34-generic          
Fetching index from kernel.ubuntu.com...                                              
OK                                                                                    
----------------------------------------------------------------------                                                                                                      
Found installed: 5.11.0-31.33                                                                                                                                               
Found installed: 5.11.0-22.23                                                         
Found installed: 5.11.0.34.36                                                         
Found installed: 5.11.0-34.36                                                         
----------------------------------------------------------------------               
----------------------------------------------------------------------           
                                                                                      
Downloading: 'amd64/linux-headers-5.11.20-051120_5.11.20-051120.202105120733_all.deb'... 
OK                                                                                    
                                                                                      
Downloading: 'amd64/linux-modules-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb'... 
OK                                                                                    
                                                                                      
Downloading: 'amd64/linux-image-unsigned-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb'... 
OK                                                                     
                                                                                      
Downloading: 'amd64/linux-headers-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb'... 
OK                                                                    
Preparing to install '5.11.20'             
kinst() flist += amd64/linux-headers-5.11.20-051120_5.11.20-051120.202105120733_all.deb
kinst() flist += amd64/linux-modules-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb
kinst() flist += amd64/linux-image-unsigned-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb
kinst() flist += amd64/linux-headers-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb
Selecting previously unselected package linux-headers-5.11.20-051120.
(Reading database ... 372121 files and directories currently installed.)
Preparing to unpack .../linux-headers-5.11.20-051120_5.11.20-051120.202105120733_all.deb ...
Unpacking linux-headers-5.11.20-051120 (5.11.20-051120.202105120733) ...
Selecting previously unselected package linux-modules-5.11.20-051120-generic.
Preparing to unpack .../linux-modules-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb ...
Unpacking linux-modules-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
Selecting previously unselected package linux-image-unsigned-5.11.20-051120-generic.
Preparing to unpack .../linux-image-unsigned-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb ...
Unpacking linux-image-unsigned-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
Selecting previously unselected package linux-headers-5.11.20-051120-generic.
Preparing to unpack .../linux-headers-5.11.20-051120-generic_5.11.20-051120.202105120733_amd64.deb ...
Unpacking linux-headers-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
Setting up linux-headers-5.11.20-051120 (5.11.20-051120.202105120733) ...
Setting up linux-headers-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
/etc/kernel/header_postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.20-051120-generic

Kernel preparation unnecessary for this kernel.  Skipping...
applying patch disable_fstack-clash-protection_fcf-protection.patch...patching file Kbuild
Hunk #1 succeeded at 82 (offset 11 lines).


Building module:
cleaning build area...
unset ARCH; [ ! -h /usr/bin/cc ] && export CC=/usr/bin/gcc; env NV_VERBOSE=1 'make' -j4 NV_EXCLUDE_BUILD_MODULES='' KERNEL_UNAME=5.11.20-051120-generic IGNORE_XEN_PRESENCE=
1 IGNORE_CC_MISMATCH=1 SYSSRC=/lib/modules/5.11.20-051120-generic/build LD=/usr/bin/ld.bfd modules...............
Signing module:
 - /var/lib/dkms/nvidia/460.80/5.11.20-051120-generic/x86_64/module/nvidia.ko
 - /var/lib/dkms/nvidia/460.80/5.11.20-051120-generic/x86_64/module/nvidia-drm.ko
 - /var/lib/dkms/nvidia/460.80/5.11.20-051120-generic/x86_64/module/nvidia-modeset.ko
 - /var/lib/dkms/nvidia/460.80/5.11.20-051120-generic/x86_64/module/nvidia-uvm.ko
EFI variables are not supported on this system
/sys/firmware/efi/efivars not found, aborting.
cleaning build area...

DKMS: build completed.

nvidia.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

nvidia-modeset.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

nvidia-drm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

nvidia-uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

depmod...

DKMS: install completed.

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make -j4 KERNELRELEASE=5.11.20-051120-generic -C /lib/modules/5.11.20-051120-generic/build M=/var/lib/dkms/virtualbox/6.1.26/build.......
Signing module:
 - /var/lib/dkms/virtualbox/6.1.26/5.11.20-051120-generic/x86_64/module/vboxnetflt.ko
 - /var/lib/dkms/virtualbox/6.1.26/5.11.20-051120-generic/x86_64/module/vboxnetadp.ko
 - /var/lib/dkms/virtualbox/6.1.26/5.11.20-051120-generic/x86_64/module/vboxdrv.ko
EFI variables are not supported on this system
/sys/firmware/efi/efivars not found, aborting.
cleaning build area...

DKMS: build completed.

vboxdrv.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

vboxnetadp.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

vboxnetflt.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.11.20-051120-generic/updates/dkms/

depmod...

DKMS: install completed.
   ...done.
Setting up linux-modules-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
Setting up linux-image-unsigned-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
I: /boot/vmlinuz.old is now a symlink to vmlinuz-5.11.0-34-generic
I: /boot/initrd.img.old is now a symlink to initrd.img-5.11.0-34-generic
I: /boot/vmlinuz is now a symlink to vmlinuz-5.11.20-051120-generic
I: /boot/initrd.img is now a symlink to initrd.img-5.11.20-051120-generic
Processing triggers for linux-image-unsigned-5.11.20-051120-generic (5.11.20-051120.202105120733) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.20-051120-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.11.20-051120-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.20-051120-generic
Found initrd image: /boot/initrd.img-5.11.20-051120-generic
Found linux image: /boot/vmlinuz-5.11.0-34-generic
Found initrd image: /boot/initrd.img-5.11.0-34-generic
Found linux image: /boot/vmlinuz-5.11.0-31-generic
Found initrd image: /boot/initrd.img-5.11.0-31-generic
Found linux image: /boot/vmlinuz-5.11.0-22-generic
Found initrd image: /boot/initrd.img-5.11.0-22-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Installation completed. A reboot is required to use the new kernel.

List installed kernels.

$ mainline --list-installed 
mainline 1.0.15
Distribution: Ubuntu 21.04
Architecture: amd64
Running kernel: 5.11.0-34-generic
----------------------------------------------------------------------
Found installed: 5.11.0-31.33
Found installed: 5.11.0-22.23
Found installed: 5.11.0.34.36
Found installed: 5.11.20-051120.202105120733
Found installed: 5.11.0-34.36
----------------------------------------------------------------------
----------------------------------------------------------------------

Uninstall kernels older than the running one or a specific one.

$ sudo mainline --uninstall-old
$ sudo mainline --uninstall 5.13.18                                                    
mainline 1.0.15                                                                       
Distribution: Ubuntu 21.04                                                            
Architecture: amd64                                                                   
Running kernel: 5.11.0-34-generic                                                     
Fetching index from kernel.ubuntu.com...                                              
OK                                                                                    
----------------------------------------------------------------------                
Found installed: 5.11.0-31.33                                                         
Found installed: 5.13.18-051318.202109161133                                          
Found installed: 5.11.0-22.23                                                                                                                                               
Found installed: 5.11.0.34.36                                                                                                                                               
Found installed: 5.11.0-34.36                                                                                                                                               
----------------------------------------------------------------------                                                                                                      
----------------------------------------------------------------------                                                                                                      
Preparing to uninstall selected kernels                                                                                                                                     
(Reading database ... 406995 files and directories currently installed.)                                                                                                    
Removing linux-headers-5.13.18-051318-generic (5.13.18-051318.202109161133) ...                                                                                             
Removing linux-headers-5.13.18-051318 (5.13.18-051318.202109161133) ...                                                                                                     
Removing linux-modules-5.13.18-051318-generic (5.13.18-051318.202109161133) ...                                                                                             
Purging configuration files for linux-modules-5.13.18-051318-generic (5.13.18-051318.202109161133) ...                                                                      
dpkg: warning: while removing linux-modules-5.13.18-051318-generic, directory '/lib/modules/5.13.18-051318-generic' not empty so not removed                                
Removing linux-image-unsigned-5.13.18-051318-generic (5.13.18-051318.202109161133) ...                                                                                      
I: /boot/vmlinuz.old is now a symlink to vmlinuz-5.11.0-31-generic                                                                                                          
I: /boot/initrd.img.old is now a symlink to initrd.img-5.11.0-31-generic                                                                                                    
I: /boot/vmlinuz is now a symlink to vmlinuz-5.11.0-34-generic                                                                                                              
I: /boot/initrd.img is now a symlink to initrd.img-5.11.0-34-generic                                                                                                        
/var/lib/dpkg/info/linux-image-unsigned-5.13.18-051318-generic.postrm ... removing pending trigger
/etc/kernel/postrm.d/initramfs-tools:                                                 
update-initramfs: Deleting /boot/initrd.img-5.13.18-051318-generic                    
/etc/kernel/postrm.d/zz-update-grub:                                                  
Sourcing file `/etc/default/grub'                                                     
Sourcing file `/etc/default/grub.d/init-select.cfg'                                   
Generating grub configuration file ...                                                
Found linux image: /boot/vmlinuz-5.11.0-34-generic    
Found initrd image: /boot/initrd.img-5.11.0-34-generic
Found linux image: /boot/vmlinuz-5.11.0-31-generic    
Found initrd image: /boot/initrd.img-5.11.0-31-generic
Found linux image: /boot/vmlinuz-5.11.0-22-generic    
Found initrd image: /boot/initrd.img-5.11.0-22-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-unsigned-5.13.18-051318-generic (5.13.18-051318.202109161133) ...
Un-install completed

In case of trouble, you can always clean the cache.

$ mainline --clean-cache
mainline 1.0.15
Distribution: Ubuntu 21.04
Architecture: amd64
Running kernel: 5.11.0-34-generic
Removed cached files in '/home/milosz/.cache/mainline'

You can also use a graphical user interface.

$ mainline-gtk

Beware, kernel upgrade is not always possible due to the used version of the standard C library.

[...]
dpkg: dependency problems prevent configuration of linux-headers-5.13.18-051318-generic:
 linux-headers-5.13.18-051318-generic depends on libc6 (>= 2.34); however:            
  Version of libc6:amd64 on system is 2.33-0ubuntu5.  
[...]
ko-fi