All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

How can I install a virtio driver (Linux)?

Last updated:2021-07-16 11:18:19

Check the virtio driver status

Check whether the kernel supports the virtio driver

  1. Run the grep -i virtio /boot/config-$(uname -r) command.

    图片1.png

    No VIRTIO_BLK and VIRTIO_NET information is found in the output message, which means that no virtio driver is installed in this operating system, and the driver needs to be installed. If the values of the parameters CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET are y, the virtio driver is included and can be uploaded directly.

    If the values of the parameters CONFIG_VIRTIO_BLK and CONFIG_VIRTIO_NET are m, proceed with Step 2.

  2. Run the lsinitrd /boot/initramfs-$(uname -r).img | grep virtio command (in CentOS or Fedora) or lsinitrd /boot/initrd.img-$(uname -r) | grep virtio command (in Ubuntu or Debian) to check whether virtio is included in the temporary file system.

    As shown in the figure below, virtio_blk.ko, virtio_pci.ko and virtio.ko are included, indicating that the virtio_blk driver is included in the system and can be uploaded directly. If the temporary file system does not contain the virtio driver, the temporary file system needs to be fixed.

    图片2.png

Fix the temporary file system

Check whether the kernel supports the virtio driver by executing the preceding steps. If you find that the kernel supports the virtio driver, but the temporary file system initramfs or initrd does not contain the virtio driver, fix the temporary file system as follows:

CentOS/RedHat 5

mkinitrd -f --allow-missing \

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

CentOS/Redhat 6/7

mkinitrd -f --allow-missing \

--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 

'nvirtio_blk\nvirtio_pci\nvirtio_console' >> \

/etc/initramfs-tools/modules
mkinitramfs -o /boot/initrd.img-$(uname -r)

Compile and install the virtio driver

If you find that the kernel of the current device does not support the virtio driver, you can refer to the following example to install the virtio driver. The following example uses a CentOS server as an example to describe how to compile and install the virtio driver.

Download the kernel installation package

  1. Run the yum install -y ncurses-devel gcc make wget command to confirm that the tools you need to use are installed before compiling.
  2. Run uname -r to check the kernel version used in the current system, such as 2.6.32-696.18.7.el6.x86_64 in the example.

    图片3.png

  3. Go to the Linux kernel list page to download the source code package of the corresponding kernel version. For example, the URL of the kernel source code package linux-2.6.32.27.tar.gz is https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.27.tar.gz.

    图片4.png

  4. Run cd /usr/src to switch the directory.
  5. Run wget https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.27.tar.gz to download the installation package.
  6. Run tar -xvf linux-2.6.32.27.tar.gz to decompress the installation package.
  7. Run ln -s linux-2.6.32.27 linux to establish the link.
  8. Run cd /usr/src/linux to switch the directory.

Compile the kernel

  1. Run the following commands 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 window appears, open the virtio configuration:

    a. Press Spacebar to select Virtualization, and then press Enter to enter the details window.

    微信图片_20180621172459.png

    b. Confirm whether the Kernel-based Virtual Machine (KVM) support option is selected in the details window.

    微信图片_20180621172605.png

    Note: * indicates that the driver is compiled to the kernel, while m indicates that the driver is compiled as a module.

    c. Return to the homepage, select Processor type and features with the up arrow or down arrow key, and then press Enter to enter the details window. Select Paravirtualized guest support with the up arrow or down arrow key, and then press Enter to enter the details window.

    Check whether KVM paravirtualized clock and KVM Guest support are selected.

    微信图片_20180621172700.png

    d. Return to the homepage, select Device Drivers with the up arrow or down arrow key, and then press Enter to enter the details window. Select Block devices with the up arrow or down arrow key, and then press Enter to enter the details window. Make sure Virtio block driver (EXPERIMENTAL) is selected.

    微信图片_20180621172726.png

    e. Return to the Device Drivers details window, select Network device support with the up arrow or down arrow key, and then press Enter to enter the details window. Make sure Virtio network driver (EXPERIMENTAL) is selected.

    微信图片_20180621172752.png

    f. Press Esc to exit the kernel configuration window and save the .config file as prompted.

  3. Use the preceding method to check whether virtio has been configured correctly.
  4. (Optional) If virtio is not configured correctly, run the following commands to manually edit the .config file.
make oldconfig

make prepare

make scripts

make

make install
  1. Run the following commands to check whether the virtio driver has been installed.
find /lib/modules/"$(uname -r)"/ -name "virtio.*" | grep -E "virtio.*"

grep -E "virtio.*" < /lib/modules/"$(uname -r)"/modules.builtin

Note: If the file list such as virtio_blk or virtio_pci.virtio_console is output with any command, it indicates that the virtio driver has been installed correctly.

On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback