Updating the Linux Kernel offers many advantages, including new features, security patches, and performance improvements. We highly recommend regularly updating the kernel of your Linux distribution to maintain your system. This guide will show you how to safely update your kernel, walk you through the actual update process, and help you perform post-update checks to ensure everything runs smoothly.
The kernel manages every action on your Linux system, from opening applications to connecting to the internet. Therefore, keeping your kernel up-to-date is crucial. It ensures both system stability and security. Several Linux distributions, such as Debian, Linux Mint, and Pop!_OS, share similar kernel update procedures with Ubuntu due to their use of the APT package management system. While they might use different or customized kernels, some offer graphical tools to simplify the update process. Users should consult their distribution documentation to ensure compatibility and stability during kernel updates.
[Important] Ensuring data integrity cannot be overstated. Before beginning the conversion process, back up all critical data, including system files, user data, and configuration files. Tools like rsync, tar, and external backup services can be utilized. Also before updating, verify that the new kernel version supports your current hardware and Ubuntu installation. This ensures that the system will remain stable and usable after the update.
How to Check Current Linux Kernel Version?
You can easily check the current Linux kernel version using a few simple commands in the terminal. There are two commands in Linux to check the Linux Kernel version directly:
uname -r
cat /proc/version
Both these commands will display the current kernel version where cat /proc/version
command will display detailed information about the current kernel.
In the output, the first three numeric values together represent the kernel version, which is 5.15.0
. The numeric value between the hyphens indicates the build number, and “generic” is the specific kernel flavor name.
You can check the supported Kernels for your specific Ubuntu OS via https://ubuntu.com/security/livepatch/docs/livepatch/reference/kernels
How to Update Kernel Using the APT Package Manager?
Updating the Linux kernel using the APT package manager is preferred for its simplicity, security, and reliability. APT automates the update process, resolves dependencies, and ensures updates come from trusted sources, thereby reducing the risk of instability. This method seamlessly integrates with overall system management, making it a convenient and safe choice for maintaining up-to-date kernels.
To update and upgrade the kernel using the APT Package manager, open the terminal and execute the command:
sudo apt update && sudo apt upgrade -y
This command refreshes the list of available packages and their versions and upgrades all upgradable packages, including the kernel, to their latest versions. Then reboot the system to apply the new kernel. To update execute the command:
sudo reboot
After reboot, check again the output values of the command “uname -r
” or “cat /proc/version
” to see the current upgraded kernel version.
How to Manually Update Kernel? (Advanced Method)
To upgrade to the latest kernel, you can follow a manual upgrade method that involves selecting and installing a new kernel using Mainline. Mainline kernels are released directly by the Linux kernel organization and often include newer features that aren’t yet available in the official Ubuntu repositories. However, these kernels may not be as stable as those extensively tested by the Ubuntu team. Therefore, limited support is available for any issues that arise from using mainline kernels, so there are risks involved with this procedure.
To manually update the kernel, first, install the software-properties-common
package and then add the mainline PPA to your system with the command:
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:cappelikan/ppa
Now, it will be possible to install the mainline kernel after updating the system:
sudo apt update -y
sudo apt install mainline -y
If successfully installed, you can open the mainline application by executing the command:
sudo mainline
This will open the mainline application, here you can tick the kernel you need and click the “Install” button to install it.
Ensure to reboot the machine after installing the right kernel from the mainline. This way you can update the kernel via the Mainline Application.
Sometimes the mainline installation via sudo apt install mainline -y
will result in an error: E: “Unable to locate package mainline”. If this is your case, you can try an alternative installation method, which involves manually downloading and installing the mainline kernel packages from the Ubuntu mainline kernel archive.
For that first check the Ubuntu Mainline Kernel Archive website by visiting >> https://kernel.ubuntu.com/mainline/
Then choose the kernel you wish to use for your machine.
After checking your machine’s architecture by running the command: uname -m
, select the correct kernel for your machine architecture from the list.
uname -m
For example; the output of uname -m
on my machine is x86_64
. Therefore I need to choose arm64 from the Mainline kernel website for kernel installation.
You need to install: linux-headers, linux-image, and linux-modules from the list for your machine architecture.
To download those to your machine use the wget
tool.
wget <kernel download URL>
Thereafter downloading, install them with dpkg
utility:
sudo dpkg -i linux-headers-*.deb linux-image*.deb linux-modules-*.deb
Subsequently, update the grub config and then reboot to finalize the changes.
sudo update-grub
sudo reboot
You can then check the status of the change with the command uname -r
after reboot.
How to Remove Old Kernels from Linux?
Linux users should remove outdated kernels to maintain system cleanliness and save up disk space, particularly if they are utilizing a boot partition with a small amount of available space.
The “apt autoremove
” command can be used to automatically remove unused kernels, including outdated kernels.
sudo apt autoremove
Alternatively, you can manually remove them by listing and removing them one by one.
For that first, you need to list all installed kernels using the following command:
dpkg --list | grep linux-image
This command will list all the kernels available in the machine. Now you can remove them one by one with the command:
sudo apt-get remove linux-image-VERSION-generic
Replace VERSION
with the version number of the kernel you wish to remove. For example:
On successful removal update the grub and reboot the system to finalize the changes.
sudo update-grub
sudo reboot
It’s a good practice to keep at least one older kernel that you know works well. This can be helpful if you encounter issues with the latest kernel.
By following the steps in this knowledge base, you can successfully update to the new kernel version as well as remove unused kernels to free some space in the boot partition, which can bring improvements in performance, security, and hardware support.
Frequently Asked Questions (FAQs)
What should I do before updating the Linux kernel?
Answer: Before you update the Linux kernel, back up your data. Although updating is generally safe, something might still go wrong. By backing up your data, you ensure that you can restore your system if necessary.
Is it safe to update the Linux kernel using third-party repositories?
Answer: Third-party repositories can offer newer kernel versions, but they might not always provide the same level of stability and security as the official Ubuntu repositories. If you use a third-party repository, ensure it is reputable and regularly maintained.
Can I revert to an older kernel if the new one causes issues?
Answer: Yes, Ubuntu keeps the old kernels when you install new ones. You can select an older kernel from the GRUB menu at boot time. This helps if the new kernel causes issues with your hardware or software.
Why do I need to disable Secure Boot in the BIOS settings before updating a third-party kernel?
Answer: Secure Boot is a security standard that ensures your PC boots using only software trusted by the PC manufacturer. When you install a new kernel manually, especially one not signed by Ubuntu’s key, you may need to disable Secure Boot to allow the system to boot with an unsigned kernel. If you prefer not to disable Secure Boot, you will need to manually sign the kernel using your own keys.
Should I upgrade my kernel manually?
Answer: Generally, it’s not recommended to manually upgrade kernels unless you need support for specific hardware not currently supported by your existing kernel. Manual upgrades can compromise system stability and security if not handled carefully. It’s often better to stick with kernel versions provided through the official Ubuntu repositories, as they undergo thorough testing and support.
What are the risks of installing kernels from outside the main Ubuntu repositories?
Answer: Kernels installed from outside the main Ubuntu repositories may lack support and won’t receive security updates from the Ubuntu security team. This exposes your system to security vulnerabilities and stability issues. If you face problems while using an unsupported kernel, Ubuntu support forums and other users may suggest reverting to a supported kernel from the official repositories.
Is there any way to upgrade the kernel without rebooting?
Upgrading the Linux kernel typically mandates a reboot for the new kernel version to take effect since the kernel constitutes the core of the operating system. Nonetheless, there exists a technology called live patching that facilitates updating the kernel without rebooting. This technology proves particularly useful for servers where minimizing downtime is essential.
Also Read:
How to Tune Linux Kernel without Reboot