In some scenarios, you may want to create a custom image based on the operating system data of a source server, import the image to Alibaba Cloud, and then create an Elastic Compute Service (ECS) instance from the image. This source server can be a physical server, a virtual machine, or a cloud host. If the source server is not installed with the virtio driver, the created ECS instance may be unable to start. To prevent this issue, you must check whether the virtio driver is installed on the source server before you import a custom image to Alibaba Cloud.

Background information

You can determine whether you need to manually install the virtio driver based on the operating system of your source server.
Operating system Description
  • Windows Server 2008
  • Windows Server 2012
  • Windows Server 2016
  • Windows Server Version **** (Semi-Annual Channel)
  • Windows Server 2019 and later
  • CentOS 6, CentOS 7, CentOS 8, and later
  • Ubuntu 12, Ubuntu 14, Ubuntu 16, Ubuntu 18, Ubuntu 20, and later
  • Debian 7, Debian 8, Debian 9, Debian 10, and later
  • SUSE 11, SUSE 12, SUSE 15, and later
When you import a custom image created from a source server that runs one of the operating systems listed on the left, Alibaba Cloud automatically adds the virtio driver to the image. You do not need to manually install the virtio driver on the source server before you create the custom image.

For servers that are pre-installed with the virtio driver, if the driver is not contained in the temporary file systems, you must repair the file systems. For more information, see the Step 2: Repair the temporary file system section in this topic.

Other operating systems If your source server runs a Linux-like operating system that is not contained in the preceding list, perform the following steps to install the virtio driver:
  1. Step 1: Check whether the operating system kernel supports the virtio driver
  2. Step 2: Repair the temporary file system
  3. Step 3: Download the kernel installation package
  4. Step 4: Compile the kernel

Step 1: Check whether the operating system kernel supports the virtio driver

  1. Run the following command to check whether the kernel of the current operating system supports the virtio driver:
    grep -i virtio /boot/config-$(uname -r)
    virtio_driver

    Check the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters in the command output.

    Check result Description
    The two parameters do not exist. The virtio driver is not installed on the operating system and custom images created from the source server cannot be imported to Alibaba Cloud. You must compile the kernel and install the virtio driver on the source server. For more information, see the Step 3: Download the kernel installation package and Step 4: Compile the kernel sections in this topic.
    The parameter values are both m. Proceed to the next step to check whether the virtio driver is contained in the initramfs or initrd temporary file system.
    The parameter values are both y. The virtio driver is installed on the operating system and custom images created from the source server can be imported to Alibaba Cloud. For more information, see Instructions for importing images and Import custom images.
  2. Run the following command to check whether the virtio driver is contained in the initramfs or initrd temporary file system:
    lsinitrd /boot/initramfs-$(uname -r).img | grep virtio
    temporary_fileDescription of the command output:
    • The preceding figure shows that initramfs contains the virtio_blk driver and the virtio.ko, virtio_pci.ko, and virtio_ring.ko dependencies. You can import your custom images to Alibaba Cloud. For more information, see Instructions for importing images and Import custom images.
    • If initramfs does not contain the virtio driver, you must repair the temporary file system before you can import custom images to Alibaba Cloud. For more information, see the Step 2: Repair the temporary file system section in this topic.

Step 2: Repair the temporary file system

If the check result shows that the kernel of the operating system supports the virtio driver but the initramfs or initrd temporary file system does not contain the virtio driver, you must repair the temporary file system. Run one set of the following commands based on the operating system of your source server to repair the temporary file system:
  • CentOS 8 or Red Hat 8
    mkinitrd -f --allow-missing \
                --with=virtio_blk --preload=virtio_blk \
                --with=virtio_net --preload=virtio_net \
                --with=virtio_console --preload=virtio_console \
                /boot/initramfs-$(uname -r).img $(uname -r)
  • CentOS 6, CentOS 7, Red Hat 6, or Red Hat 7
    mkinitrd -f --allow-missing \
                --with=xen-blkfront --preload=xen-blkfront \
                --with=virtio_blk --preload=virtio_blk \
                --with=virtio_pci --preload=virtio_pci \
                --with=virtio_console --preload=virtio_console \
                /boot/initramfs-$(uname -r).img $(uname -r)
  • CentOS 5 or RedHat 5
    mkinitrd -f --allow-missing \
                --with=xen-vbd  --preload=xen-vbd \
                --with=xen-platform-pci --preload=xen-platform-pci \
                --with=virtio_blk --preload=virtio_blk \
                --with=virtio_pci --preload=virtio_pci \
                --with=virtio_console --preload=virtio_console \
                /boot/initrd-$(uname -r).img $(uname -r)
  • Debian or Ubuntu
    echo -e 'xen-blkfront\nvirtio_blk\nvirtio_pci\nvirtio_console' >> \
    /etc/initramfs-tools/modules
    mkinitramfs -o /boot/initrd.img-$(uname -r)

Step 3: 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 components required for compiling 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.a17.x86_64.
    uname -r
    kernel_version
  3. Go to the Index of pub/lunix/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 4: 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 error 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 them:
    yum install  ncurses-devel
    yum install  bison
    yum install  flex
  2. When the following page is displayed, start to make virtio-related configurations.
    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 then 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.
      For more information, see the Step 1: Check whether the operating system kernel supports the virtio driver section in this topic.
    6. Optional:If virtio-related configurations are not complete, run the following commands in sequence to automatically edit 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 one of the command outputs contains virtio-related files such as virtio_blk, virtio_pci, and virtio_console, the virtio driver is installed.

What to do next

After the virtio driver is installed, you can perform the following operations: