虛擬機 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>