KVM虛擬機的xml配置文件


在RHEL6中,用於從磁盤啟動的XML文件

  這里以dcs01.xml為例:

  <domain type='kvm'>
<name>dcs01</name>
<uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='rhel6.0.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/home/kvm/images/dcs01.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:ad:75:98'/>
<source bridge='br0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<video>
<model type='vga' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</memballoon>
</devices>
</domain>

  注釋如下:

  1、kvm guest 定義開始
<domain type='kvm'>

  2、guest的short name。由字母和數字組成,不能包含空格
<name>dcs01</name>

  3、uuid,由命令行工具 uuidgen生成。
<uuid>e5fff551-bbe1-e748-c8e4-8ecb3bffb902</uuid>

  4、在不reboot guest的情況下,guset可以使用的最大內存,以KB為單位
<memory>1048576</memory>

  5、guest啟動時內存,可以通過virsh setmem來調整內存,但不能大於最大可使用內存。
<currentMemory>1048576</currentMemory>

  6、分配的虛擬cpu
<vcpu>1</vcpu>

  7、有關OS
架構:i686、x86_64
machine:宿主機的操作系統
boot:指定啟動設備,可以重復多行,指定不同的值,作為一個啟動設備列表。
<os>
<type arch='x86_64' machine='rhel6.0.0'>hvm</type>
<boot dev='hd'/>
</os>

  8、處理器特性
<features>
<acpi/>
<apic/>
<pae/>
</features>

  9、時鍾。使用本地時間:localtime
<clock offset='localtime'/>

  10、定義了在kvm環境中power off,reboot,或crash時的默認的動作分別為destroy和restart。其他允許的動作包括: preserve,rename-restart.。
destroy:停止該虛擬機。相當於關閉電源。
restart重啟虛擬機
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>

  11、設備定義開始
<devices>

  12、模擬元素,此處寫法用於kvm的guest
<emulator>/usr/libexec/qemu-kvm</emulator>

  13、用於kvm存儲的文件。在這個例子中,在guest中顯示為IDE設備。
使用qemu-img命令創建該文件,kvm image的默認目錄為:/var/lib/libvirt/images/
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/home/kvm/images/dcs01.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>

  補充:可以定義多個磁盤。
使用virtio:
采用普通的驅動,即硬盤和網卡都采用默認配置情況下,網卡工作在 模擬的rtl 8139 網卡下,速度為100M 全雙工。采用 virtio 驅動后,網卡工作在 1000M 的模式下。

  采用普通的驅動,即硬盤和網卡都采用默認配置情況下,硬盤是 ide 模式。采用 virtio 驅動后,硬盤工作是SCSI模式下。
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/usr/local/kvm/vmsample/disk.os'/>
<target dev='vda' bus='virtio'/>
</disk>

  CD-ROM device:
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>

  14、使用網橋類型。確保每個kvm guest的mac地址唯一。將創建tun設備,名稱為vnetx(x為0,1,2...)
<interface type='bridge'>
<mac address='52:54:00:ad:75:98'/>
<source bridge='br0'/>
<address type='pcidomain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

  補充:
使用默認的虛擬網絡代替網橋,即guest為NAT模式。也可以省略mac地址元素,這樣將自動生成mac地址。
<interface type='network'>
<source network='default'/>
<mac address="3B:6E:01:69:3A:11"/>
</interface>
默認分配192.168.122.x/24的地址,也可以手動指定。網關為192.168.122.1

  使用virtio:
采用普通的驅動,即硬盤和網卡都采用默認配置情況下,網卡工作在 模擬的rtl 8139 網卡下,速度為100M 全雙工。采用 virtio 驅動后,網卡工作在 1000M 的模式下。
<interface type='bridge'>
<source bridge='br1'/>
<model type='virtio' />
</interface>

  15、輸入設備
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>

  16、定義與guset交互的圖形設備。在這個例子中,使用vnc協議。listen的地址為host的地址。prot為-1,表示自動分配端口號,通過以下的命令查找端口號:
virsh vncdisplay <KVM Guest Name>

  這里未設置
<graphics type='vnc' port='-1' autoport='yes'/>

  17、設備定義結束
</devices>

  18、KVM定義結束
</domain>

 

 

 

http://www.cnblogs.com/yanghuahui/archive/2013/05/08/3067676.html

 

<domain type='kvm'>
  <name>centos_x86_6.4</name>
#由字母和數字組成,不能包含空格  <uuid>b9dcdd92-9b9b-14d6-3938-1982a9746a12</uuid> <memory unit='KiB'>2097152</memory>
 #由字母和數字組成,不能包含空格  <currentMemory unit='KiB'>2097152</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc-1.2'>hvm</type>
#type 表示全虛擬化還是半虛擬化,hvm表示全虛擬化  <boot dev='hd'/>
  #boot 怎么啟動的,如"fd"表示從文件啟動, "hd"從硬盤啟動, "cdrom"從光驅啟動 和 "network"從網絡啟動 #可以重復多行,指定不同的值,作為一個啟動設備列表。 #The dev attribute takes one of the values "fd", "hd", "cdrom" or "network"  </os>
#處理器特性  <features> <acpi/> <apic/> <pae/> </features>  <clock offset='localtime'> <timer name='pit' tickpolicy='delay'/> <timer name='rtc' tickpolicy='catchup'/> </clock> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices>
#Guest需要的設備
<emulator>/bin/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
#目的鏡像路徑 在這個例子中,在guest中顯示為IDE設備。  <source file='/home/template_make/centos_x86_6.4.img'> <seclabel model='selinux' relabel='no'/> </source> <target dev='hda' bus='ide'/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/home/template_make/CentOS-6.4-x86_64-bin-DVD1.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'>
#虛擬機網絡連接方式  <mac address='52:54:00:78:f9:5a'/> <source bridge='br0'/> <target dev='vnet27'/>
## 使用virtio: 采用普通的驅動,即硬盤和網卡都采用默認配置情況下,硬盤是 ide 模式, 而網卡工作在 模擬的rtl 8139 網卡下,速度為100M 全雙工。 采用 virtio 驅動后,網卡工作在 1000M 的模式下,硬盤工作是SCSI模式下 <model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <input type='mouse' bus='ps2'/>
#vnc方式登錄,端口號自動分配 可以通過virsh vncdisplay來查詢[vncdisplay domainId]  <graphics type='vnc' port='5915' autoport='yes' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <video> <model type='cirrus' vram='9216' heads='1'/> <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='0x04' function='0x0'/> </memballoon> </devices> <seclabel type='dynamic' model='selinux' relabel='yes'> <label>unconfined_u:system_r:svirt_t:s0:c362,c396</label> <imagelabel>unconfined_u:object_r:svirt_image_t:s0:c362,c396</imagelabel> </seclabel> </domain>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM