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 the define command again!

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

 

s199425@s199425-OptiPlex-780:~/vm$ cat ubuntutest.xml
<domain type='kvm'>
 <name>ubuntutest</name>
 <uuid>0f0806ab-531d-6134-5def-c5b4955292aa</uuid>
 <memory unit='KiB'>1048576</memory>
 <currentMemory unit='KiB'>1048576</currentMemory>
 <vcpu placement='static'>1</vcpu>
 <os>
 <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
 <boot dev='hd'/>
 </os>
 <features>
 <acpi/>
 <apic/>
 <pae/>
 </features>
 <clock offset='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>
 <disk type='file' device='disk'>
 <driver name='qemu' type='qcow2'/>
 <source file='/home/s199425/vm/ubuntutest.qcow2'/>
 <target dev='vda' bus='virtio'/>
 </disk>
 <controller type='pci' index='0' model='pci-root'/>
 <interface type='bridge'>
 <mac address='fa:16:3e:6e:89:ce'/>
 <source bridge='br0'/>
 <target dev='tap1'/>
 <model type='virtio'/>
 <alias name='net0'/>
 </interface>
 <serial type='pty'>
 <target port='0'/>
 </serial>
 <console type='pty'>
 <target type='serial' port='0'/>
 </console>
 <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
 <listen type='address' address='0.0.0.0'/>
 </graphics>
 <video>
 <model type='cirrus' vram='9216' heads='1'/>
 <alias name='video0'/>
 </video>
 <memballoon model='virtio'>
 <alias name='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=C PATH=/bin HOME=/home/test USER=test 
LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 
-nographic -monitor pty -no-acpi -boot c -hda 
/dev/HostVG/QEMUGuest1 -net none -serial none 
-parallel none -usb
EOF

$ virsh domxml-from-native qemu-argv demo.args
Converting from domain XML to QEMU args
$ cat > demo.xml <<EOF
<domain type='qemu'>
  <name>QEMUGuest1</name>
  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
  <memory>219200</memory>
  <currentMemory>219200</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='i686' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu</emulator>
    <disk type='block' device='disk'>
      <source dev='/dev/HostVG/QEMUGuest1'/>
      <target dev='hda' bus='ide'/>
    </disk>
  </devices>
</domain>
EOF

$ virsh domxml-to-native qemu-argv demo.xml

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

root@ubuntu:/home/s199425/VM# qemu-img convert -O qcow2 -c ubuntu.12-04.x86.20141001.raw.img ubuntu.12-04.x86.20141001.raw.img.qcow2
root@ubuntu:/home/s199425/VM# nano ubunturaw.xml

root@ubuntu:/home/s199425/VM# virsh create ubunturaw.xml
Domain ubuntutraw created from ubunturaw.xml
~~

http://libvirt.org/drvqemu.html

Example domain XML config

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