第 9 章 KVM 半虚拟驱动程序

9.1. 安装 KVM Windows 半虚拟驱动程序

半虚拟驱动程序可用于 KVM 主机中运行的虚拟 Windows 客户端。这些半虚拟驱动程序包含在 virtio 软件包中。Virtio 软件包支持块(存储)设备和网络接口控制器。

半虚拟驱动程序改进了全虚拟客户端的性能。使用半虚拟驱动程序可降低客户端 I/O 等待时间,流量可达到近似裸机的水平。建议您在运行很多 I/O 任务和程序的全虚拟客户端中使用半虚拟驱动程序。

新的 Fedora 版本中可自动载入并安装 KVM 半虚拟驱动程序。那些 Fedora 版本探测并安装这些驱动程序因此不需要额外的安装步骤。

与 KVM 模块一样,virtio 驱动程序只可用于运行较新版本 Fedora 的主机。

Note

每个客户端只有 28 个 PCI 插槽可用于附加设备。每个半虚拟网络或者块设备使用一个插槽。每个客户端最多可使用 28 个附加设备,它们可以是任意组合的半虚拟网络、半虚拟磁盘设备或者其它使用 VTd 的 PCI 设备。

以下微软 Windows 版本支持 KVM 半虚拟驱动程序:

  • Windows XP,

  • Windows Server 2003,

  • Windows Vista 以及

  • Windows Server 2008。

9.1. 安装 KVM Windows 半虚拟驱动程序

这部分论述了如何安装 KVM Windows 半虚拟驱动程序。KVM 半虚拟驱动程序可在 Windows 安装过程中载入,也可在客户端安装后载入。

You can install the para-virtualized drivers on your guest by one of the following methods:

  • hosting the installation files on a network accessible to the guest,

  • using a virtualized CD-ROM device of the driver installation disk .iso file, or

  • using a virtualized floppy device to install the drivers during boot time (for Windows guests).

This guide describes installation from the para-virtualized installer disk as a virtualized CD-ROM device.

  1. 下载驱动程序

    微软提供这些驱动程序(windowsservercatalog.com)。

    virtio-win 软件包在 /usr/share/virtio-win/ 目录中安装安装光驱映像 virtio-win.iso

  2. 安装半虚拟驱动程序

    建议您在附加或者修改设备使其使用半虚拟驱动程序前在客户端中安装该驱动程序。

    在保存根文件系统的块设备或者需要引导客户端的其它块设备中,必须在修改该设备前安装驱动程序。如果没有在客户端中安装驱动程序,但将驱动程序设定为 virtio 驱动程序,则无法引导该客户端。

使用 virt-manager 挂载映像

Follow 过程 9.1, “使用 virt-manager 在 Windows 客户端中挂载光驱映像” to add a CD-ROM image with virt-manager.

过程 9.1. 使用 virt-manager 在 Windows 客户端中挂载光驱映像
  1. 打开 virt-manager,在虚拟机列表中选择您的虚拟客户端并按 详情 按钮。

  2. 点击「详情」面板中的 添加 按钮。

  3. This opens a wizard for adding the new device. Select Storage device from the drop down menu, then click Forward.

    9. KVM 半虚拟驱动程序 - 图1

  4. 选择「文件(磁盘映像)」选项,并将半虚拟驱动程序文件设定为 .iso 文件。如果您使用 yum 安装半虚拟驱动程序软件包,那么这个 .iso 文件的位置就是 /usr/share/xenpv-win

    如果该驱动程序是保存在物理光盘中,请使用「普通磁盘分区」选项。

    Set the Device type to IDE cdrom and click Forward to proceed.

    9. KVM 半虚拟驱动程序 - 图2

  5. The disk has been assigned and is available for the guest once the guest is started. Click Finish to close the wizard or back if you made a mistake.

    9. KVM 半虚拟驱动程序 - 图3

使用虚拟软盘安装

这个过程包括在 Windows 安装过程中安装半虚拟驱动程序。

  • 第一次安装 Windows VM 时请使用立即运行菜单将 viostor.vfd 附加为一个软盘

    1. Windows Server 2003

      当窗口提示按 F6 使用第三方驱动程序时,请按 F6 并根据屏幕指示操作。

    2. Windows Server 2008

      When the installer prompts you for the driver, click on “Load Driver”, point the installer to drive A: and pick the driver that suits your OS and bittage

在现有设备中使用 KVM 半虚拟驱动程序

Modify an existing hard disk device attached to the guest to use the virtio driver instead of virtualized IDE driver. This example edits libvirt configuration files. Alternatively, virt-manager, virsh attach-disk or virsh attach-interface can add a new device using the para-virtualized drivers 在新设备中使用 KVM 半虚拟驱动程序.

  1. 以下是使用虚拟 IDE 驱动程序的基于文件的块设备。这是用于不使用虚拟驱动程序的虚拟客户端的典型条目。

    1. <disk type='file' device='disk'>
    2. <source file='/var/lib/libvirt/images/disk1.img'/>
    3. <target dev='hda' bus='ide'/>
    4. </disk>
  2. bus= 条目改为 virtio 可让该条目使用半虚拟设备。

    1. <disk type='file' device='disk'>
    2. <source file='/var/lib/libvirt/images/disk1.img'/>
    3. <target dev='hda' bus='virtio'/>
    4. </disk>
在新设备中使用 KVM 半虚拟驱动程序

这个步骤是用 virt-manager 创建使用 KVM 半虚拟驱动程序的新设备。

另外,使用 virsh attach-disk 或者 virsh attach-interface 命令可附加使用半虚拟驱动程序的设备。

首先安装驱动程序

请在 Windows 客户端中安装新设备前确定安装了该驱动程序。如果该驱动程序不可用,则无法识别和使用该设备。

  1. 请在 virt-manager 中双击客户端名称打开虚拟客户端。

  2. 打开「硬件」标签。

  3. 「添加硬件」按钮。

  4. 在“添加虚拟硬盘”标签中选择「存储」或者「网络」作为设备类型。

    1. New disk devices

      选择存储设备或者基于文件的映像。选择「Virtio 磁盘」作为「设备类型」并按「前进」

      9. KVM 半虚拟驱动程序 - 图4

    2. New network devices

      选择「虚拟网络」或者「共享物理设备」。选择「virtio」 作为「设备类型」并按「前进」

      9. KVM 半虚拟驱动程序 - 图5

  1. 「完成」保存该设备。

    9. KVM 半虚拟驱动程序 - 图6

  2. 重启该客户端。Windows 客户端要在重启后才可识别该设备。