使用xml文件创建虚拟机

步骤一:创建一个空镜像文件(空磁盘)用来存放虚拟机

Qemu-imgcreate-fqcow2/raw/mnt/sunwei.qcow210G

步骤二:更改libvirt.xml文件

<name>vm1</name>#更改名字

<memory>8388608</memory>#更改内存

<sourcefile='/bcshare/cluster/instance/i-02672D9E/instance'/#空镜像文件位置

<disktype='file'device='cdrom'>

<targetdev='hdc'bus='ide'/>

<sourcefile=""/>#iso文件存放位置

<readonly/>#创建好虚拟机后注释这行,否则启动不了

</disk>

<disktype='file'device='cdrom'>

<targetdev='hdd'bus='ide'/>

<sourcefile=""/>#创建windows虚拟机时,驱动存放位置

<readonly/>

</disk>

<graphicstype='vnc'port='16606'passwd='ACAEA20F'autoport='no'keymap='en-us'listen='0.0.0.0'/>#vnc设置

<interfacetype='bridge'><sourcebridge='eucabr102'/><macaddress='D0:0D:02:67:2D:9E'/><modeltype='virtio'/></interface>#网卡桥接模式设置,需要更改mac地址,以及桥接名称br0

步骤3:如果在xml文件内没有设置网卡的话,那么此时就需要手动添加网卡

virshattach-interface--domainvm1--typebridge--sourcebr0

步骤4:此时物理机上面就会将br0vnet0绑定在一起,这只是临时添加的,如果需要永久添加的话,就需要执行下面的这条语句

Virshdumpxmlvm1>/mnt/libvirt.xml#生成的新的配置文件导入原始的xml文件,达到永久保存。

[root@localhostlibvirt]#ls

libvirt.conflibvirtd.conflxc.confnwfilterqemuqemu.confqemu-lockd.confstoragevirtlockd.conf

[root@localhostlibvirt]#cdqemu/

[root@localhostqemu]#ls

networksrhel7.0.xmlvm1.xmlvm2.xml

[root@localhostqemu]#pwd#自己创建的虚拟机xml文件存放位置

/etc/libvirt/qemu

[root@localhostqemu]#cd/var/lib/libvirt/images/

[root@localhostimages]#ls

rhel7.0.qcow2vm1vm2

[root@localhostimages]#pwd

/var/lib/libvirt/images#镜像存放位置

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念