Skip to content

Installing the Linux Kernel

Installing a Linux kernel involves either upgrading to a newer version, downgrading, or custom installing a kernel to suit specific requirements. This process can vary based on the distribution and whether you are using precompiled binaries or building the kernel from source.


1. Why Install a New Kernel?

  • Upgrades: To access the latest features, performance enhancements, or security updates.
  • Hardware Support: To enable compatibility with newer hardware.
  • Customization: To tailor the kernel for specific use cases, such as embedded systems or high-performance tasks.
  • Bug Fixes: To resolve issues in the current kernel.

2. Methods for Installing a Kernel

There are two main approaches:

  1. Precompiled Kernel Installation: Using package managers or repositories.
  2. Custom Kernel Installation: Compiling and installing a kernel from source.

3. Installing a Precompiled Kernel

3.1 Using Package Managers

Most Linux distributions provide precompiled kernels via their package managers.

Debian/Ubuntu

  • Check for Available Kernels:

apt list linux-image*

  • Install a New Kernel:

sudo apt-get install linux-image-x.y.z

  • Optional: Install Headers for Development:

sudo apt-get install linux-headers-x.y.z

  • Reboot the System:

sudo reboot

RHEL/CentOS

  • List Available Kernels:

yum list available kernel

  • Install a New Kernel:

sudo yum install kernel-x.y.z

  • Reboot the System:

sudo reboot

Fedora

  • Install the Latest Kernel:

sudo dnf update kernel

  • Reboot the System:

sudo reboot


3.2 Using Third-Party Tools

Some distributions offer tools for managing kernel updates, such as UKUU (Ubuntu Kernel Update Utility) for Ubuntu systems:

  • Install UKUU:

sudo add-apt-repository ppa:teejee2008/ppa

sudo apt-get update

sudo apt-get install ukuu

  • Launch UKUU and install the desired kernel version.

4. Installing a Custom Kernel from Source

4.1 Download the Kernel Source

  1. Download the kernel source code from kernel.org.
  2. Extract the source code:

tar -xvf linux-x.y.z.tar.xz

cd linux-x.y.z

4.2 Configure the Kernel

  • Copy the current kernel configuration:

cp /boot/config-$(uname -r) .config

  • Configure the kernel:

make menuconfig

4.3 Build the Kernel

  • Compile the kernel:

make -j$(nproc)

  • Compile the kernel modules:

make modules

4.4 Install the Kernel

  • Install modules:

sudo make modules_install

  • Install the kernel:

sudo make install

4.5 Update Bootloader

  • Update GRUB to recognize the new kernel:

sudo update-grub

4.6 Reboot the System

  • Reboot and select the new kernel from the GRUB menu:

sudo reboot


5. Verifying the Installed Kernel

  • After rebooting, verify the running kernel:

uname -r

  • Check installed kernels:

dpkg –list | grep linux-image   # Debian/Ubuntu

rpm -qa | grep kernel            # RHEL/CentOS


6. Removing an Old Kernel

To save disk space or avoid confusion, you may remove unused kernels.

6.1 Listing Installed Kernels

  • Debian/Ubuntu:

dpkg –list | grep linux-image

  • RHEL/CentOS:

rpm -qa | grep kernel

6.2 Removing Kernels

  • Debian/Ubuntu:

sudo apt-get remove linux-image-x.y.z

  • RHEL/CentOS:

sudo yum remove kernel-x.y.z


7. Best Practices for Kernel Installation

  1. Backup Data: Always back up important data before installing or upgrading a kernel.
  2. Test in a Virtual Environment: Test custom kernels in a VM or non-critical system.
  3. Keep a Known Working Kernel: Do not remove the currently active kernel until the new one is tested.
  4. Use LTS Kernels for Stability: For production systems, prefer Long-Term Support (LTS) kernels.
  5. Monitor Logs: After installation, check logs for errors:

dmesg | less


Installing a Linux kernel, whether precompiled or custom-built, is a straightforward process if done with careful planning and preparation. By following these steps, you can ensure a successful installation and minimal downtime.