KVM 使用virtio驱动Windows Server 虚拟机

KVM安装Windows默认使用的是qemu虚拟化IDE硬盘模式,在这种情况下,IO性能比较低,如果使用virtio的方式可以提高虚拟机IO性能。而virtio所驱动的网卡,也将原来的百兆扩展到千兆。这里就简单介绍下如何使用virtio驱动安装window server 2008. 其它windows版本操作相同,只需选择对应的驱动即可。

使用virtio安装window虚拟机

KVM安装Windows需要使用virtio的驱动:

https://Fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download

安装虚拟机步骤:

1、安装virtio驱动

wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo -O /etc/yum.repos.d/virtio-win.repo

yum install virtio-win -y

2、查看virtio-win提供的驱动

rpm -ql virtio-win | grep iso
/usr/share/virtio-win/virtio-win-0.1.126.iso
/usr/share/virtio-win/virtio-win.iso

3、安装windows

创建一个虚拟机磁盘:

qemu-img  create -f qcow2 win-2c8g150g.img 150G

使用virtio驱动安装虚拟机:

virt-install -n win-2c8g150g --vcpus=2 --ram=8192 --os-type=windows --os-variant=win2k8 \
-c /vm/iso/cn_windows_server_2008_r2_sp1_x64.iso \
--disk path=/usr/share/virtio-win/virtio-win-0.1.126_amd64.vfd,device=floppy \
--disk path=/vm/win-2c8g150g.img,format=qcow2,bus=virtio --graphics vnc,listen=0.0.0.0 \
--noautoconsole

提示: 这里是使用的是软盘方式加载,如果镜像和驱动都使用cdrom的方式加载,在有些情况系统会找不到启动镜像,导致无法启动. 加载的驱动有x86和amd64两种类型,64位系统选择amd64. 32为系统选择x86.

4、 安装过程中,在选择磁盘界面会找不到磁盘

选择“加载驱动”,“浏览”,找到“软盘驱动器”,点开后选择 “server 2008”确定,驱动加载完成后,磁盘就出现了,继续安装即可。

5、安装完成后,在设备管理器中可以看到使用的是virtio

在已安装的kvm虚拟机上添加virtio驱动

如果以传统的IDE硬盘模式安装可以使用如下命令:

virt-install  --virt-type kvm --name win-2c8g100g  --ram 8192  \
-vcpus=2 -s 100 -c /vm/iso/cn_windows_server_2008_r2_sp1_x64.iso \
--os-type=windows -f /vm/win-2c8g100g.img --graphics vnc,listen=0.0.0.0 --noautoconsole

安装之后要使用virtio驱动,可以选择加载virtio驱动的iso文件到虚拟机光驱:

virsh  attach-disk  win-2c8g100g /usr/share/virtio-win/virtio-win.iso  hdb  --type cdrom

或者使用如下命令:

virsh change-media win-2c8g100g hdb /usr/share/virtio-win/virtio-win.iso

参考链接:https://superuser.com/questions/239870/change-cd-rom-via-virsh

修改虚拟机的xml文件,使其能发现virtio类型的设备,否则驱动无法安装:
增加一块virtio驱动的硬盘:

qemu-img  create -f qcow2 test.img 1G

修改虚拟机的xml文件,在原有的”disk type”区域增加一个test磁盘的配置:

  <disk>
      <driver/>
      <source/>
      <target/>
    </disk>

修改网卡类型为 virtio, 在 interface type 区域,修改model type=’virtio’ :

<interface>
      <mac/>
      <source/>
      <model/>

提示:如果不是使用vnc远程连接,需要新增一个网卡配置,在没有安装驱动前,使用上面的配置,虚拟机是断网状态。
修改完成之后,重启虚拟机:

virsh shutdown win-2c8g100g
virsh start win-2c8g100g

进入虚拟机,成功添加iso驱动程序后,进入虚拟机的设备管理器界面,在“系统设备”里面对相应的驱动进行更新:
更新驱动需要找到挂载的CD中 virtio-win.iso中的对应文件。驱动镜像中分别有四种驱动,他们对应关系为:

Balloon, the balloon driver, affects the PCI standard RAM Controller in the System devicesgroup.

vioserial, the serial driver, affects the PCI Simple Communication Controller in the System devices group.

NetKVM, the network driver, affects the Network adapters group. This driver is only available if a virtio NIC is configured. Configurable parameters for this driver are documented in Appendix A, NetKVM Driver Parameters.

viostor, the block driver, affects the Disk drives group. This driver is only available if a virtio disk is configured.

参考链接:

https://access.RedHat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Mounting_the_image_with_virt_manager.html

如果找不到英文说明中对应的设备,使用如下方式:

对未知设备添加virtio驱动即可,如图:

安装驱动之后:

对应的磁盘驱动成功安装:

此时virtio驱动添加完成,修改虚拟机的xml文件,删除test.img的虚拟磁盘配置,修改启动磁盘驱动类型:

    <disk>
      <driver/>
      <source/>
      <target/>
      <address/>
    </disk>

重启虚拟机即可。

标签:KVMWindows 发布于:2019-11-13 06:21:50