All Products
Search
Document Center

Elastic Compute Service:Install the virtio driver

Last Updated:Oct 22, 2025

The virtio driver is a high-performance I/O driver required for virtualized environments. To ensure your custom Linux images can boot properly on Alibaba Cloud, you must install the virtio driver and include it in the temporary file system. Otherwise, Elastic Compute Service (ECS) instances created from your image may fail to start because they cannot detect the virtualized storage and network devices. This topic guides you through installing the virtio driver in your Linux.

Operation flow

The operation flow for installing the virtio driver in a Linux system is as follows:

image

Procedure

Check whether the system kernel supports the virtio driver

  1. In the virtual machine where you are creating the image, run the following command to check whether the current system kernel supports the virtio driver. This helps you determine whether to install the virtio driver for the custom image or add the driver to a temporary file system.

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

    The following command output is returned:

    virtio_driver

  2. Analyze the command output.

    Check the CONFIG_VIRTIO_BLK (virtio block device driver) and CONFIG_VIRTIO_NET (virtio network device driver) parameters in the command output:

    • If the parameter values are y: The system has correctly installed the virtio driver, and the driver is compiled into the kernel. The driver will be loaded automatically at startup. You do not need to continue with the steps in this topic.

    • If the parameter values are m or one parameter value is y and the other is m: The virtio driver exists as a kernel module. You only need to add the virtio driver to the temporary file system.

    • If the parameters do not appear: The system does not have the virtio driver installed. You need to manually install the virtio driver.

Add the virtio driver to the temporary file system

When the kernel has enabled CONFIG_VIRTIO_BLK=m or CONFIG_VIRTIO_NET=m, but these modules have not been added to the temporary file system (initramfs), the system may fail to load the virtio driver at startup, causing the virtual machine to fail to detect them.

  1. If the values of the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters are m or one parameter value is y and the other is m, run one of the following commands to check whether the virtio driver is added to a temporary file system.

    CentOS series

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

    image

    Debian series

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

    image

    SUSE series

    lsinitrd /boot/initrd-$(uname -r)|grep virtio

    image

    • As shown in the preceding figures, if the output contains virtio_blk.ko and virtio_net.ko information, the virtio driver is already added to the temporary file system. You do not need to continue with the steps in this topic.

    • If the output does not contain virtio_blk.ko and virtio_net.ko information, or contains only one of virtio_blk.ko and virtio_net.ko, you need to proceed to the next step to add the virtio driver to the temporary file system.

  2. Add the virtio driver to the temporary file system.

    CentOS series

    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 (you can run the uname -r command to check the kernel version), perform the following operations to add the virtio driver to the temporary file system.

    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 CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET values 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, write only add_drivers+="virtio_net" to the file.

    3. Run the following command to regenerate initrd:

      dracut -f
      Note

      After you run the command, you can run the echo $? command to check whether a value of 0 is returned. If so, 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 series

    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 CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET values 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, add only virtio_net to the file.

    3. Run the following command to regenerate initrd:

      update-initramfs -u
      Note

      After you run the command, you can run the echo $? command to check whether a value of 0 is returned. If so, 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 series

    • Versions earlier than SUSE 12 SP1 or openSUSE 13

      1. 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 CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET values 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, write only INITRD_MODULES="virtio_net" to the file.

      3. Regenerate initrd:

        mkinitrd
    • SUSE 12 SP1, OpenSUSE 13, or later

      1. 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 CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET values 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, write only add_drivers+="virtio_net" to the file.

      3. Regenerate initrd:

        dracut -f
    Note

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

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

Manually 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 in the CentOS operating system. Modify the commands based on the kernel version of your operating system.

  1. Install the components required for kernel compilation:

    yum install -y ncurses-devel gcc make wget
  2. 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 Linux kernel list page to find the download URL of the corresponding kernel version source code.

    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.

    download

  4. Download the installation package:

    cd /usr/src/
    wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz
  5. Decompress the installation package and create a symbolic link:

    tar -xzf linux-4.4.24.tar.gz
    ln -s linux-4.4.24 linux
    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 appears when you run the make menuconfig command, troubleshoot the issue based on it. 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. Complete virtio-related configurations on the following page:

    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.

    1. Configure the Virtualization options.

      1. Press the spacebar key to select Virtualization, and then press the Enter key to view the 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 options.

      2. Press the spacebar key to select Paravirtualized guest support, and then press the Enter key to view the 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 options.

      2. Press the spacebar key to select Block devices, and then press the Enter key to view the options.

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

      4. Go back to the Device Drivers option list, press the up and down arrow keys to select Network device support, and then press the Enter key to view the 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 the 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. 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.确认结果