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 the virtio driver (Windows)?

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

Install the virtio driver

You need to install the virtio driver for Windows images. The following section describes the process of installing the virtio driver for a Windows system in the KVM environment.

Prepare the driver file

Visit https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.149-2/ and then select the file virtio-win-0.1.149.iso to download.

Create placeholder disks

  1. Create six qcow2-format virtual disk files with a small size (10 GB) in advance to simulate one swap disk and five data disks.

  2. Assume that names of the six placeholder disks are disk.swap, disk1, disk2, disk3, disk4, and disk5. These names correspond to virtio PCI device numbers 0x06, 0x08, 0x09, 0x0a, 0x0b, and 0x0c when the Libvirt XML configuration file is edited.

    Note that the PCI device numbers 0x5 and 0x7 are used by other devices and cannot be used.

    • Network: A dual-bridge network is required to simulate the online environment, including the internal network br0 and the external network br_vm.

    • Configuration: Add the information about the image for which the virtio driver is to be installed, placeholder disks, network, and ISO file containing the driver file to libvirt xml of the virtual machine to be created. Then start the virtual machine, and access the virtual machine through methods such as VNC to proceed with the installation and configuration.

    • Installation: After you access the Windows virtual machine and go to "Device Manager", you will find that a lot of devices are identified with the question mark. The question mark is displayed because these devices have no virtio driver installed.

    Right-click a device with the question mark, select Update driver, and then select Browse my computer for driver software in the dialog box that appears.

Because the virtio driver file has been configured in libvrit xml of this virtual machine, the driver file will be displayed in the form of the partition mounting, as shown in the figure below. Select D:\ in the input box and click Next. The installation program can automatically detect the driver. You can also specify the exact path to install the driver.

Example

Preparation

  1. Prepare the Linux environment with normal network connection. Run the $ grep -Ei "svm|vmx" /proc/cpuinfo command to check whether the CPU supports the installation of the virtio driver. If vmx is returned, the CPU supports the installation.

  2. Install qemu-kvm, qemu-img, and libvirt.
# centos 6
$ sudo yum install libvirt-daemon libvirt-client qemu-kvm qemu-img

# ubuntu
$ sudo apt-get install libvirt-daemon libvirt-clients  qemu-kvm qemu-utils  bridge-utils libvirt-daemon-system ebtables

Due to software dependency, you will be prompted to install several packages. If the required package does not conflict with current packages, you can enter y directly and press Enter to install the packages. (For more information about Ubuntu, visit https://help.ubuntu.com/community/KVM/Installation).

  1. Start the libvirtd service.

    # centos 6
    $ sudo /etc/init.d/libvirtd start
    $ /etc/init.d/libvirtd status
    # ubuntu
    $ sudo systemctl start libvirtd.service
  2. Download the driver package (URL: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio).
$ wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.110-1/virtio-win-0.1.110.iso
  1. Add the bridge.

    $ sudo brctl addbr br0
    $ sudo ifconfig br0 up
  2. Edit /etc/qemu/bridge.conf.

    $ cat /etc/qemu/bridge.conf
    allow all
  3. Add permissions if Ubuntu is used.

    $ sudo chmod +s /usr/lib/qemu/qemu-bridge-helper
  4. Load the kvm module.
    $ modprobe kvm
    $ lsmod | grep kvm
    kvm_intel             212992  4
    kvm                   598016  1 kvm_intel
    irqbypass              16384  1 kvm
  5. kvm, libvirt, libvirt-qemu, or libvirt-dnsmasq user or group may need to be created manually.

Install the driver

  1. Create placeholder disks.

    qemu-img create -f qcow2 Windows_Server.1.img 10G
    qemu-img create -f qcow2 Windows_Server.2.img 10G
    qemu-img create -f qcow2 Windows_Server.3.img 10G
    qemu-img create -f qcow2 Windows_Server.4.img 10G
    qemu-img create -f qcow2 Windows_Server.5.img 10G
    qemu-img create -f qcow2 Windows_Server.6.img 10G
  2. Edit libvirt daemon xml to obtain the path of qemu-system-x86_64.
$ which qemu-system-x86_64

Modify the path to the emulator for the following XML. Using the editor, save the following code as libvirt.xml.

<domain type='kvm'>
  <name>windows2012zh</name>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
  <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file=''/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/virtio-win-0.1.110.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.1.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.2.img'/>
      <target dev='vdc' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.3.img'/>
      <target dev='vdd' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.4.img'/>
      <target dev='vde' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.5.img'/>
      <target dev='vdf' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.6.img'/>
      <target dev='vdg' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <interface type='bridge'>
      <mac address='fa:16:3e:32:19:f1'/>
      <source bridge='virbr0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='ea:16:3e:57:7a:fa'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='1'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='1'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='vga' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
  </devices>
</domain>
  1. Create a successor image of the target image, or directly operate the image.
    $ qemu-img create -f qcow2 -b Win2012R2.qcow2 Win2012R2.qcow2.init
    Formatting 'Win2012R2.qcow2.init', fmt=qcow2 size=53687091200 backing_file='Win2012R2.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16

    Add the absolute path of Win2012R2.qcow2.init to source file of the first disk in libvirt.xml.

    <disk type='file' device='disk'>
    <driver name='qemu' type='qcow2' cache='none'/>
    <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
    <target dev='hda' bus='ide'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
  2. Register the domain.

    $ virsh define libvirt.xml
    Domain windows2012zh defined from libvirt.xml
  3. Start the virtual machine.
    $ virsh start windows2012zh
    Domain windows2012zh started
  4. Obtain the VNC address.

    $ virsh vncdisplay windows2012zh
    :0

    The VNC address is 127.0.0.1:0. Use the VNC client to log in to 127.0.0.1:0 to access the virtual machine.

  5. Install the driver.

    a. Right-click Computer and select Properties. Click Device Manager. You can see that the driver of SCSI controller and Ethernet controller is not installed. Right-click the first Ethernet controller from the top down, select Update driver, and then click Browse my computer for driver software.

    Fill in the path to install the driver. After the configuration based on the preceding libvirt xml, there is only one CD-ROM on the virtual machine, and its path is D:\. Click Next. When the driver is installed, Windows will warn that the driver has not been signed by Microsoft. In this case, click Always trust software from Red Hat, Inc., and then click Install.

    Similarly, install the driver for the second Ethernet controller. The following figure shows successful installation.

    b. Enter Device Manager. Right-click SCSI Controller, select Update driver, and then click Browse my computer for driver software. Fill in the path to install the driver. If there is only one CD-ROM, the path is D:\. Click Next.

    Similarly, install the driver for the second to six SCSI controllers. The following figure shows successful installation.

    c. Shut down the virtual machine. Edit the types of virtual disk bus and driver used by Windows Guest in Libvirt XML to make the system disk to use the virtio driver.

    Before the change:

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

    After the change:

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>

    d. Restart the virtual machine, and log in to the system. There are no unknown devices in the device manager, and no exception exists with the driver. This indicates that the driver has been installed.

  6. If the successor image .init is used to complete the above update steps, the image needs to be merged. The newly generated image with the suffix of .base can be uploaded to KS3.
$ qemu-img convert -f qcow2 -O qcow2 Win2012R2.qcow2.init Win2012R2.qcow2.base
  1. Import the image by following steps described in Import images.
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback