All Products
Search
Document Center

:Upgrade the operating system kernel of a Linux ECS instance

Last Updated:Mar 27, 2024

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 a CentOS or Debian operating system is used.

CentOS

  1. (Optional) Create snapshots for the disks that are attached to the ECS instance to back up data. For more information, see Create a snapshot for a disk.

  2. Connect to the ECS instance. For more information, see Connect to a Linux instance by using a password or key.

  3. View the current operating system kernel version of the instance

    uname -r
  4. 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 2 or 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:

      1. Run the following command to check whether the initrd or initramfs 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
      2. If the file does not contain the virtio-blk or xen-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'
  5. Upgrade the operating system kernel.

    sudo yum update -y
  6. 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
  7. Restart the instance.

    sudo reboot
  8. Check whether the new kernel version is installed.

    uname -r

    If the new kernel version is returned, the kernel upgrade is successful.

Debian

  1. (Optional) Create snapshots for the disks that are attached to the ECS instance to back up data. For more information, see Create a snapshot for a disk.

  2. Connect to the ECS instance. For more information, see Connect to a Linux instance by using a password or key.

  3. Check the current operating system kernel version of the instance to determine whether an upgrade is required.

    uname -r
  4. 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 Alibaba Cloud Linux 2 or Alibaba Cloud Linux 3. 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 <Kernel package name>
  5. Update the GRUB configuration file for the instance to load the new kernel version on startup.

    sudo update-grub
  6. Restart the instance and refresh the Workbench page.

    sudo reboot
  7. Check whether the new kernel version is installed.

    uname -r

    If the new kernel version is returned, the kernel upgrade is successful.