[root@kvm01 qemu]# cat vm01-centos7.xml 
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit vm01-centos7
or other application using the libvirt API.
-->

<domain type='kvm'>    // domain 是一个所有虚拟机都需要的根元素,type定义使用哪个虚拟机管理程序,                        


<name>vm01-centos7</name>        <!--虚拟机名称-->


<uuid>92a80d4c-1a1f-49bc-b946-10852a9bc15f</uuid>     <!--个性化设置,也可以自行修改,做虚拟机模板时可以删除-->


<memory unit='KiB'>1048576</memory>         <!--虚拟机能使用的最大内存,此处为2G,即:1*1024*1024-->


<currentMemory unit='KiB'>1048576</currentMemory>    <!--在虚拟机中用 free -m 命令可以看见的内存大小,一般与上面的最大内存值设为一样-->
<vcpu placement='static'>1</vcpu>      <!--CPU的数量--> vcpu的内容是为虚拟机最多分配几个cpu,值处于1~maxcpu之间 //placement参数指定一个domain的cpu的分配模式,static、auto

<os>            <!--系统引导设备配置,无需手动修改-->
<type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>    // type参数指定了虚拟机操作系统的类型 // arch指定虚拟机的CPU架构,machine指定机器的类型 // hvm表明需要全虚拟化


<boot dev='hd'/>      // boot:指定启动设备,hd表示从硬盘启动


</os>
<features>      <!--高级电源管理,无需手动修改-->  Hypervisors所有的特性都在fearures元素中

<acpi/>

// 用于电源管理
<apic/>

// 是装置的扩充组合用来驱动 Interrupt 控制器
</features>
<cpu mode='custom' match='exact' check='partial'>    <!--CUP配置,cpu mode可以写成'host-passthrough',意思是使用真机的CPU-->
<model fallback='allow'>Broadwell-noTSX-IBRS</model>
<feature policy='require' name='md-clear'/>
<feature policy='require' name='spec-ctrl'/>
<feature policy='require' name='ssbd'/>
</cpu>
<clock offset='utc'>  <!--时钟设置,可以设置为localtime-->

// 客户端的时间初始化来自宿主机的时间 // 大多数操作系统期望硬件时钟保持UTC格式,UTC也是默认格式 // 当一个客户端的OS触发lifecycle时,它将采取新动作覆盖默认操作 // 具体状态参数如下:
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>     <!--虚拟机关机命令-->

<on_reboot>restart</on_reboot>       <!--虚拟机重启命令-->

<on_crash>destroy</on_crash>    <!--虚拟机强制重启命令-->

<pm>          <!--内存及硬盘休眠设置,可删除-->
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>        
<devices>       <!--系统仿真设备,主板驱动类-->


<emulator>/usr/libexec/qemu-kvm</emulator>     <!--仿真设备使用哪个程序来仿真,这里使用qemu-kvm来仿真-->


<disk type='file' device='disk'>        <!--硬盘配置,需要手动修改,可以通过复制本段来创建新的磁盘-->


<driver name='qemu' type='qcow2'/>    <!--磁盘驱动类型-->


<source file='/data/images/vm01-centos7.img'/>    <!--磁盘路径设置-->


<target dev='vda' bus='virtio'/>       <!--磁盘盘符设置-->

// 将磁盘暴露给客户机时的总线类型和设备名称。 // target元素:控制总线设备在某个磁盘被选为客户 // 端的OS时,dev属性表明本地磁盘在客户端上的实际 // 名称,因为实际设备的名称指定并不能保证映射到 // 客户端OS上的设备。 // bus属性指定了哪种类型的磁盘被模拟 // virtio 半虚拟化


<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>     <!--总线地址,下同,可删除-->
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hda' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>      <!--USB相关配置,可删除,下同-->
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:4a:d6:c4'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5902' autoport='no' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</rng>
</devices>

// 在技术上KVM-QMEU架构采用了一种叫virtio-serial的技术,这种技术处理主机用户空间和客户机用户空间的数据传输。 // 它主要包含两个部分: // 1. Qemu中模拟一个叫virtio-pci的设备,这个设备提供给客户机使用; // 2.客户机上安装一个字符设备驱动访问virtio-pci设备。

