All Products
Search
Document Center

Elastic Compute Service:Install the virtio driver

Last Updated:Apr 09, 2024

Only custom images whose operating system kernels support the virtio driver can be imported to Alibaba Cloud Elastic Compute Service (ECS) and then be used to create ECS instances that can start. When you create a custom image based on the data of a source server or import a custom image, make sure that the virtio driver is installed in the image and added to a temporary file system. If the virtio driver is not installed, install the driver.

You can perform the following steps to check whether the operating system kernel of the source server supports the virtio driver and take action based on the check result:

  1. Check whether the operating system kernel of your source server supports the virtio driver.

  2. Perform the following operations based on the check result:

Check whether the operating system kernel of your source server supports the virtio driver

Run the following command to check whether the operating system kernel of your source server supports the virtio driver, and determine whether to install the virtio driver for the custom image or whether to add the driver to a temporary file system.

grep -i virtio /boot/config-$(uname -r)

virtio_driver

View the command output

Check the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters in the command output.

  • If the parameter values are y, the virtio driver is installed as expected. Perform the operations that are described in the References section of this topic.

  • If the parameters do not exist, the virtio driver is not installed. Install the driver. For more information, see the Install the virtio driver section in this topic.

  • If the parameter values are m or if one parameter value is y and the other parameter value is m, the virtio driver is supported. Perform one of the following operations:

    • If the parameter values are m, the virtio driver is supported. Run one of the following commands to check whether the virtio driver is added to a temporary file system.

    • If one parameter value is y and the other parameter value is m, the virtio driver whose value is y is compiled into the kernel and installed as expected. Run one of the following commands to check whether the virtio driver whose value is m is added to a temporary file system.

    CentOS series

    lsinitrd /boot/initramfs-$(uname -r).img | grep virtio

    image

    • If the command output similar to the output shown in the preceding figure is returned, the virtio driver is added to a temporary file system. In this case, perform the operations that are described in the References section of this topic.

    • If the virtio driver is not added to a temporary file system, perform the operations that are described in the Add the virtio driver to a temporary file system section of this topic. If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only check whether the virtio driver whose value is m is added to a temporary file system.

    Ubuntu or Debian series

    lsinitramfs /boot/initrd.img-$(uname -r)|grep  virtio

    image

    • If the command output similar to the output shown in the preceding figure is returned, the virtio driver is added to a temporary file system. In this case, perform the operations that are described in the References section of this topic.

    • If the virtio driver is not added to a temporary file system, perform the operations that are described in the Add the virtio driver to a temporary file system section of this topic. If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only check whether the virtio driver whose value is m is added to a temporary file system.

Add the virtio driver to a temporary file system

If the operating system kernel of your source server supports the virtio driver but the virtio driver is not added to a temporary file system, add the driver to a temporary file system. Run one set of the following commands based on the operating system of your source server:

CentOS 6, Anolis OS 7, AlmaLinux 8, or Fedora 33

If the operating system version is CentOS 6, Anolis OS 7, AlmaLinux 8, Fedora 33, or later and the kernel version is later than 2.6.24, run the following commands to repair the temporary file system. You can run the uname -r command to check the kernel version.

  1. Run the following command to open the dracut.conf file:

    vim /etc/dracut.conf
  2. Press the I key to enter the Insert mode and add the following content to the file:

    add_drivers+="virtio_blk virtio_net"

    Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

    Note

    If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only add the virtio driver whose value is m to the file. For example, if the value of the CONFIG_VIRTIO_NET parameter is m, you only need to write add_drivers+="virtio_net" to the file.

  3. Run the following command to regenerate initrd:

    dracut -f
    Note

    After the command is run, you can run the echo $? command to check whether a value of 0 is returned. If the value of 0 is returned, initrd is regenerated as expected. You can also run the

    lsinitrd /boot/initramfs-$(uname -r).img | grep virtio command to check whether the virtio driver is added to the temporary file system as expected.

Debian or Ubuntu

  1. Run the following command to open the modules file:

    vim /etc/initramfs-tools/modules
  2. Press the I key to enter the Insert mode and add the following content to the file:

    virtio_blk
    virtio_net

    Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

    Note

    If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only add the virtio driver whose value is m to the file. For example, if the value of the CONFIG_VIRTIO_NET parameter is m, you only need to add virtio_net to the file.

  3. Run the following command to regenerate initrd:

    update-initramfs -u
    Note

    After the command is run, you can run the echo $? command to check whether a value of 0 is returned. If the value of 0 is returned, initrd is regenerated as expected. You can also run the lsinitramfs /boot/initrd.img-$(uname -r)|grep virtio command to check whether the virtio driver is added to the temporary file system as expected.

