咱們使用 KVM 建立虛擬機後,會在 /etc/libvirt/qemu/ 路徑下生成該虛擬機的 xml 配置文件,不少時候,咱們會以此 xml 配置爲模板,進行修改後來建立新的虛擬機,這樣,就須要咱們瞭解該配置文件中各個字段的意思,下面,就對該文件作一說明:
node
<!-- 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>
這裏採用源文件註釋的方式對字段進行說明,能夠是更方便的瞭解字段意思,各位老鐵可直接複製粘貼,修改以後使用。
api