xml文件内容是来定义kvm中domain的配置信息,可以使用virt-install来生成,但需要指定各个选项,那还不如生成一个基本的xml或复制模板来做相应修改。

以下是kvm中domain的xml配置解释。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!--  #提示信息
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 win7-02
or other application using the libvirt API.
-->
<domain  type = 'kvm' #用kvm创建的虚拟机称为domain,type定义使用哪个虚拟机管理程序,值可以是:xen、kvm、qemu、lxc、kqemu
                     #第二个参数是id,它唯一的标示一个运行的虚拟机,不活跃的客户端没有id。 
   <name>win7-02< /name >
             #name参数为虚拟机定义了一个简短的名字,必须唯一
   <uuid>6ce14f21-33ac-dc79-5444-f64ccc80ea17< /uuid >
                     #uuid,全球唯一,linux下可以用uuidgen生成
  <title>This is my first  test  kvm< /title >
                     #title参数提供一个对虚拟机简短的说明,它不能包含换行符。
   <memory unit= 'KiB' >2097152< /memory >
                     #可以分配到的最大内存,内存单位由unit定义,单位可以是:K、KiB、M、MiB、G、GiB、T、TiB。默认是KiB。MiB 2048代表2G
   <currentMemory unit= 'KiB' >2097152< /currentMemory >
                     #实际分给给客户端的内存她小于memory的定义,如果没有定义,值和memory一致。
   <vcpu placement= 'static' >1< /vcpu >
                     #vcpu的内容是为虚拟机最多分配几个cpu
   <os>
     < type  arch= 'x86_64'  machine= 'rhel6.5.0' >hvm< /type >
#arch指定虚拟机的CPU构架,machine指定机器的类型。hvm表明该OS被设计为直接运行在裸金属上面,需要全虚拟化。
     <boot dev= 'cdrom' />
                 #dev属性的值可以是:fd、hd、cdrom、network,boot的元素可以被设置多个用来建立一个启动优先规则。 
   < /os >
   <features>  #Hypervisor的特性:
     <acpi/>   #Hypervisors允许特定的CPU/机器特性打开或关闭,所有的特性都在fearures元素中,以下介绍一些在全虚拟化中常用的标记:
     <apic/>   #acpi:用于电源管理      
     <pae/>    #pae:扩展物理地址模式,使32位的客户端支持大于4GB的内存
   < /features >
   <cpu mode= 'host-passthrough' >
     <topology sockets= '1'  cores= '4'  threads= '1' />
   < /cpu >
   
   <on_poweroff>destroy< /on_poweroff >
   #当客户端请求poweroff时执行特定的动作
   <on_reboot>restart< /on_reboot >
   #当客户端请求reboot时执行特定的动作
   <on_crash>restart< /on_crash >
   #当客户端崩溃时执行的动作
  #每种状态下可以允许指定如下四种行为:
          #destory:domain将会被完全终止,domain的所有资源会被释放
          #restart:domain会被终止,然后以相同的配置重新启动
          #preserver:domain会被终止,它的资源会被保留用来分析
          #rename-restart:domain会被终止,然后以一个新名字被重新启动
  
  <clock offset= "localtime"  />
          #客户端的时间初始化来自宿主机的时间,大多数操作系统期望硬件时钟保持UTC格式,UTC也是默认格式,然而Windows机器却期望它是'localtime'
  #UTC:当引导时客户端时钟同步到UTC时钟
          #localtime:当引导时客户端时钟同步到主机时钟所在的时区
          #timezone:The guest clock will be synchronized to the requested timezone using the timezone attribute 
  
  <devices>  #所有的设备都是一个名为devices元素的子设备
     <emulator> /usr/libexec/qemu-kvm < /emulator >
         #emulator元素指定模拟设备二进制文件的全路径
     <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2' />
       < source  file = '/data/vmdisk/win7-02.qcow2' />
       <target dev= 'vda'  bus= 'virtio' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x0' />
     < /disk >
     <disk  type = 'file'  device= 'cdrom' >
       <driver name= 'qemu'  type = 'raw' />
       < source  file = '/iso/win7.iso' />
       <target dev= 'hda'  bus= 'ide' />
       < readonly />
       <address  type = 'drive'  controller= '0'  bus= '0'  target= '0'  unit= '0' />
     < /disk >
     <disk  type = 'file'  device= 'cdrom' >
       <driver name= 'qemu'  type = 'raw' />
       < source  file = '/iso/virtio-win-0.1-100.iso' />
       <target dev= 'hdb'  bus= 'ide' />
       < readonly />
       <address  type = 'drive'  controller= '0'  bus= '0'  target= '0'  unit= '1' />
     < /disk >
     <disk  type = 'file'  device= 'floppy' >
       <driver name= 'qemu'  type = 'raw' />
       < source  file = '/iso/virtio-win-0.1.96_amd64.vfg' />
       <target dev= 'fda'  bus= 'fdc' />
       < readonly />
       <address  type = 'drive'  controller= '0'  bus= '0'  target= '0'  unit= '0' />
     < /disk >