SUSE or openSUSE

  • Versions earlier than SUSE 12 SP1 or openSUSE 13

    1. Run the following command to open the kernel file:

      vim /etc/sysconfig/kernel
    2. Press the I key to enter the Insert mode and add the following content to the file:

      INITRD_MODULES="virtio_blk virtio_net"

      Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

      Note

      If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only add the virtio driver whose value is m to the file. For example, if the value of the CONFIG_VIRTIO_NET parameter is m, you only need to write INITRD_MODULES="virtio_net" to the file.

    3. Run the following command to regenerate initrd:

      update-initramfs -u
  • SUSE 12 SP1, OpenSUSE 13, or later

    1. Run the following command to open the dracut.conf file:

      vim /etc/dracut.conf
    2. Press the I key to enter the Insert mode and add the following content to the file:

      add_drivers+="virtio_blk virtio_net"

      Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

      Note

      If one of the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters is y and the other is m, you need to only add the virtio driver whose value is m to the file. For example, if the value of the CONFIG_VIRTIO_NET parameter is m, you only need to write add_drivers+="virtio_net" to the file.

    3. Run the following command to regenerate initrd:

      dracut -f
Note

After the command is run, you can run the echo $? command to check whether a value of 0 is returned. If the value of 0 is returned, initrd is regenerated as expected. You can also run the

lsinitrd /boot/initramfs-$(uname -r).img | grep virtio command to check whether the virtio driver is added to the temporary file system as expected.

Install the virtio driver

Note

For Red Hat and CentOS 5, we recommend that you upgrade the kernel version to 5.11 before you install the virtio driver.

Step 1: Download the kernel installation package

Note

In this example, the linux-4.4.24.tar.gz kernel installation package is used. You must modify the commands based on the kernel version of your operating system.

  1. Run the following command to install the components that are required to compile the kernel:

    yum install -y ncurses-devel gcc make wget
  2. Run the following command to query the kernel version of your operating system. In this example, the kernel version is 4.4.24-2.al7.x86_64.

    uname -r

    kernel_version

  3. Go to the Index of /pub/linux/kernel/ page to query the download URL of the kernel version repository.

    In this example, the download URL of linux-4.4.24.tar.gz is https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz, as shown in the following figure.

    download

  4. Run the following command to switch the directory:

    cd /usr/src/
  5. Run the following command to download the installation package:

    wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz
  6. Run the following command to decompress the installation package:

    tar -xzf linux-4.4.24.tar.gz
  7. Run the following to create a symbolic link:

    ln -s linux-4.4.24 linux
  8. Run the following command to switch the directory:

    cd /usr/src/linux

Step 2: Compile the kernel

  1. Run the following commands in sequence to compile the kernel:

    make mrproper
    symvers_path=$(find /usr/src/ -name "Module.symvers")
    test -f $symvers_path && cp $symvers_path .
    cp /boot/config-$(uname -r) ./.config
    make menuconfig
    Note

    If an error message is displayed when the make menuconfig command is run, you can troubleshoot the issue based on the message. For example, if the ncurses-devel, bison, and flex components are not installed, you can run the following commands in sequence to install the components:

    yum install  ncurses-devel
    yum install  bison
    yum install  flex
  2. Make virtio-related configurations when the following page is displayed.

    Note

    If you select the configurations that contain asterisks (*), the virtio driver is compiled into the kernel. If you select configurations that contain m, the virtio driver is compiled into a module and the module is inserted into the kernel when the driver starts.

    1. Configure the Virtualization options.

      1. Press the spacebar key to select Virtualization and press the Enter key to view the list of options.Select_Virtualization

      2. Check that the Kernel-based Virtual Machine (KVM) support option is selected.Select_KVM

    2. Configure the Processor type and features options.

      1. Go back to the main menu, press the up and down arrow keys to select Processor type and features, and then press the Enter key to view the list of options.

      2. Press the spacebar key to select Paravirtualized guest support and press the Enter key to view the list of options.guest_support

      3. Check that the KVM paravirtualized clock and KVM Guest support options are selected.KVM

    3. Configure the Device Drivers options.

      1. Go back to the main menu, press the up and down arrow keys to select Device Drivers, and then press the Enter key to view the list of options.

      2. Press the spacebar key to select Block devices and press the Enter key to view the list of options.

      3. Check that the Virtio block driver option is selected.Virtio_block

      4. Go back to the list of Device Drivers options, press the up and down arrow keys to select Network device support, and then press the Enter key to view the list of options.

      5. Check that the Virtio network driver option is selected.Virtio_network

    4. Press the Esc key to exit the kernel configuration window and select Yes at the prompt to save the .config file.

    5. Check whether virtio-related configurations are complete.

    6. (Optional) If virtio-related configurations are incomplete, run the following commands in sequence to modify the .config file:

      make oldconfig
      make prepare
      make scripts
      make
      make install
    7. Run the following commands to check whether the virtio driver is installed:

      find /lib/modules/"$(uname -r)"/ -name "virtio*" | grep -E "virtio*"
      grep -E "virtio*" < /lib/modules/"$(uname -r)"/modules.builtin

      If the virtio driver is installed, one of the command outputs contains a list of virtio-related files, such as virtio_blk, virtio_pci, and virtio_console, as shown in the following figure.确认结果

References

After the virtio driver is installed in the Linux operating system, you can perform the following operations: