参考源地址:http://libvirt.org/formatdomain.html

      http://blog.csdn.net/qq250941970/article/details/6022094

libvirt是管理KVM的工具,通过libvirt可以管理配置虚拟机。而虚拟机的配置主要都是通过libvirt的xml文件来实现的,因此xml是十分重要的。

Domain XML format

从官网文档中,我们可以发现xml文件具有一定的格式。

1、Element and attribute overview(元素和属性概述

根元素是所有虚拟机的域。它有两个属性,第一个属性是指定Hypervisor的类型,如”Xen”,“KVM”,“qemu”,“lxc”和“kqemu”。第二个属性是id,运行的guest Domain 的ID,已停用的guest Domain有没有ID值。

<domain type='xen' id=''>
<name>xp</name>
<uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>
<description>Some human readable description</description>

2、Operating system booting(操作系统的启动

BIOS bootloader

 <os>
<type>hvm</type>
<loader readonly='yes' type='rom'>/usr/lib/xen/boot/hvmloader</loader>
<nvram template='/usr/share/OVMF/OVMF_VARS.fd'>/var/lib/libvirt/nvram/guest_VARS.fd</nvram>
<boot dev='hd'/>
<boot dev='cdrom'/>
<bootmenu enable='yes' timeout=''/>
<smbios mode='sysinfo'/>
<bios useserial='yes' rebootTimeout=''/>
</os>

type 表示全虚拟化还是半虚拟化,hvm表示全虚拟化

loader 全虚拟化才需要的,表示全虚拟化的守护进程所在位置

boot 启动设备列表,如"fd"表示从文件启动, "hd"从硬盘启动, "cdrom"从光驱启动 和 "network"从网络启动,同时启动次序也可以由此顺序决定。

bootmenu 当虚拟机启动时是否启用引导菜单,默认时表示使用引导菜单

Host bootloader

半虚拟化的虚拟机启动一般使用这个,在主机使用一个伪引导来为guest Domain提供一个界面选择启动的内核。下面是个xen下半虚拟化的启动范例

<bootloader>/usr/bin/pygrub</bootloader>
<bootloader_args>--append single</bootloader_args>

Bootloader给出主机操作系统引导程序的完整路径,运行这个引导程序,选择启动的内核,这个会因使用的Hypervisor不同而不同。

bootloader_args该元素的可选bootloader_args允许命令行参数传递到bootloader

Direct kernel boot(内核直接启动)

  <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>

3、CPU Allocation(cpu资源)

<domain>
...
<vcpu placement='static' cpuset="1-4,^3,6" current=""></vcpu>
...
</domain>

所谓cpuset,就是在用户空间中操作cgroup文件系统来执行进程与cpu和进程与内存结点之间的绑定,在cpu调优中一般会用到(稍后再写)

4、基本资源

<memory></memory>
<currentMemory></currentMemory>
<memoryBacking>
<hugepages/>
</memoryBacking>
<memtune>
<hard_limit></hard_limit>
<soft_limit></soft_limit>
<swap_hard_limit></swap_hard_limit>
<min_guarantee></min_guarantee>
</memtune>
<vcpu cpuset="1-4,^3,6" current=""></vcpu>
 <cpu match='exact'>
<model>core2duo</model>
<vendor>Intel</vendor>
<topology sockets='' cores='' threads=''/>
<feature policy='disable' name='lahf_lm'/>
</cpu>

这里可以看到各种资源的配置。内存大小、页面大小、memtune内存设定。cpu的model等等

5、 Lifecycle control(操作控制)

<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>

用户请求不同动作时,对domain的执行也不同。

6、 Devices(外设)

 <devices>
<disk type='file' snapshot='external'>
<driver name="tap" type="aio" cache="default"/>
<source file='/var/lib/xen/images/fv0' startupPolicy='optional'>
<seclabel relabel='no'/>
</source>
<target dev='hda' bus='ide'/>
<iotune>
<total_bytes_sec></total_bytes_sec>
<read_iops_sec></read_iops_sec>
<write_iops_sec></write_iops_sec>
</iotune>
<boot order=''/>
<encryption type='...'>
...
</encryption>
<shareable/>
<serial>
...
</serial>
</disk>
...
<disk type='network'>
<driver name="qemu" type="raw" io="threads" ioeventfd="on" event_idx="off"/>
<source protocol="sheepdog" name="image_name">
<host name="hostname" port=""/>
</source>
<target dev="hdb" bus="ide"/>
<boot order=''/>
<transient/>
<address type='drive' controller='' bus='' unit=''/>
</disk>
<disk type='network'>
<driver name="qemu" type="raw"/>
<source protocol="rbd" name="image_name2">
<host name="hostname" port=""/>
<snapshot name="snapname"/>
<config file="/path/to/file"/>
</source>
<target dev="hdc" bus="ide"/>
<auth username='myuser'>
<secret type='ceph' usage='mypassid'/>
</auth>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdd' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="http" name="url_path">
<host name="hostname" port=""/>
</source>
<target dev='hde' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="https" name="url_path">
<host name="hostname" port=""/>
</source>
<target dev='hdf' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="ftp" name="url_path">
<host name="hostname" port=""/>
</source>
<target dev='hdg' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="ftps" name="url_path">
<host name="hostname" port=""/>
</source>
<target dev='hdh' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='network' device='cdrom'>
<driver name='qemu' type='raw'/>
<source protocol="tftp" name="url_path">
<host name="hostname" port=""/>
</source>
<target dev='hdi' bus='ide' tray='open'/>
<readonly/>
</disk>
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sda'/>
<target dev='sda' bus='scsi'/>
<address type='drive' controller='' bus='' target='' unit=''/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sda'/>
<geometry cyls='' heads='' secs='' trans='lba'/>
<blockio logical_block_size='' physical_block_size=''/>
<target dev='hdj' bus='ide'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='blk-pool0' volume='blk-pool0-vol0'/>
<target dev='hdk' bus='ide'/>
</disk>
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.2013-07.com.example:iscsi-nopool/2'>
<host name='example.com' port=''/>
</source>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='network' device='lun'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.2013-07.com.example:iscsi-nopool/1'>
<host name='example.com' port=''/>
</source>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='sdb' bus='scsi'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='iscsi-pool' volume='unit:0:0:1' mode='host'/>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vdb' bus='virtio'/>
</disk>
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='iscsi-pool' volume='unit:0:0:2' mode='direct'/>
<auth username='myuser'>
<secret type='iscsi' usage='libvirtiscsi'/>
</auth>
<target dev='vdc' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/domain.qcow'/>
<backingStore type='file'>
<format type='qcow2'/>
<source file='/var/lib/libvirt/images/snapshot.qcow'/>
<backingStore type='block'>
<format type='raw'/>
<source dev='/dev/mapper/base'/>
<backingStore/>
</backingStore>
</backingStore>
<target dev='vdd' bus='virtio'/>
</disk>
</devices>

Encryption如果存在,指定如何给存储卷加密,查看存储加密页面更多信息

Serial  这个在全虚拟化中比较重要,如果用文件存储,不加下面一段代码,虚拟机无法运行,下面代码是指出硬盘为串口

<serial type='pty'>

<source path='/dev/pts/3'/>

<target port='0'/>

</serial>

<devices>
<controller type='usb' index='' model='ich9-ehci1'>
<address type='pci' domain='' bus='' slot='' function=''/>
</controller>
<controller type='usb' index='' model='ich9-uhci1'>
<master startport=''/>
<address type='pci' domain='' bus='' slot='' function='' multifunction='on'/>
</controller>
...
</devices>

USB设备的xml描述格式如上所示。

官网关于USB重定向的描述:

Redirected devices

USB device redirection through a character device is supported since after 0.9.5 (KVM only):

<devices>
<redirdev bus='usb' type='tcp'>
<source mode='connect' host='localhost' service=''/>
<boot order=''/>
</redirdev>
<redirfilter>
<usbdev class='0x08' vendor='0x1234' product='0xbeef' version='2.56' allow='yes'/> //0x08指大容量存储设备,文件系统。此处指只有大容量存储设备才能访问虚拟机
<usbdev allow='no'/> //其他USB设备不行
</redirfilter>
</devices>

USB常用设备类别和ID:

http://wenku.baidu.com/link?url=66ymV2VeFOTlFCAEVG2iU0yZ3TM5zzWOzs2ICDUNdfK_ZIbg0CKNxgVCS1j-UMfoWSzQ954WsPPx8tfl9vbJz-Tm8nbizgdLNvaEKoteItS

除此之外,还有网络设备,视频声卡

libvirt笔记(未完待续)的更多相关文章

  1. Go web编程学习笔记——未完待续

    1. 1).GOPATH设置 先设置自己的GOPATH,可以在本机中运行$PATH进行查看: userdeMacBook-Pro:~ user$ $GOPATH -bash: /Users/user/ ...

  2. jQuery 学习笔记(未完待续)

    一.jQuery概述    宗旨: Write Less, Do More.    基础知识:        1.符号$代替document.getElementById()函数        2.使 ...

  3. linux学习笔记---未完待续,缓慢更新

    做为linux菜鸟,由于work的需要,慢慢的开始接触学习linux. <鸟哥的linux私房菜>学习笔记. 一.基础命令操作 1.显示日期的命令 date 执行date命令后,显示结果为 ...

  4. oracle-绑定变量学习笔记(未完待续)

    --定义变量SQL> var a number; --给绑定变量赋值SQL> exec :a :=123; PL/SQL procedure successfully completed. ...

  5. Java学习笔记(未完待续)

    变量的作用域(scope)是指变量可以在程序中引用的范围.在方法中定义的变量称为局部变量(local variable).局部变量的作用域从声明变量的地方开始,直到包含该变量的块结束为止.局部变量都必 ...

  6. Greys学习笔记(未完待续)

    Greys介绍 greys-anatomy是一个Java线上诊断工具,取名来自美剧<实习医生格雷>,由菜鸟-杜琨同学开发维护.比我们常用的脚本工具btrace提供更多的功能,greys采用 ...

  7. Java并发笔记-未完待续待详解

    为什么需要并行? – 业务要求 – 性能 并行计算还出于业务模型的需要 – 并不是为了提高系统性能,而是确实在业务上需要多个执行单元. – 比如HTTP服务器,为每一个Socket连接新建一个处理线程 ...

  8. Java开发中的23+2种设计模式学习个人笔记(未完待续)

    注:个人笔记 一.设计模式分三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接模式.组合模 ...

  9. 堆学习笔记(未完待续)(洛谷p1090合并果子)

    上次讲了堆,别人都说极其简单,我却没学过,今天又听dalao们讲图论,最短路又用堆优化,问懂了没,底下全说懂了,我???,感觉全世界都会了堆,就我不会,于是我决定补一补: ——————来自百度百科 所 ...

  10. 关于DOM的一些总结(未完待续......)

    DOM 实例1:购物车实例(数量,小计和总计的变化) 这里主要是如何获取页面元素的节点: document.getElementById("...") cocument.query ...

随机推荐

  1. C语言的各种输入情况介绍(ACM中常用到)

    1.最简单的输入输出形式: 计算a+b的值: scanf("%d%d",&a,&b); printf("%d\n",a+b);--------- ...

  2. vue-devtools插件安装

    1.git clone https://github.com/vuejs/vue-devtools.git 2.此时表示vue-devtools包下载完成,进入到对应的目录下cd vue-devtoo ...

  3. 对MVVM思想的在认识

    如果说MVP是对MVC的进一步改进,那么MVVM则是思想的完全变革.它是将“数据模型数据双向绑定”的思想作为核心,因此在View和Model之间没有联系,通过ViewModel进行交互,而且Model ...

  4. Dreams save us. Dreams lift us up and transform us into something better.

    Dreams save us. Dreams lift us up and transform us into something better.梦想能够拯救我们.梦想能够激励我们并让我们成为更好的人 ...

  5. C++ Knowledge series 3

    Programming language evolves always along with Compiler's evolvement The Semantics of Data The size ...

  6. Java学习笔记——集合

    类集简介 从JDK1.2开始Java引入了类集开发框架,所谓的类集指的就是一套动态对象数组的实现方案,在实际开发之中没有有何一项开发可以离开数组,但是传统的数组实现起来非常的繁琐.而且长度是其致命伤, ...

  7. iOS 谓词(NSPredicate)的应用

    Cocoa中谓词(Predicate)提供了一个通用的查询方式处理数据,可以获取和指定数据的过滤形式,Cocoa实际开发中可以是使用NSPredicate及其父类NSComparisonPredica ...

  8. python网络编程-socketserver模块

    使用socketserver 老规矩,先引入import socketserver 必须创建一个类,且继承socketserver.BaseRequestHandler 这个类中必须重写handle( ...

  9. 算法练习-字符串转换成整数(实现atoi函数)

    练习问题来源 https://leetcode.com/problems/string-to-integer-atoi/ https://wizardforcel.gitbooks.io/the-ar ...

  10. Java字体优化

    需求背景 最近在做的项目显示的字体感觉太丑,于是乎想着DIY改进一下. 查阅资料,总觉得别人写的都不咋地,于是决心写一篇略微完善点的关于项目字体优化方面的文章. 当然,这篇文章不会教你如何使用True ...