为什么要学习libvirt 中的XML
l Libvirt中配置虚拟机都是通过xml文件来配置的,如启动一个虚拟机需要的对虚拟机配置的描述就是通过XML来实现的。因此XML在libvirt管理虚拟机中有很重要的地位。
Domain XML format 1. 元素和属性概述
根元素为所有虚拟机需要的是命名域。它有两个属性,第一个属性是指定Hypervisor的类型,如”Xen”,“KVM”,“qemu”,“lxc”和“kqemu”。第二个属性是id,运行的guest Domain 的ID,已停用的guest Domain有没有ID值。
Direct kernel boot
当安装新的一个客户机操作系统,直接从存储在主机操作系统上的内核和initrd启动是非常有效的引导,这样运行命令行参数直接传递给安装程序。全虚拟和半虚拟都可以使用这种引导方式 ... <os> <type>hvm</type> <loader>/usr/lib/xen/boot/hvmloader</loader> <kernel>/root/f8-i386-vmlinuz</kernel> <initrd>/root/f8-i386-initrd</initrd> <cmdline>console=ttyS0 ks=http://example.com/f8-i386/os/</cmdline> </os> ...
type
This element has the same semantics as described earlier in the BIOS boot section
loader
This element has the same semantics as described earlier in the BIOS boot section
kernel
The contents of this element specify the fully-qualified path to the kernel image in the host OS.
initrd
The contents of this element specify the fully-qualified path to the (optional) ramdisk image in the host OS.
cmdline
The contents of this element specify arguments to be passed to the kernel (or installer) at boottime. This is often used to specify an alternate primary console (eg serial port), or the installation media source / kickstart file
CPU model and topology <cpu match='exact'> <model>core2duo</model> <vendor>Intel</vendor> <topology sockets='1' cores='2' threads='1'/> <feature policy='disable' name='lahf_lm'/> </cpu> ...
5. Lifecycle control ... <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> ...
6. Hypervisor features ... <features> <pae/> <acpi/> <apic/> </features> ...
pae
Physical address extension mode allows 32-bit guests to address more than 4 GB of memory.
acpi
ACPI is useful for power management, for example, with KVM guests it is required for graceful shutdown to work.
7. Time keeping
Guest Domain 的时钟通常应初始化于主机时钟,然而大多数操作系统默认使用UTC时间,在windows中把这个叫做”localtime”
UTC协调世界时,又称世界统一时间,世界标准时间,国际协调时间。定义:以原子时为基准的一种时间计量系统,其时刻与世界时时刻差不超过±0.9s。 ... <clock offset="localtime"> <timer name="rtc" tickpolicy="catchup" track="guest"> <catchup threshold=123 slew=120 limit=10000/> </timer> <timer name="pit" tickpolicy="none"/> </clock> ...
Clock
Offset 的属性可能有四种值,用来让guest Domain 时钟采取什么方式同步到honst,但并不是所有的hypervisor都支持这四种方式
Offset的四个值:
utc
The guest clock will always be synchronized to UTC when booted
localtime
The guest clock will be synchronized to the host's configured timezone when booted, if any.
timezone
The guest clock will be synchronized to the requested timezone using the timezone attribute. Since 0.7.7
variable
The guest clock will have an arbitrary offset applied relative to UTC. The delta relative to UTC is specified in seconds, using the adjustment attribute. The guest is free to adjust the RTC over time an expect that it will be honoured at next reboot. Thisis in contrast to 'utc' mode, where the RTC adjustments are lost at each reboot.(根据libvirt0.7.7版,Aclock may have zero or moretimersub-elements.Since 0.8.0)
Timer
每一个timer元素都要求有一个name属性,指定不同的名字会有一些不同的属性,不同的hypervisor支持不同的属性组合
name
The name attribute selects which timer is being modified, and can be one of "platform", "pit", "rtc", "hpet", or "tsc".
track
The track attribute specifies what the timer tracks, and can be "boot", "guest", or "wall". Only valid for name="rtc" or name="platform".
tickpolicy
The tickpolicy attribute determines how missed ticks in the guest are handled, and can be "delay", "catchup", "merge", or "discard". If the policy is "catchup", there can be further details in the catchup sub-element.
catchup
The catchup element has three optional attributes, each a positive integer. The attributes are threshold, slew, and limit.
frequency
The frequency attribute is an unsigned integer specifying the frequency at which name="tsc" runs.
mode
The mode attribute controls how the name="tsc" timer is managed, and can be "auto", "native", "emulate", "paravirt", or "smpsafe". Other timers are always emulated.
present
The present attribute can be "yes" or "no" to specify whether a particular timer is available to the guest