xml文件创建虚拟机

本文介绍了如何使用XML文件创建虚拟机,首先详细讲解了如何制作CentOS7的后端模板系统,包括配置virsh console以便连接。接着说明了创建前端盘和XML配置文件的步骤,提供了XML文件示例,最后阐述了启动虚拟机的方法。
摘要由CSDN通过智能技术生成

一、制作后端模板系统(CentOS7)
先创建后端盘:

qemu-img create -f qcow2 CentOS7.img 2G

用virt-manager使用这个后端盘,完成后进入系统调试为模板系统
注意:
制作模板系统时可提前配置virsh console可连接:
1.进入虚机中,编辑 /etc/default/grub 文件,找到下面行:

GRUB_CMDLINE_LINUX="rhgb quiet"

改为:(尾部增加 console=ttyS0,115200)

GRUB_CMDLINE_LINUX="rhgb quiet console=ttyS0,115200”

2.使用以下命令激活服务(这个是centos7才有的服务,但默认没有启动)

systemctl start serial-getty@ttyS0.service
systemctl enable serial-getty@ttyS0.service

3.重启系统验证后关机

virsh console centos7
poweroff

二、创建前端盘和xml文件
1.基于后端盘创建前端盘:

cd /var/lib/libvirt/images/
qemu-img create -f qcow2 -b CentOS7.img centos7-1.img 20G

2.创建xml配置文件(默认路径:/etc/libvirt/qemu/):

virsh dumpxml CentOS7 >centos7-1.xml
vim centos7-1.xml
<domain type='kvm'>		#删除id=''
<name>myrh7_2</name>	#修改虚拟机名
						#删除UUID整行(会自动生成)
<source file='/var/lib/libvirt/images/centos7-1.img'/>	#修改所用磁盘
						#删除网卡mac地址行
						#删除<channel type='unix' >闭合块

附上xml文件供直接拷贝:

<!--
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 centos7-1
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>centos7-1</name>	#虚拟机名
  <memory unit='KiB'>1048576</memory>	#内存大小
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <bootmenu enable='yes'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='partial'>
    <model fallback='allow'>Broadwell-noTSX-IBRS</model>
    <feature policy='require' name='md-clear'/>
    <feature policy='require' name=
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值