All Products
Search
Document Center

Elastic Compute Service:Install the virtio driver

Last Updated:May 15, 2026

Install and load the virtio driver in your custom Linux image so that ECS instances can detect virtualized storage and network devices at boot.

Procedure

The following flowchart shows how to install the virtio driver in a Linux system:

image

Procedure

Check whether the kernel supports virtio

  1. On the virtual machine where you create the image, run the following command to check whether the kernel supports virtio:

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

    Sample output:

    virtio_driver

  2. Analyze the output.

    Check the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters:

    • If the parameter values are y: The virtio driver is compiled into the kernel and loads automatically at startup. No further action is required.

    • 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. Add the virtio driver to the temporary file system.

    • If the parameters do not appear: The virtio driver is not installed. Manually install the virtio driver.

Add the virtio driver to the temporary file system

If the kernel has CONFIG_VIRTIO_BLK=m or CONFIG_VIRTIO_NET=m but these modules are not in the initramfs, the system may fail to load virtio at startup.

  1. If CONFIG_VIRTIO_BLK or CONFIG_VIRTIO_NET is m, run one of the following commands to check whether the virtio driver is in the initramfs:

    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

    • If the output contains virtio_blk.ko and virtio_net.ko, the virtio driver is already in the initramfs. No further action is required.

    • If the output is missing virtio_blk.ko or virtio_net.ko, or contains only one of virtio_blk.ko and virtio_net.ko, proceed to the next step.

  2. Add the virtio driver to the initramfs.

    CentOS series

    Applicable to CentOS 6, Anolis OS 7, AlmaLinux 8, Fedora 33, or later with kernel version later than 2.6.24 (run uname -r to check).

    1. Open the dracut.conf file:

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

      add_drivers+="virtio_blk virtio_net"

      Press Esc, enter :wq, and press Enter 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

      Run echo $? to verify a return value of 0. Run the

      lsinitrd /boot/initramfs-$(uname -r).img | grep virtio command to verify that virtio is in the initramfs.

    Debian series

    1. Open the modules file:

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

      virtio_blk
      virtio_net

      Press Esc, enter :wq, and press Enter 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. Regenerate initrd:

      update-initramfs -u
      Note

      Run echo $? to verify a return value of 0. Run the lsinitramfs /boot/initrd.img-$(uname -r)|grep virtio command to verify that virtio is in the initramfs.

    SUSE series

    • Versions earlier than SUSE 12 SP1 or openSUSE 13

      1. Open the kernel file:

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

        INITRD_MODULES="virtio_blk virtio_net"

        Press Esc, enter :wq, and press Enter 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 i to enter Insert mode and add the following content:

        add_drivers+="virtio_blk virtio_net"

        Press Esc, enter :wq, and press Enter 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

    Run echo $? to verify a return value of 0. Run the

    lsinitrd /boot/initrd-$(uname -r)|grep virtio command to verify that virtio is in the initramfs.

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 CentOS. Modify the commands based on your kernel version.

  1. Install the components required for kernel compilation:

    yum install -y ncurses-devel gcc make wget
  2. Query the kernel version. 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 and find the download URL for your kernel version.

    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 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. 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 the make menuconfig command fails, install the missing components. For example:

    yum install  ncurses-devel
    yum install  bison
    yum install  flex
  2. Complete virtio-related configurations on the following page:

    Note

    Selecting configurations with asterisks (*) compiles the virtio driver into the kernel. Selecting m compiles it as a module.

    1. Configure the Virtualization options.

      1. Select Virtualization and press Enter.Select_Virtualization

      2. Verify 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, select Processor type and features, and press Enter.

      2. Select Paravirtualized guest support and press Enter.guest_support

      3. Verify that KVM paravirtualized clock and KVM Guest support are selected.KVM

    3. Configure the Device Drivers options.

      1. Go back to the main menu, select Device Drivers, and press Enter.

      2. Select Block devices and press Enter.

      3. Verify that Virtio block driver is selected.Virtio_block

      4. Go back to Device Drivers, select Network device support, and press Enter.

      5. Verify that Virtio network driver is selected.Virtio_network

    4. Press Esc to exit the kernel configuration window. Select Yes to save the .config file.

    5. Check whether the virtio-related configurations are complete.

    6. (Optional) If virtio configurations are incomplete, 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 lists virtio-related files such as virtio_blk, virtio_pci, and virtio_console.确认结果