How to Install and Set a Specific Version of the Linux Kernel
When using a Linux system, there may be times when you need to install and set a specific version of the kernel to meet particular requirements. This article will guide you through installing a specific kernel version, checking and setting the kernel order, and locking the current kernel version to prevent automatic updates.
Step 1: Install the Specific Version of the Linux Kernel
We will use version 6.2.0-39-generic as an example. To install the kernel and its related modules and headers, execute the following commands:
sudo apt install -y linux-image-6.2.0-39-generic
sudo apt install -y linux-headers-6.2.0-39-generic
sudo apt install -y linux-modules-6.2.0-39-generic
sudo apt install -y linux-modules-extra-6.2.0-39-generic
These commands will install the kernel image, headers, modules, and extra modules to ensure full support for this kernel version.
Step 2: List Linux-Related Packages in the System
To confirm the installed Linux-related packages and their installation status, use the following command:
dpkg --get-selections | grep linux
To specifically list all installed Linux kernel image packages, use:
dpkg --list | grep linux-image
Step 3: Check the Currently Used Kernel Version
To see the current kernel version that the system is using, execute:
uname -rs
Step 4: Set the Default Boot Kernel Version
To set a specific kernel version as the default at boot, we need to check the kernel entries in the GRUB boot menu. First, view the GRUB configuration file for kernel entries:
cat /boot/grub/grub.cfg | grep menuentry
This command will list all available kernel entries. For example, the output might be:
Find the menuentry for the desired kernel version and note its position in the menu, starting the count from 0. For example, if Linux 6.2.0-39-generic is the fifth entry, its position is 4.
Next, edit the GRUB configuration file:
sudo nano /etc/default/grub
Find the line GRUB_DEFAULT and set it as follows:
Here, 1>4 indicates the target kernel's position in the submenu.
Update the GRUB configuration to apply the changes:
sudo update-grub
Step 5: Lock the Current Kernel Version to Prevent Automatic Updates
To ensure that the current running kernel version is not replaced during system updates, use the following commands to lock the current kernel version:
sudo apt-mark hold linux-image-6.2.0-39-generic
sudo apt-mark hold linux-modules-6.2.0-39-generic
sudo apt-mark hold linux-modules-extra-6.2.0-39-generic
sudo apt-mark hold linux-headers-6.2.0-39-generic