</domain>
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit node1
or other application using the libvirt API.
-->

<!--
以下两项可有可无,所以在此注释。
-->

<!--
<seclabel>......</seclabel>                                                               驱动安全标签,可删除
<resource>......</resource>                                                               资源设置,可删除
-->

<domain type='kvm'>
  <name>node1</name>                                                                      <!--虚拟机名称-->
  <uuid>8908d03b-0329-4105-851f-c93fd091e9e9</uuid>                                       <!--个性化设置,也可以自行修改,做虚拟机模板时可以删除-->
  <memory unit='KiB'>2097152</memory>                                                     <!--虚拟机能使用的最大内存,此处为2G,即:2*1024*1024-->
  <currentMemory unit='KiB'>2097152</currentMemory>                                       <!--在虚拟机中用 free -m 命令可以看见的内存大小,一般与上面的最大内存值设为一样-->
  <vcpu placement='static'>2</vcpu>                                                       <!--CPU的数量-->
  <os>                                                                                    <!--系统引导设备配置,无需手动修改-->
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>                                                                              <!--高级电源管理,无需手动修改-->
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='partial'>                                       <!--CUP配置,cpu mode可以写成'host-passthrough',意思是使用真机的CPU-->
    <model fallback='allow'>Westmere</model>
  </cpu>
  <clock offset='utc'>                                                                    <!--时钟设置,可以设置为localtime-->
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>                                                      <!--虚拟机关机命令-->
  <on_reboot>restart</on_reboot>                                                          <!--虚拟机重启命令-->
  <on_crash>destroy</on_crash>                                                            <!--虚拟机强制重启命令-->
  <pm>                                                                                    <!--内存及硬盘休眠设置,可删除-->
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>                                                                               <!--系统仿真设备,主板驱动类-->
    <emulator>/usr/libexec/qemu-kvm</emulator>                                            <!--仿真设备使用哪个程序来仿真,这里使用qemu-kvm来仿真-->
    <disk type='file' device='disk'>                                                      <!--硬盘配置,需要手动修改,可以通过复制本段来创建新的磁盘-->
      <driver name='qemu' type='qcow2'/>                                                  <!--磁盘驱动类型-->
      <source file='/var/lib/libvirt/images/node1.img'/>                                  <!--磁盘路径设置-->
      <target dev='vda' bus='virtio'/>                                                    <!--磁盘盘符设置-->
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>         <!--总线地址,下同,可删除-->
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>                                  <!--USB相关配置,可删除,下同-->
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>                                    <!--PCI设备配置,可删除-->
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='network'>                                                             <!--网卡设置,可复制本段来添加新的网卡-->
      <mac address='52:54:00:74:1c:9e'/>                                                   <!--网卡MAC地址,可删除-->
      <source network='default'/>                                                          <!--指定网卡连接的交换机-->
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>          <!--总线地址,可删除-->
    </interface>
    <serial type='pty'>                                                                    <!--串口终端,需要保留,下同-->
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='unix'>                                                                  <!--虚拟机通讯控制接口-->
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <channel type='spicevmc'>                                                              <!--图形图像相关配置,可以删除-->
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>                      <!--串口设备,需要保留串口终端-->
    </channel>
    <input type='tablet' bus='usb'>                                                        <!--数位板,如笔记本电脑的触摸板等,可删除-->
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>                                                        <!--鼠标-->
    <input type='keyboard' bus='ps2'/>                                                     <!--键盘-->
    <graphics type='spice' autoport='yes'>                                                 <!--图形图像显卡相关配置,可以删除-->
      <listen type='address'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>                                                                   <!--声卡相关设置,可以删除-->
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>                                                                                <!--图形图像显卡相关配置,可以删除-->
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>                                                   <!--设备重定向,可以删除,下同-->
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <memballoon model='virtio'>                                                            <!--内存气泡,可以动态调整内存-->
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>
</domain>