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

今天我们实验一些libvirt虚拟机XML定义文件中的配置参数。 

 

<domain type='kvm'>

 <name>XP_VM4</name>

  <uuid>92f1ab08-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='qcow2'/>

     <source file='/opt/vm/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/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'/>   -->

     <source bridge='br0'/>

     <target dev='vnet0'/>

     <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>

 

1.      内存配置: 

修改  <memory>1024000</memory>缺省单位是KB

如果要将虚拟机的内存改为2G,就是<memory>2048000</memory>

 

2.      CPU配置: 

修改  <vcpu>1</vcpu>  <cpu><topology sockets='1' cores='1'  threads='1'/></cpu>

如果要改成4VCPU,可以这样:<vcpu>4</vcpu>  <cpu><topology sockets='1' cores='2' threads='2'/></cpu>

 

3.      时间同步配置: 

修改 <clock  offset='localtime'/>

Localtime:表示虚拟机从本地主机同步时间:

如果要从外部时间服务器同步UTC时间,则改为:

<clock offset=’utc’/>

 

4.      启动问题: 

<boot dev='cdrom'/>      

<boot dev='hd'/>         ————光驱位第一启动项,硬盘其次

<bootmenu enable='yes'/> ————有启动菜单选项,F12可以选择启动顺序

 

5.      电源控制: 

<acpi/>    ————虚拟机接收电源控制信号,可以用libvirtshutdown命令优雅的关闭虚拟机操作系统

 

6.      虚拟机行为控制: 

<on_poweroff>destroy</on_poweroff>       ——虚机操作系统关机后释放资源

 <on_reboot>restart</on_reboot>    ——虚机操作系统要求重启后libvirt重启虚拟机 

  <on_crash>restart</on_crash> ——虚机操作系统崩溃后重启虚拟机

 

7.      鼠标模式 

<input type='tablet'  bus='usb'/> ——光标的绝对移动

<input type=’mouse’ bus='ps2'/> ——光标的相对移动

 

实际使用效果 tablet较好

 

 

未完待续

 

你可能感兴趣的:(libvirt,qemu-kvm)