Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十一)

上一个介绍主要讲了如何virtio驱动对于虚拟机性能改善的重要性以及如何安装针对磁盘的虚拟驱动,接下来我们继续安装其他几个虚拟驱动:QXL虚拟显卡、虚拟网卡、虚拟串口和改善显示和鼠标体验的vdagent程序。在继续之前我们先还是有针对性的修改定义虚拟机的XML定义文件,参阅红色字体部分:

<domain type='kvm'>

<name>XP_VM2</name>

<uuid>91f15b08-e115-4016-a522-b550ff593af8</uuid>

<memory>1024000</memory>

<currentMemory>1024000</currentMemory>

<vcpu>1</vcpu>

<os>

<type arch='x86_64' machine='pc'>hvm</type>

<boot dev='cdrom'/>

<boot dev='hd'/>

<bootmenu enable='yes'/>

</os>

<features>

<acpi/>

<apic/>

<pae/>

</features>

<cpu>

<topology sockets='1' cores='1' threads='1'/>

</cpu>

<clock offset='localtime'/>

<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='raw'/>

<source file='/opt/vm/xpvm_virtio/xp_c.img' lock='exclusive'/>

<target dev='hda' bus='virtio'/>

</disk>

<disk type='file' device='disk'>

<driver name='qemu' type='qcow2'/>

<source file='/opt/vm/xpvm_virtio/xp_d.img' lock='exclusive'/>

<target dev='hdb' bus='virtio'/>

</disk>

<disk type='file' device='cdrom'>

<source file='/opt/vm/windows_xp_professional_sp3_x86.iso'/>

<target dev='hdc'/>

<readonly/>

</disk>

<disk type='file' device='floppy'>

<source file='/opt/vm/virtio-WinXP-x86.vfd'/>

<target dev='fda' bus='fdc'/>

<readonly/>

</disk>

<interface type='bridge'>

<mac address='52:54:00:7b:a8:d8'/>

<source bridge='virbr0'/>

<target dev='vnet1'/>

<model type='virtio'/>

</interface>

<channel type='spicevmc'>

<target type='virtio' name='com.redhat.spice.0'/>

<alias name='virserial-channel1'/>

</channel>

<input type='tablet' bus='usb'/>

<graphics type='spice' port='4000' autoport='no' listen='0.0.0.0'>

<listen type='address' address='0.0.0.0'/>

<agent_mouse mode='off'/>

</graphics>

<sound model='ac97'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>

</sound>

<video>

<model type='qxl' vram='65536' heads='1'/>

</video>

<memballoon model='virtio'>

<alias name='balloon0'/>

</memballoon>

</devices>

<qemu:commandline>

<qemu:arg value="-cpu"/>

<qemu:arg value="qemu64,model=3"/>

</qemu:commandline>

</domain>

挑出来就是下面一段:

<channeltype='spicevmc'>

<targettype='virtio' name='com.redhat.spice.0'/>

<aliasname='virserial-channel1'/>

</channel>

有关spicevmc的说明如下(http://www.libvirt.org/formatdomain.html

Paravirtualized SPICE channel. The domainmust also have a SPICE server as a graphicsdevice, at which point the host piggy-backs messages across the main channel. The target element must be present, withattribute type='virtio'; an optional attribute namecontrols how the guest will have access to the channel, and defaults to name='com.redhat.spice.0'. The optional address element can tie thechannel to a particular type='virtio-serial'controller.

简单的说是一个虚拟串口通道,用于优化主机和虚拟机之间的一些通信。

在修改了XML后,需要通过重新执行下面的命令来让其生效:

sudo virsh undefined XP_VM2

sudo virsh define xp.xml

然后再启动虚拟机:sudo virsh start XP_VM2

启动完成后当然还是通过spice连接上去: spicec –h 127.0.0.1 –p 4000:

启动完后你会发现在虚拟机的设备管理器上会出现一些未知设备,那是因为在更新了XML定义后系统发现了一些硬件上的改动。为了让系统识别这些设备,我们需要为其装上驱动,下载这些驱动的路径是:http://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-0.59.exe

Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十一)

这个exe里面就包含了完整的虚拟显卡驱动、虚拟网卡驱动和虚拟串口驱动,而且针对windows各个版本的都有(也包括32位和64位)。

下载以后执行这个EXE程序:

Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十一)

中间会有些警告信息,那是因为没有数字证书,没关系,选择安装就是。

安装完以后再看一下设备管理器,发现那些原来带黄色问号的设备纷纷被识别出来了,原来它们就是虚拟网卡、虚拟串口和虚拟显卡,参考下图:

Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十一)

同时在服务列表中可以看到增加了一个叫RHEV Spice Agent的服务:

Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十一)

这个服务就是所谓的vdagent,它主要起到下面几个作用:

1. 在虚拟机和本地系统间拷贝、粘贴文本;

2. 在全屏模式下让虚拟机自适应本地系统的分辨率;

3. 改善在虚拟机里面的鼠标使用体验等。

这个vdagent运行的LOG缺省在 C:\windows\temp 目录下,如果有什么问题可以去看看。