To avoid failure in starting the Linux instances created by using the imported images of your server, virtual machines, or cloud hosts,  Import custom images an Xen (pv) or virtio driver must be installed on your on-premises image and configured before importing. Follow these steps to check whether you must install the driver manually, and then install and configure the virtio driver for a Linux server if needed.

Images requiring no manual installation

After you import images in Import custom images, if the operating systems of your image is listed in the following,  Alibaba Cloud automatically processes the virtio driver for you:

  • Windows Server 2008
  • Windows Server 2012
  • Windows Server 2016
  • CentOS 6/7
  • Ubuntu 12/14/16
  • Debian 7/8/9
  • SUSE 11/12

You can skip to recover the temporary root file system of initramfs or initrd.

Images requiring manual installation

For Linux images that are not included in the preceding list, you must install the virtio driver on-premises before importing the images.

To check the availability of virtio driver on a server
  1. Run grep -i virtio /boot/config-$(uname -r) to inspect whether the  virtio driver is already built in the kernel of your server.

    Note
    • If VIRTIO_BLK and VIRTIO_NET do not exist in the output, the virtio driver  is not built in the kernel,  and you must install and configure the virtio driver on your serverto compile and install virtio driver.
    • If the values of parameter CONFIG_VIRTIO_BLK and and parameter CONFIG_VIRTIO_NET are y, the virtio driver is already built in the kernel.You can read Notes for importing custom images Notes for importing images and import the image Import custom images.
    • If the values of parameter CONFIG_VIRTIO_BLK and and parameter CONFIG_VIRTIO_NET are m, continue to step 2.
  2. Run lsinitrd /boot/initramfs-$(uname -r).img | grep virtioto make sure  virtio driver has been complied in the temporary root file system of initramfs or initrd.

    Note
    • According to the preceding figure, the virtio_blk driver, including its dependency virtio.ko, virtio_pci.ko and  virtio_ring.ko, has been compiled in the temporary root file system initramfs. After reading Notes for importing custom images Notes for importing images, you can directly import the image Import custom images.
    • If virtio driver is unavailable in the initramfs, you must recover the temporary root file system of initramfs or initrd before importing images or migration.
To recover the temporary root file system

After checking, if the virtio driver is supported by the kernel but not compiled in the temporary root file system,  you must recover the temporary root file system. Take CentOS as an example:

  • 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)"

To compile and install virtio driver

Take Redhat server as an example:

To download the kernel package
  1. Run yum install -y ncurses-devel gcc make wget to install necessary components to compile the kernel.
  2. Run uname -r to query the kernel version of your server, such as 4.4.24-2.a17.x86_64.

  3. Visit published Linux Kernel Archives to download the source codes of kernel, for example, the download link of kernel version starting with 4.4.24 is https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz.

  4. Run cd /usr/src/ to change the directory.
  5. Run wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.24.tar.gz to download the installation package.
  6. Run tar -xzf linux-4.4.24.tar.gz to decompress the package.
  7. Run ln -s linux-4.4.24 linux to establish a link.
  8. Run cd /usr/src/linux to change the directory.
To compile the kernel
  1. Run the following commands to compile the driver into 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. Configure the corresponding settings of virtio driver in the following windows:
    Note Select *to build the driver in the kernel, select m to compile it as a module.
    1. Press the space bar to select Virtualization.

      Make sure that you have selected  the option of KVM (Kernel-based Virtual Machine).



      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 windows, and save changes to file .config according to the dialog box.
    3. Inspect whether all the corresponding settings of virtio driver  has been correctly configured or not.
    4. (Optional) If no configuration of virtio driver is settled after the inspect, run the following commands to edit the file .config manually.
      make oldconfig
      make prepare
      make scripts
      make
      make install
    5. Run the following commands to check whether the virtio driver is installed. 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
      Note If any of the output  includes virtio_blk and virtio_pci.virtio_console, your server has correctly installed the virtio driver.

Next steps

After compiling the virtio driver, You can Migrate your server to Alibaba Cloud by using Cloud Migration Tool.