配置KVM下windows虚拟机使用virtio驱动

本文介绍了如何在KVM环境下为Windows虚拟机配置VirtIO驱动,以提升性能。首先解释了virtio驱动的作用和适用系统,接着详细阐述了两种安装方法,特别是通过IDE方式安装后修改启动参数。最后,逐步指导操作过程,包括安装KVM、配置网卡、下载驱动ISO、挂载驱动和更新虚拟机XML配置文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、virtiod的介绍:

(参考官方文档:http://docs.fedoraproject.org/en-US/Fedora/13/html/Virtualization_Guide/chap-Virtualization-KVM_Para_virtualized_Drivers.html)

    Para-virtualized drivers are available for virtualized Windows guests running on KVM hosts. These para-virtualized drivers are included in the virtio package. The virtio package supports block (storage) devices and network interface controllers.
    Para-virtualized drivers enhance the performance of fully virtualized guests. With the para-virtualized drivers guest I/O latency decreases and throughput increases to near bare-metal levels. It is recommended to use the para-virtualized drivers for fully virtualized guests running I/O heavy tasks and applications.
    The KVM para-virtualized drivers are automatically loaded and installed on the following:

  • Any 2.6.27 or newer kernel.
  • Newer Ubuntu, CentOS, Red Hat Enterprise Linux.
  • Those versions of Linux detect and install the drivers so additional installation steps are not required.
    The following Microsoft Windows versions have should work KVM para-virtualized drivers:
  • Windows XP (32-bit only)
  • Windows Server 2003 (32-bit and 64-bit versions)
  • Windows Server 2008 (32-bit and 64-bit versions)
  • Windows 7 (32-bit and 64-bit versions)

默认情况下安装好windows虚拟机,采用普通的驱动,即硬盘和网卡都采用默认配置情况下,硬盘是 ide 模式;
而网卡工作在模拟的rtl 8139 网卡下,速度为100M 全双工。采用 virtio 驱动后,网卡工作在 1000M 的模式下,硬盘工作是SCSI模式下

二、Windows安装VirtIO驱动的两种方法: 

1、使用IDE方式来安装系统,安装系统完成后,在guest中安装virtio磁盘驱动,然后再修改kvm启动参数,设置磁盘为virtio
(1)安装完Windows后,创建一块临时的硬盘,将其设置为virtio模式添加到Windows中,并设置网卡模式为virio
(2)开机后将提示检查到新硬件,然后安装驱动程序后关机
(3)删除新添加的临时硬盘,将原来的硬盘设置为virtio模式,开机即可识别到硬盘与网卡都为virtio模式
2、在安装时直接加载virtio驱动
因为已经有做好的windows镜像文件,所以此教程采用第一种方法

三、操作过程(包括前期准备):

1、确定机器是否支持虚拟化:(必要时需要在BIOS开启VT)

egrep "(vmx|svm)" --color=always /proc/cpuinfo (显示红色)

2、安装kvm、libvirt

apt-get install kvm qemu-kvm bridge-utils libvirt-bin virtinst
kvm:这个是KVM的核心,是一个内核模块。
qemu-kvm:KVM的设备模拟,由开源虚拟化软件QEMU中的管理工具演变而来。
bridge-utils:用于桥接网卡
libvirt-bin:虚拟机命令行管理工具
virtinst:虚拟机创建工具
这里插一句:kvm已经和qemu合并了,源里”kvm“和”qemu“都是指向“qemu-kvm”的虚包
PS:如果你的宿主机安装有图形界面,推荐你安装图形化管理工具 virt-manager,而且这个工具还支持SSH远程连接(qemu+SSH)

3、配置桥接网卡

虚拟机通过桥接的方式,才更加接近物理环境。配置如下:
vim /etc/network/interfaces
加入br0,把原来与eth0有关的配置注释掉
然后添加br0,并且将eth0网络配置给br0
例如:以test60(192.168.7.60)为例:
auto br0
iface br0 inet static
  address 192.168.7.60
  netmask 255.255.255.0
  gateway 192.168.7.254
  bridge_ports eth0 # 桥接到eth0网卡

4、制作镜像的过程不叙述,假设镜像已经制作好,并安装好操作系统

5、为虚拟机创建xml配置文档,方便libvirt管理,也避免了每次用命令行创建启动虚拟机时要写很多命令

注:也可以安装virt-manager,使用图形界面的形式安装,可参考:
http://www-01.ibm.com/support/docview.wss?uid=swg21587905
http://hi.baidu.com/woailiuxiaomi/item/635361d93898782548e1ddc7#

保证img文件格式和原来的一致:比如之前为qcow2,但是文件中写成raw,就无法启动
例子:
<domain type='kvm'> 
  <name>win7-32</name>
  <memory>1048576</memory>
  <currentMemory>1048576</currentMemory> 
  <vcpu>1</vcpu>
  <os> 
    <type arch='x86_64' machine='pc'>hvm</type> 
    <boot dev='cdrom'/>
    <boot dev = 'hd'/>
  </os> 
  <features> 
    <acpi/> 
    <apic/> 
    <pae/> 
  </features> 
  <clock offset='localtime'/> 
  <on_poweroff>destroy</on_poweroff> 
  <on_reboot>restart</on_reboot> 
  <on_crash>destroy</on_crash> 
  <devices> 
    <emulator>/usr/bin/kvm</emulator> 
    <disk type='file' device='disk'> 
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/windows-virtio/win7-32.img'/>
      <target dev='hda' bus='ide'/> 
    </disk>
    <interface type='bridge'>
      <source bridge='br0'/>
      <mac address="00:16:3e:5d:aa:a9"/>
    </interface>
    <input type='mouse' bus='ps2'/> 
    <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>
  </devices> 
</domain> 

5、准备好virtio驱动:

下载地址:http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/,下载最新的ISO文件(virtio-win-0.1-81.iso)
在该ISO文件中,包括好几个文件夹,具体对应关系如下:

  • wxp: winxp 磁盘驱动
  • wnet: win2003磁盘驱动 
  • win7:win7磁盘驱动
  • wlh: win2008磁盘驱动 
  • xp: win xp/2003 网卡驱动
  • vista: win vista/7/2008 网卡驱动

6、手动申请一块硬盘给该虚拟机挂上,并把下载的iso也挂载在该虚拟机上

qemu-img ceate -f qcow2 fake.img 10G
修改win-server-08的libvirt的配置文件。增加如下内容:
<disk type='file' device='disk'> 
  <driver name='qemu' type='qcow2'/>
  <source file='/var/lib/windows-virtio/win7-32.img'/>
  <target dev='hda' bus='ide'/> 
</disk>
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2'/>
  <source file='/var/lib/windows-virtio/fake.img'/>
  <target dev='vdb' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
  <driver name='qemu' type='raw'/>
  <source file='/var/lib/windows-virtio/virtio-win-0.1-81.iso'/>
  <target dev='hdc' bus='ide'/>
</disk>
其中cdrom是为了挂载iso文件,以便安装virtio的驱动。而fake.img是为了让win能识别需要安装virtio的驱动。
网卡部分直接新增<model type='virtio'/>就好了

7、重启虚拟机

重启之后,在windows下的硬件管理器之中就能看到有标黄的需要安装的驱动(硬盘驱动和网卡驱动),选择在文件系统里安装,在iso文件里找对应的版本的驱动
注意:在windows xp系统下如果选择自动安装会出现不成功,一定要手动选择具体安装路径,具体可参考:http://lvii.github.io/system/2013/11/15/xp-sp3-kvm-network-virtio-install-failed/

8、更新xml文件,删掉新添加的磁盘信息,并使原disk更新为SCSI格式

<disk type='file' device='disk'> 
  <driver name='qemu' type='qcow2'/>
  <source file='/var/lib/windows-virtio/win7-32.img'/>
  <target dev='vda' bus='virtio'/> 
</disk>

改完后,用virsh命令destroy并start重启。在设备管理器发现原硬盘项和网卡已变成virtio模式,安装成功!

参考资料:

http://www.cnblogs.com/babybluevino/p/3472996.html
http://blog.chinaunix.net/uid-20776139-id-3481065.html
http://www.361way.com/kvm-windows-virtio/2816.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值