Qemu&KVM第二篇之3使用virsh xml file 创建VM

Before you start a new VM for the first time,you must define it from its xml file(located in the/etc/libvirt/qemu/directory):

define/etc/libvirt/qemu/vm1.xml

Please note that whenever you modify the VM’s xml file in/etc/libvirt/qemu/,you must run thedefinecommand again!

在/etc/libvirt/qemu/可以找到已生成好的xml 文件, 在/var/lib/libvirt/images 可以找到 image

s199425@s199425-OptiPlex-780:~/vm$catubuntutest.xml
<domaintype='kvm'>
<name>ubuntutest</name>
<uuid>0f0806ab-531d-6134-5def-c5b4955292aa</uuid>
<memoryunit='KiB'>1048576</memory>
<currentMemoryunit='KiB'>1048576</currentMemory>
<vcpuplacement='static'>1</vcpu>
<os>
<typearch='x86_64'machine='pc-i440fx-trusty'>hvm</type>
<bootdev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clockoffset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disktype='file'device='disk'>
<drivername='qemu'type='qcow2'/>
<sourcefile='/home/s199425/vm/ubuntutest.qcow2'/>
<targetdev='vda'bus='virtio'/>
</disk>
<controllertype='pci'index='0'model='pci-root'/>
<interfacetype='bridge'>
<macaddress='fa:16:3e:6e:89:ce'/>
<sourcebridge='br0'/>
<targetdev='tap1'/>
<modeltype='virtio'/>
<aliasname='net0'/>
</interface>
<serialtype='pty'>
<targetport='0'/>
</serial>
<consoletype='pty'>
<targettype='serial'port='0'/>
</console>
<graphicstype='vnc'port='-1'autoport='yes'listen='0.0.0.0'>
<listentype='address'address='0.0.0.0'/>
</graphics>
<video>
<modeltype='cirrus'vram='9216'heads='1'/>
<aliasname='video0'/>
</video>
<memballoonmodel='virtio'>
<aliasname='balloon0'/>
</memballoon>
</devices>
</domain>

virsh define *.xml
virsh start

Converting from QEMU args to domain XML

http://libvirt.org/drvqemu.html

$cat>demo.args<<EOF
LC_ALL=CPATH=/binHOME=/home/testUSER=test
LOGNAME=test/usr/bin/qemu-S-Mpc-m214-smp1
-nographic-monitorpty-no-acpi-bootc-hda
/dev/HostVG/QEMUGuest1-netnone-serialnone
-parallelnone-usb
EOF

$virshDomXML-from-nativeqemu-argvdemo.args
Converting from domain XML to QEMU args
$cat>demo.xml<<EOF
<domaintype='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</currentMemory>
<vcpu>1</vcpu>
<os>
<typearch='i686'machine='pc'>hvm</type>
<bootdev='hd'/>
</os>
<clockoffset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disktype='block'device='disk'>
<sourcedev='/dev/HostVG/QEMUGuest1'/>
<targetdev='hda'bus='ide'/>
</disk>
</devices>
</domain>
EOF

$virshDomXML-to-nativeqemu-argvdemo.xml

再测试一次 成功
先拷贝prebuild img ,
创建 xml 文件
然后 virsh create <VM name>
记得要 看看网卡设置

root@ubuntu:/home/s199425/VM#qemu-imgconvert-Oqcow2-cubuntu.12-04.x86.20141001.raw.imgubuntu.12-04.x86.20141001.raw.img.qcow2
root@ubuntu:/home/s199425/VM#nanoubunturaw.xml

root@ubuntu:/home/s199425/VM#virshcreateubunturaw.xml
Domainubuntutrawcreatedfromubunturaw.xml
~~

http://libvirt.org/drvqemu.html

Example domain XML config

QEMU emulated guest on x86_64
<domaintype='qemu'>
<name>QEmu-fedora-i686</name>
<uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid>
KVM hardware accelerated guest on i686
<domaintype='kvm'>
<name>demo2</name>
<uuid>4dea24b3-1d52-d8f3-2516-782e98a23fa0</uuid>

相关文章

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