#所有的设备看起来就像一个disk、floppy、cdrom或者一个 paravirtualized driver,他们通过一个disk元素指定。
#type特性包括:file,block,dir,network,device描述disk如何受到客户端OS的,特性包括:floppy、disk、cdrom、lun,默认是disk
#source元素:在disk的type是file时,file属性指定一个合格的全路径文件映像作为客户端的磁盘,在disk的type是block时,dev属性指定一个主机设备的路径作为disk。
    #在disk的type是dir时,dir属性指定一个全路径的目录作为disk,在disk的type是network时,protocol属性指定协议用来访问镜像,镜像的值可以是:nbd,rbd,sheepdog
#dev属性表明本地磁盘在客户端上的实际名称,因为实际设备的名称指定并不能保证映射到客户端OS上的设备
#bus属性指定了哪种类型的磁盘被模拟,值主要有:ide、scsi、virtio、xen、usb、sata
#readonly元素:指定客户端不能修改设备。当一个disk含有type=cdrom,readonly则是默认值。
(disk中virtio-win-0.1-100.iso和virtio-win-0.1.96_amd64.vfg是windows需要的驱动文件,linux系列无需定义)
     
<controller  type = 'usb'  index= '0' >
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x2' />
     < /controller >
     <controller  type = 'ide'  index= '0' >
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x1' />
     < /controller >
     <controller  type = 'fdc'  index= '0' />
     <controller  type = 'virtio-serial'  index= '0' >
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x05'  function = '0x0' />
     < /controller >
     
<interface  type = 'bridge' >   #类型桥接
       < source  bridge= 'br0' />  #桥接的设备名字
       <model  type = 'virtio' />
     < /interface >
     
#串行端口
<serial  type = 'file' >
       < source  path= '/tmp/console.log' />
       <target port= '0' />
     < /serial >
     <serial  type = 'pty' >
       <target port= '1' />
     < /serial >
     <console  type = 'file' >
       < source  path= '/tmp/console.log' />
       <target  type = 'serial'  port= '0' />
     < /console >
     <channel  type = 'spicevmc' >
       <target  type = 'virtio'  name= 'com.redhat.spice.0' />
       <address  type = 'virtio-serial'  controller= '0'  bus= '0'  port= '1' />
     < /channel >
     <input  type = 'tablet'  bus= 'usb' />
     <input  type = 'mouse'  bus= 'ps2' />
     #input元素:input元素含有一个强制的属性,type属性的值可以是mouse或tablet
#bus属性指定一个明确的设备类型,值可以是:xen、ps2、usb。 
<graphics  type = 'spice'  port= '6789'  autoport= 'no'  listen= '0.0.0.0'  keymap= 'en-us' >
       <listen  type = 'address'  address= '0.0.0.0' />  #graphics元素:graphics含有一个强制的属性type,type的值可以是:sdl、vnc、rdp、desktop、spice
       <channel name= 'main'  mode= 'insecure' />      #vnc则启动vnc服务,port属性指定tcp端口,如果是-1,则表示自动分配
       <channel name= 'display'  mode= 'insecure' />   #vnc的端口自动分配的话是从5900向上递增。listen属性提供一个IP地址给服务器监听,可以单独在listen元素中设置
       <channel name= 'inputs'  mode= 'insecure' />    #passwd属性提供一个vnc的密码
       <channel name= 'cursor'  mode= 'insecure' />    #listen元素:listen元素专门针对vnc和spice设置监听端口等
       <channel name= 'playback'  mode= 'insecure' />  #它包含以下属性:type、address、network。type的值可以是address或network。
       <channel name= 'record'  mode= 'insecure' />    #如果设置了type=address,那么address属性设置一个ip地址或者主机名来监听。
       <channel name= 'smartcard'  mode= 'insecure' /> #如果type=network,则network属性设置一个网络名称在libvirt‘s的网络配置文件中。
       <channel name= 'usbredir'  mode= 'insecure' />
       <image compression= 'auto_glz' />
       <streaming mode= 'all' />
       <clipboard copypaste= 'yes' />
     < /graphics >
   
   <video>
       <model  type = 'qxl'  ram = '65536'  vram= '65536'  heads= '1' >
         <acceleration accel3d= 'yes'  accel2d= 'yes' />
       < /model >
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x02'  function = '0x0' />
     < /video >
     <memballoon model= 'virtio' >
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x06'  function = '0x0' />
     < /memballoon >
   < /devices >
< /domain >
    #video元素:是描述声音设备的容器,为了向后完全兼容,如果没有设置video但是有graphics在xml配置文件中,这时libvirt会按照客户端类型增加一个默认的video

本文转自Jacken_yang 51CTO博客,原文链接:http://blog.51cto.com/linuxnote/1881726,如需转载请自行联系原作者