分类: 虚拟化
2012-02-06 10:29:33
Libvirt XML学习笔记
为什么要学习libvirt 中的XMLl Libvirt中配置虚拟机都是通过xml文件来配置的,如启动一个虚拟机需要的对虚拟机配置的描述就是通过XML来实现的。因此XML在libvirt管理虚拟机中有很重要的地位。
Domain XML format
1. 元素和属性概述
根元素为所有虚拟机需要的是命名域。它有两个属性,第一个属性是指定Hypervisor的类型,如”Xen”,“KVM”,“qemu”,“lxc”和“kqemu”。第二个属性是id,运行的guest Domain 的ID,已停用的guest Domain有没有ID值。
2. 通用元数据
每个guest Domain都有它的名称,uuid ,描述(描述可有可无)
3. 启动操作系统
...
... |
type 表示全虚拟化还是半虚拟化,hvm表示全虚拟化
loader 全虚拟化才需要的,表示全虚拟化的守护进程所在位置
boot 怎么启动的,如"fd"表示从文件启动, "hd"从硬盘启动, "cdrom"从光驱启动 和 "network"从网络启动
bootmenu 当虚拟机启动时是否启用引导菜单,默认时表示使用引导菜单
半虚拟化的虚拟机启动一般使用这个,在主机使用一个伪引导来为guest Domain提供一个界面选择启动的内核。下面是个xen下半虚拟化的启动范例
... ... |
Bootloader给出主机操作系统引导程序的完整路径,运行这个引导程序,选择启动的内核,这个会因使用的Hypervisor不同而不同。
bootloader_args该元素的可选bootloader_args允许命令行参数传递到bootloader
当安装新的一个客户机操作系统,直接从存储在主机操作系统上的内核和initrd启动是非常有效的引导,这样运行命令行参数直接传递给安装程序。全虚拟和半虚拟都可以使用这种引导方式
...
... |
type
This element has the same semantics as described earlier in the
loader
This element has the same semantics as described earlier in the
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
4. 配置虚拟机的基本资源
...
... |
... |
5. Lifecycle control
... ... |
...
... |
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.
Guest Domain 的时钟通常应初始化于主机时钟,然而大多数操作系统默认使用UTC时间,在windows中把这个叫做”localtime”
UTC协调世界时,又称世界统一时间,世界标准时间,国际协调时间。定义:以原子时为基准的一种时间计量系统,其时刻与世界时时刻差不超过±0.9s。
...
... |
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. This is in contrast to 'utc' mode, where the RTC adjustments are lost at each reboot.(根据libvirt0.7.7版,A clockmay have zero or more timersub-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
在最后一组xml元组中用来描述为guest Domain提供设备的,所有的设备都是在这里描述的
...
... |
Emulator 模拟器,给出二进制模拟器设备的完整路径
...
...
...
... |
Encryption如果存在,指定如何给存储卷加密,查看存储加密页面更多信息
Serial 这个在全虚拟化中比较重要,如果用文件存储,不加下面一段代码,虚拟机无法运行,下面代码是指出硬盘为串口