Cloud server systems require Virtio driver support (including block device driver virtio_blk and network card driver virtio_net) to run properly on Tencent Cloud. To avoid instances created from imported custom images failing to start, you need to check and fix Virtio driver support in the source server before importing the image. This document uses CentOS as an example to guide you on how to check and fix Virtio driver support in the image before importing it.
Instructions
Step 1: Checking whether the kernel supports virtio drivers
Execute the following command to check whether the current kernel supports virtio drivers:
grep -i virtio /boot/config-$(uname -r)
A result similar to the following is returned:
If the returned results show that the values of CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters are m, proceed to Step 2.
If the values of CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters in the returned results are y, it indicates that the operating system includes Virtio drivers, and you can directly import your custom image to Tencent Cloud. For more details, please refer to Image Import Overview.
If the returned results do not contain information about CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET parameters, it indicates that the operating system does not support importing to Tencent Cloud. Please download and compile the kernel.
Step 2: Checking whether virtio drivers are in the temporary file system
If the parameter value in Step 1 is m, further checks are needed to confirm whether the temporary file system initramfs or initrd contains the virtio driver. Please execute the corresponding command according to the operating system:
For CentOS 6/CentOS 7/CentOS 8/Red Hat 6/Red Hat 7:
From the output, initramfs already includes virtio_blk driver, as well as its dependencies virtio.ko, virtio_pci.ko, and virtio_ring.ko. You can directly import your custom image to Tencent Cloud. For more information, see Importing Image Overview.
If initramfs or initrd does not contain virtio drivers, please proceed to Step 3.
Step 3: Reconfigure the temporary file system
If the results of Step 2 show that the temporary file system initramfs or initrd does not include the virtio driver, you need to reconfigure the temporary file system initramfs or initrd to include the virtio driver. Please choose the appropriate operation according to the operating system:
1. Execute the following command to install the components necessary for kernel compilation.
yum install -y ncurses-devel gcc make wget
2. Execute the following command to view the current version of the kernel.
uname -r
The output should resemble the following, indicating that the current kernel version is 2.6.32-642.6.2.el6.x86_64:
3. Visit the Linux Kernel Download Page and download the source code for the corresponding or closest kernel version.
For example, for kernel version 2.6.32-642.6.2.el6.x86_64, download the linux-2.6.32.tar.gz package. The download link is: https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.tar.gz.
4. Execute the following command to switch directory.
cd /usr/src/
5. Execute the following command to download the installation package.
6. Execute the following command to decompress the installation package.
tar -xzf linux-2.6.32.tar.gz
7. Execute the following command to make connection.
ln -s linux-2.6.32 linux
8. Execute the following command to switch directory.
cd /usr/src/linux
Compling the kernel
1. Execute the following commands to compile the kernel.
make mrproper
cp /boot/config-$(uname -r) ./.config
make menuconfig
Enter the "Linux Kernel vX.X.XX Configuration" interface, as shown below:
Note
If you do not enter the "Linux Kernel vX.X.XX Configuration" interface, please perform Step 18.
"Linux Kernel vX.X.XX Configuration" interface:
Press "Tab" or the "↑"/"↓" key to move the cursor.
Press "Enter" to select or execute the item selected by the cursor.
Press the spacebar to select the item where the cursor is located. An asterisk (*) indicates that it is compiled into the kernel, while an "M" indicates that it is compiled as a module.
2. Press the "↓" key to move the cursor to "Virtualization" and press the space bar to select "Virtualization".
3. Press "Enter" to enter the Virtualization details interface.
4. In the Virtualization details interface, confirm whether the Kernel-based Virtual Machine (KVM) support option is selected, as shown below:
If not selected, press the spacebar to select the "Kernel-based Virtual Machine (KVM) support" option.
5. Press "Esc" to return to the "Linux Kernel vX.X.XX Configuration" main interface.
6. Press the "↓" key to move the cursor to "Processor type and features" and press "Enter" to enter the Processor type and features details interface.
7. Press the "↓" key to move the cursor to "Paravirtualized guest support" and press "Enter" to enter the detailed interface of Paravirtualized guest support.
8. In the Paravirtualized guest support details interface, confirm whether "KVM paravirtualized clock" and "KVM Guest support" are selected, as shown in the following figure:
If not selected, press the spacebar to select the "KVM paravirtualized clock" and "KVM Guest support" options.
9. Press "Esc" to return to the "Linux Kernel vX.X.XX Configuration" main interface.
10. Press the "↓" key to move the cursor to "Device Drivers" and press "Enter" to enter the Device Drivers details interface.
11. Press the "↓" key to move the cursor to "Block devices" and press "Enter" to enter the Block devices details interface.
12. In the Block devices details interface, confirm whether "Virtio block driver (EXPERIMENTAL)" is selected. As shown in the image below:
If not selected, press the spacebar to select the "Virtio block driver (EXPERIMENTAL)" option.
13. Press "Esc" to return to the Device Drivers details interface.
14. Press the "↓" key to move the cursor to "Network device support" and press "Enter" to enter the Network device support details interface.
15. In the Network device support details interface, confirm whether "Virtio network driver (EXPERIMENTAL)" is selected. As shown below:
If not selected, press the spacebar to select the "Virtio network driver (EXPERIMENTAL)" option.
16. Press "Esc" to exit the kernel configuration interface, and select "YES" according to the pop-up prompt to save the .config file.
If the output of any command returns a file list containing virtio_blk, virtio_pci.virtio_console, etc., it indicates that the Virtio drivers have been installed correctly.