When stability or performance issues, such as system crashes, stuttering, or memory leaks, occur in the operating system kernel of a Linux Elastic Compute Service (ECS) instance, you can upgrade the operating system kernel of the ECS instance to resolve the issues. You can also upgrade the operating system kernel of an ECS instance to obtain new kernel features.
Precautions
The kernel upgrade operation is a complex and high-risk operation that may lead to system instability or incompatibility issues. Before you upgrade the kernel, we recommend that you back up important data. Make sure that you fully understand the upgrade procedure and the impacts of the upgrade operation. Proceed with caution.
Procedure
This section describes how to upgrade the operating system kernel of an ECS instance. In this example, an ECS instance that runs one of the following operating systems is used: Alibaba Cloud Linux, CentOS, Ubuntu and Debian.
Alibaba Cloud Linux and CentOS
(Optional) Create snapshots for the disks that are attached to the ECS instance to back up data. For more information, see Create a snapshot.
Connect to the ECS instance. For more information, see Connect to a Linux instance by using a password or key.
View the current operating system kernel version of the instance
uname -r
Check whether a kernel version is available for upgrade.
sudo yum list kernel
If no kernel version is available for upgrade, we recommend that you change the operating system to Alibaba Cloud Linux 3. For more information, see Migrate and upgrade the operating system of an ECS instance or Replace the operating system (system disk) of an instance.
If a kernel version is available for upgrade, perform the following steps to upgrade the kernel:
Run the following command to check whether the
initrd
orinitramfs
file in the system contains the virtio-blk and xen-blkfront drivers:sudo lsinitrd /boot/initramfs-`uname -r`.img | grep -E 'virtio|xen'
If a command output similar to the following one is returned, the file contains the virtio-blk and xen-blkfront drivers. Otherwise, the file does not contain the virtio-blk or xen-blkfront driver.
-rw-r--r-- 1 root root 83312 Jul 22 10:38 usr/lib/modules/4.19.91-27.5.al7.x86_64/kernel/drivers/block/xen-blkfront.ko -rw-r--r-- 1 root root 68016 Jul 22 10:38 usr/lib/modules/4.19.91-27.5.al7.x86_64/kernel/drivers/net/xen-netfront.ko
If the file does not contain the
virtio-blk
orxen-blkfront
driver, run the following command to add the drivers to the system. If the file contains the drivers, skip this step.sudo sh -c 'echo 'add_drivers+="xen-blkfront virtio_blk"' >> /etc/dracut.conf.d/virt-drivers.conf'
Upgrade the operating system kernel.
sudo yum update -y
Update the configuration file of GRand Unified Bootloader (GRUB) for the instance to load the new kernel version on startup.
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Restart the instance.
sudo reboot
Check whether the new kernel version is installed.
uname -r
If the new kernel version is returned, the kernel upgrade is successful.
Ubuntu and Debian
(Optional) Create snapshots for the disks that are attached to the ECS instance to back up data. For more information, see Create a snapshot.
Connect to the ECS instance. For more information, see Connect to a Linux instance by using a password or key.
Check the current operating system kernel version of the instance to determine whether an upgrade is required.
uname -r
Update the system software package list and check whether a kernel version is available for upgrade.
sudo apt update apt-cache search linux-image
If no kernel version is available for upgrade, we recommend that you change the operating system to higher version. For more information, see Replace the operating system (system disk) of an instance.
If a kernel version is available for upgrade:
Run the following command to upgrade the kernel:
sudo apt-get install linux-image-<Kernel package name>
(Optional) If you are using Ubuntu, you need to upgrade additional kernel modules for the operating system.
sudo apt-get install linux-modules-extra-<Kernel package name>
Take Ubuntu 20.04 for example, run the following commands to upgrade the kernel version to 5.15.0 and the additional kernel modules:
sudo apt update apt-cache search linux-image | grep '5.15' | grep generic sudo apt-get install linux-image-5.15.0-122-generic sudo apt-get install linux-modules-extra-5.15.0-122-generic
Update the GRUB configuration file for the instance to load the new kernel version on startup.
sudo update-grub
Restart the instance and refresh the Workbench page.
sudo reboot
Check whether the new kernel version is installed.
uname -r
If the new kernel version is returned, the kernel upgrade is successful.