【虚拟化】虚拟机xml文件解析

虚拟机xml文件解析

name

name	# 虚拟机名称,具有唯一性,不可与已建立的虚拟机重复

uuid

uuid	#虚拟机ID,通常在新建虚拟机时自动生成,可自行设定,不可重复

memory/currentMemory

虚拟机内存,默认单位KB,新建虚拟机时指定,也可自行修改,修改后需重新定义虚拟机,不可超过物理机空余内存。

<memory unit='G'>4</memory>
<currentMemory unit='G'>4</currentMemory>

vcpu

为虚拟机CPU个数,创建虚拟机时指定或根据系统版本默认设定,可自行修改,修改后需重新定义虚拟机,如虚拟机需运行压力测试等消耗资源的进程,则需为宿主机预留足够CPU以避免系统崩溃

<vcpu placement='static'>2</vcpu>

boot

为虚拟机启动位置,在安装完系统后通常设定为hd,即从硬盘启动。

其它选项包括cdrom(通过光驱或镜像启动)、pxe(通过网络启动)、nfs、ftp等

<os>
    <type arch='x86_64' machine='pc-i440fx-4.1'>hvm</type>
    <boot dev='hd'/>
</os>

cpu

虚拟机cpu模式,默认为host-model,查看系统支持配置并修改为相应配置。

嵌套虚拟化配置为host-passthrough,修改后需重新定义虚拟机

<cpu mode='host-passthrough' check='none'/>

on_poweroff

on_poweroff、on_reboot、on_crash:为虚拟机在相应情况发生时的应对设定,默认动作为poweroff关机,reboot重启,crash系统崩溃时关机。

on_poweroff与on_reboot不可对换,即不可在on_poweroff设定为restart的同时将on_reboot设定为destroy。

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

on_poweroff 支持的配置:

# 指定了 guest 请求断电时执行的操作。可选值有
<on_poweroff>destroy</on_poweroff> # domain 将被完全终止并释放所有资源。
<on_poweroff>restart</on_poweroff> #domain 将被终止,然后使用相同的配置重新启动。
<on_poweroff>preserve</on_poweroff> #domain 将被终止,其资源将被保留以便进行分析。

on_reboot

on_reboot 支持的配置:

# 指定了 guest 请求重启时执行的操作。可选值有
<on_reboot>destroy</on_reboot> # domain 将被完全终止并释放所有资源。
<on_reboot>restart</on_reboot> #domain 将被终止,然后使用相同的配置重新启动。
<on_reboot>preserve</on_reboot> #domain 将被终止,其资源将被保留以便进行分析。

on_crash

系统崩溃处理【因arm不支持相关监控硬件,故 on_crush 设定在arm上不适用】

使on_crush事件设置生效,需要在xml文件中增加如下硬件:

<devices>
    <panic model='isa'>
    </panic>
</devices>

on_crush 支持的配置:

# 指定了 guest 请求断电时执行的操作。可选值有
<on_crush>destroy</on_crush> # domain 将被完全终止并释放所有资源。
<on_crush>restart</on_crush> #domain 将被终止,然后使用相同的配置重新启动。
<on_crush>preserve</on_crush> #domain 将被终止,其资源将被保留以便进行分析。
# 还支持额外的两个操作
<on_cursh>coredump-destroy</on_cursh> # 崩溃 domain 的核心将被转储,然后 domain 将被完全终止并释放所有资源。
<on_cursh>coredump-restart</on_cursh> # 崩溃 domain 的核心将被转储,然后 domain 将使用相同的配置重新启动

disk

为存储设备配置。磁盘文件、虚拟光驱在此项配置。

磁盘总线类型支持:IDE / scsi / usb /virtio

磁盘映像格式支持:raw / qcow2

# 磁盘文件
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
  <source file='/cyq-data/images/test.qcow2'/>
  <target dev='vda' bus='virtio'/>
</disk>

# 虚拟光驱
<disk type='file' device='cdrom'>
    <driver name='qemu' type='raw'/>
    <source file='/iso/Kylin-Server-10-Host-x86_64-Build02-20220627.iso'/>
    <target dev='hdb' bus='ide'/>
    <readonly/>
    <address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>

interface

网络配置,type配置支持网桥、nat等。

网桥需要事先在宿主机中配置桥接网卡,在配置文件中则表示为bridge,即interface type=‘bridge’,并定义桥接网卡,即source bridge=‘my-br’,其中my-br为宿主机中所建立的桥接网卡。

mac地址通常为自动生成,也可指定,但作为虚拟机,mac地址前三段必须为52:54:00。

model type为虚拟机载入的网卡驱动,支持e1000、rt18139、virtio等,写法如下

<interface type='network'>
    <mac address='52:54:34:4d:b4:e0'/>
    <source network='default'/>
    <model type='virtio'/>
</interface>

input

定义虚拟机的输入设备,通常可自动生成,如未生成可添加如下行,注意port不可重复

tablet为数位板,keyboard为键盘,mouse为鼠标,tablet作为鼠标使用。

# 数位板
<input type='tablet' bus='usb'>
    <address type='usb' bus='0' port='3'/>
</input>

# 键盘
<input type='keyboard' bus='usb'>
    <address type='usb' bus='0' port='4'/>
</input>

graphics

为虚拟机图形化配置。

通常设置为vnc以便于远程连接,其中port不可重复,passwd为访问密码,必须设置,listen设置监听端口,通常设置为0.0.0.0,即监听本机全部端口。

设置为vnc时,autoport需设置为no,listen type配置为address,address定义为0.0.0.0。

<graphics type='vnc' port='5925'  autoport='no' passwd='qwer1234' listen='0.0.0.0'>
    <listen type='address' address='0.0.0.0'/>
</graphics>

补充说明

1.磁盘总线类型

虚拟机磁盘总线类型和物理机磁盘总线类型没有直线联系

虚拟机:磁盘总线类型支持:IDE / scsi / /virtio

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值