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. The source server can be a physical server, a virtual machine, or a cloud web host. If the source server is not installed with the virtio driver, the created ECS instance may not be able to start. To avoid this problem, 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 Step 2: Repair the temporary file system.

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 grep -i virtio /boot/config-$(uname -r) command to check whether the kernel of the current operating system supports the virtio driver.

    Check the CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters.

    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 Step 3: Download the kernel installation package and Step 4: Compile the kernel.
    The parameter values are both m. Go to the next step.
    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 lsinitrd /boot/initramfs-$(uname -r).img | grep virtio command to check whether the virtio driver is contained in the initramfs or initrd temporary file system.
    Note
    • 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 import custom images to Alibaba Cloud.

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. Operating systems such as CentOS are used in the following examples:
  • CentOS/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 \
  • CentOS/RedHat 6/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)
  • Debian/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 The linux-4.4.24.tar.gz kernel version is used in the following example. You must modify the commands based on the kernel version of your operating system.
  1. Run the yum install -y ncurses-devel gcc make wget command to install components required to compile the kernel.
  2. Run the uname -r command to query the kernel version of your operating system. In this example, the kernel version is 4.4.24-2.a17.x86_64.
  3. Go to the Index of pub/lunix/kernel/ page to query the download link of the kernel version source code.
    The download link 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.
  4. Run the cd /usr/src/ command to switch the directory.
  5. Run the wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz command to download the installation package.
  6. Run the tar -xzf linux-4.4.24.tar.gz command to decompress the installation package.
  7. Run the ln -s linux-4.4.24 linux command to build a link.
  8. Run the cd /usr/src/linux command to switch the directory.

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
  2. When the following page is displayed, start to perform virtio-related configurations.
    Note If you select the configurations that contain asterisks (*), the virtio driver is directly 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 is to start.
    1. Select Virtualization.
      Select the Kernel-based Virtual Machine (KVM) support option.
      Processor type and features  --->
         [*] Paravirtualized guest support  --->
           --- Paravirtualized guest support
       (128)   Maximum allowed size of a domain in gigabytes
       [*]   KVM paravirtualized clock
       [*]   KVM Guest support
      Device Drivers  --->
        [*] Block devices  --->
       <M>   Virtio block driver (EXPERIMENTAL)
       -*- Network device support  --->
           <M>   Virtio network driver (EXPERIMENTAL)
    2. Press the Esc key to exit the kernel configuration window and save the .config file.
    3. Check whether virtio-related configurations are complete. For more information, see Step 1: Check whether the operating system kernel supports the virtio driver.
    4. Optional:If virtio-related configurations are not complete, run the following commands to manually edit the .config file:
      make oldconfig
      make prepare
      make scripts
      make
      make install
    5. 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 and virtio_pci.virtio_console, the virtio driver is installed.

What to do next

After you install the virtio driver, you can perform the following operations: