acommoners
虚拟机 XML 配置示例

虚拟机的 XML 配置(也称为 域 XML )决定虚拟机的设置和组件。下表显示了虚拟机(VM)的 XML 配置示例并解释了其内容。

要获取虚拟机的 XML 配置,您可以使用 virsh dumpxml 命令,后跟虚拟机的名称。

virsh dumpxml demo-guest1
XML 配置示例和解释
<domain type=\'kvm\' id=\'13\'>
  <name>demo-guest1</name>
  <uuid>409fc837-ef54-48c9-9a47-c62fe383d33d</uuid>
  <!-- guset可以使用的最大内存,以KB为单位 -->  
  <memory unit=\'KiB\'>2097152</memory>
  <!-- guest启动时内存,可以通过virsh setmem来调整内存,但不能大于最大可使用内存 -->  
  <currentMemory unit=\'KiB\'>2097152</currentMemory>
  <!-- 分配的虚拟cpu --> 
  <vcpu placement=\'static\'>2</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <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=\'full\'>
    <model fallback=\'forbid\'>Skylake-Server-IBRS</model>
    <feature policy=\'require\' name=\'md-clear\'/>
    <feature policy=\'require\' name=\'spec-ctrl\'/>
    <feature policy=\'require\' name=\'ssbd\'/>
    <feature policy=\'require\' name=\'hypervisor\'/>
    <feature policy=\'disable\' name=\'arat\'/>
  </cpu>
  <!-- 时钟, 使用本地时间: utc --> 
  <clock offset=\'utc\'>
    <timer name=\'rtc\' tickpolicy=\'catchup\'/>
    <timer name=\'pit\' tickpolicy=\'delay\'/>
    <timer name=\'hpet\' present=\'no\'/>
  </clock>
  <!-- 定义了在kvm环境中crash时的默认的动作分别为destroy和restart。
    destroy:停止该虚拟机。相当于关闭电源。
    restart: 重启虚拟机 -->  
  <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>
    <!-- 模拟器,此处路径为qemu-kvm绝对路径 -->
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <!-- 用于kvm启动或者存储的文件,启动设备为:/image/UCarApp1/UCarApp1_clone-disk1.raw -->
    <disk type=\'file\' device=\'disk\'>
      <driver name=\'qemu\' type=\'raw\'/>
      <source file=\'/image/UCarApp1/UCarApp1_clone-disk1.raw\'/>
      <backingStore/>
      <target dev=\'vda\' bus=\'virtio\'/>
      <!-- 可通过--disk 修改磁盘总线类型为ide --disk UCarApp1_clone-disk1.raw,bus=ide -->
      <alias name=\'virtio-disk0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x06\' function=\'0x0\'/>
    </disk>
    <controller type=\'usb\' index=\'0\' model=\'ich9-ehci1\'>
      <alias name=\'usb\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x04\' function=\'0x7\'/>
    </controller>
    <controller type=\'usb\' index=\'0\' model=\'ich9-uhci1\'>
      <alias name=\'usb\'/>
      <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\'>
      <alias name=\'usb\'/>
      <master startport=\'2\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x04\' function=\'0x1\'/>
    </controller>
    <controller type=\'usb\' index=\'0\' model=\'ich9-uhci3\'>
      <alias name=\'usb\'/>
      <master startport=\'4\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x04\' function=\'0x2\'/>
    </controller>
    <controller type=\'pci\' index=\'0\' model=\'pci-root\'>
      <alias name=\'pci.0\'/>
    </controller>
    <controller type=\'virtio-serial\' index=\'0\'>
      <alias name=\'virtio-serial0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x05\' function=\'0x0\'/>
    </controller>
    <!-- 采用普通的驱动,即硬盘和网卡都采用默认配置情况下,网卡工作在 模拟的rtl 8139 网卡下,速度为100M 全双工。采用 virtio 驱动后,网卡工作在 1000M 的模式下 -->
    <interface type=\'bridge\'>
      <mac address=\'52:54:00:bc:1b:74\'/>
      <source bridge=\'br0\'/>
      <target dev=\'vnet6\'/>
      <model type=\'virtio\'/>
      <alias name=\'net0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x03\' function=\'0x0\'/>
    </interface>
    <serial type=\'pty\'>
      <source path=\'/dev/pts/11\'/>
      <target type=\'isa-serial\' port=\'0\'>
        <model name=\'isa-serial\'/>
      </target>
      <alias name=\'serial0\'/>
    </serial>
    <console type=\'pty\' tty=\'/dev/pts/11\'>
      <source path=\'/dev/pts/11\'/>
      <target type=\'serial\' port=\'0\'/>
      <alias name=\'serial0\'/>
    </console>
    <channel type=\'unix\'>
      <source mode=\'bind\' path=\'/var/lib/libvirt/qemu/channel/target/domain-13-demo-guest1/org.qemu.guest_agent.0\'/>
      <target type=\'virtio\' name=\'org.qemu.guest_agent.0\' state=\'disconnected\'/>
      <alias name=\'channel0\'/>
      <address type=\'virtio-serial\' controller=\'0\' bus=\'0\' port=\'1\'/>
    </channel>
    <!-- 输入设备 -->
    <input type=\'tablet\' bus=\'usb\'>
      <alias name=\'input0\'/>
      <address type=\'usb\' bus=\'0\' port=\'1\'/>
    </input>
    <!-- 输入设备 -->
    <input type=\'mouse\' bus=\'ps2\'>
      <alias name=\'input1\'/>
    </input>
    <input type=\'keyboard\' bus=\'ps2\'>
      <alias name=\'input2\'/>
    </input>
    <!-- 定义与guset交互的图形设备。在这个例子中,使用vnc协议。listen的地址为0.0.0.0的地址。prot为5903,通过以下的命令查找端口号: virsh vncdisplay guestName -->
    <graphics type=\'vnc\' port=\'5903\' autoport=\'yes\' listen=\'0.0.0.0\'>
      <listen type=\'address\' address=\'0.0.0.0\'/>
    </graphics>
    <video>
      <model type=\'cirrus\' vram=\'16384\' heads=\'1\' primary=\'yes\'/>
      <alias name=\'video0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x02\' function=\'0x0\'/>
    </video>
    <memballoon model=\'virtio\'>
      <alias name=\'balloon0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x07\' function=\'0x0\'/>
    </memballoon>
    <rng model=\'virtio\'>
      <backend model=\'random\'>/dev/urandom</backend>
      <alias name=\'rng0\'/>
      <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x08\' function=\'0x0\'/>
    </rng>
  <!-- 设备定义结束 -->
  </devices>
  <seclabel type=\'dynamic\' model=\'selinux\' relabel=\'yes\'>
    <label>system_u:system_r:svirt_t:s0:c47,c808</label>
    <imagelabel>system_u:object_r:svirt_image_t:s0:c47,c808</imagelabel>
  </seclabel>
  <seclabel type=\'dynamic\' model=\'dac\' relabel=\'yes\'>
    <label>+107:+107</label>
    <imagelabel>+107:+107</imagelabel>
  </seclabel>
</domain>

分类:

技术点:

相关文章: