Installing the Linux Mainline Kernel on Ubuntu 22.04 LTS: A Step‑by‑Step Guide
On a fresh Ubuntu 22.04 installation, the stock kernel is often fine for everyday use. But when newer hardware or drivers arrive ahead of the official LTS release, that stock kernel can feel sluggish or even broken. Switching to the latest mainline kernel gives instant access to newer features, better hardware support, and sometimes restores functionality lost after a buggy driver update.
Why Upgrade to the Mainline Kernel?
A few weeks ago, a user on a laptop with an Intel i7‑1185G7 processor noticed that Wi‑Fi vanished right after installing the latest proprietary graphics drivers. The stock kernel 5.15 lacked the patch that the new driver required. Installing mainline 6.x pulled in the missing module and the network worked again. That’s one of many real-world scenarios where the mainline kernel proves its worth.
Prerequisites
- Back up important data. Kernel changes are low‑risk, but a misstep can leave a system unbootable.
- Confirm current kernel version. Open a terminal and run:
uname -r
Note the output; you’ll need it to revert if anything goes wrong.
Install Required Packages
The Ubuntu Mainline Installer relies on a handful of utilities that are not part of the default install:
sudo apt update && sudo apt install -y software-properties-common wget dkms build-essential
- software-properties-common lets you add PPAs easily.
- wget fetches the installer script from the official kernel website.
- dkms and build‑essential are needed if you want to compile modules that the mainline kernel doesn’t ship with prebuilt binaries.
Grab the Official Mainline Installer Script
The Linux Foundation hosts a small helper script that downloads, installs, and removes kernels on demand:
wget https://raw.githubusercontent.com/oznu/linux-mainline/master/mainline.sh -O ~/mainline.sh
chmod +x ~/mainline.sh
This script checks the kernel archive, verifies signatures, and keeps things tidy. No need to manually handle .deb packages.
Install the Latest Mainline Kernel
Run the installer with the --install latest flag:
cd ~ && sudo ./mainline.sh --install latest
During execution you’ll see a list of downloaded files, the kernel and headers being unpacked, and the boot loader updated. The installer automatically adds an entry to GRUB for the new kernel.
Reboot into the New Kernel
After installation, reboot:
sudo reboot
At the GRUB menu, choose “Advanced options for Ubuntu” → the entry that ends with “mainline”. If you’re comfortable with the default boot order, simply let the system start normally; it will pick the newest kernel automatically.
Verify Success
Once back in the session, open a terminal again:
uname -r
The output should now begin with 6. instead of 5.. If everything looks good, you’re running the mainline kernel.
Troubleshooting Common Issues
| Symptom | Likely Cause | Fix |
|---|---|---|
| System fails to boot after rebooting | GRUB entry corrupted or missing | Boot from recovery mode → grub-reboot to point to the previous kernel, then reinstall mainline |
| Hardware not working (e.g., Wi‑Fi, GPU) | Missing driver modules in mainline | Install DKMS module for that hardware (sudo apt install linux-modules-extra-$(uname -r)), or revert to stock kernel |
Reverting to the Official Kernel
If something breaks, simply boot into the “Ubuntu” entry (the default stock kernel) and run:
cd ~ && sudo ./mainline.sh --remove latest
This removes all mainline packages and restores GRUB to its previous state.
Keeping the Mainline Kernel Current
The installer can also keep the kernel updated automatically:
sudo ./mainline.sh --update
Run this weekly or monthly, or set up a cron job if you’re comfortable with scheduled maintenance.
That’s all there is to it: download a tiny script, let it do its work, and enjoy the bleeding‑edge kernel on your LTS machine. If a newer driver suddenly drops out of sync with 5.15, a quick switch to mainline can be the difference between a fully functional laptop and a frustrating, unresponsive desktop.