qemu的命令参数参考文档:
http://qemu.weilnetz.de/qemu-doc.html
下面是一个例子:
/usr/libexec/qemu-kvm -S -M rhel6.3.0
-cpu Westmere,+rdtscp,+pdpe1gb,+dca,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pclmuldq,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme
-enable-kvm -m 2048
-smp 2,sockets=2,cores=1,threads=1
-name inst-1219 -uuid 1cf7a47c-18ec-11e2-92db-14feb5dc2c72 -nodefconfig -nodefaults
-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/inst-1219.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control
-rtc base=localtime -no-shutdown
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2
-drive file=/dev/drVG/lv1567,if=none,id=drive-virtio-disk0,format=raw,cache=none,aio=native
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
-netdev tap,fd=22,id=hostnet0
-device e1000,netdev=hostnet0,id=net0,mac=00:16:3e:66:90:9a,bus=pci.0,addr=0x3
-netdev tap,fd=32,id=hostnet1
-device e1000,netdev=hostnet1,id=net1,mac=00:16:3e:90:70:bd,bus=pci.0,addr=0x4
-chardev pty,id=charserial0
-device isa-serial,chardev=charserial0,id=serial0
-device usb-tablet,id=input0 -vnc 0.0.0.0:9,password -vga cirrus
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
下面进行详细解释:
/usr/libexec/qemu-kvm -S -M rhel6.3.0
-cpu Westmere,+rdtscp,+pdpe1gb,+dca,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pclmuldq,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme
-enable-kvm (允许KVM全虚拟化支持,该选项只有在LINUX编译时就加入了KVM支持的时候才有效)
-m 2048 (RAM内存为2048MB)
-smp 2,sockets=2,cores=1,threads=1 (模拟双核的SMP,最多指定两个sockets,每个socket1个core, 每个core1个thread)
-name inst-1219
-uuid 1cf7a47c-18ec-11e2-92db-14feb5dc2c72 ( system UUID )
-nodefconfig (默认下qemu会从sysconfdir 和 datadir 读取配置, -nodefconfig禁止qemu读取 )
-nodefaults (默认qemu会创建serial port, parallel port, virtual console, monitor device, VGA adapter, floppy and CD-ROM drive and others, -nodefaults禁止创建这些默认的)
-chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/inst-1219.monitor,server,nowait (创建一个指定path的unix socket;server表示是一个linstening socket, nowait表示等待客户端连接的时候不应该阻塞)
-mon chardev=charmonitor,id=monitor,mode=control (把monitor重定向到宿主机设备/var/lib/libvirt/qemu/inst-1219)
-rtc base=localtime -no-shutdown
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 (添加piix3-usb-uhci US B驱动支持)
-drive file=/dev/drVG/lv1567,if=none,id=drive-virtio-disk0,format=raw,cache=none,aio=native (添加一个盘,ID为driver-virtio-disk0, raw格式,无cache, 使用linux native aio)
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 (为driver-virtio-disk0的盘添加驱动virtio-blk-pci)
-netdev tap,fd=22,id=hostnet0 (connet host tap interface to vlan n,fd表示已打开的host tap interface的句柄 ,该虚拟网卡的ID为hostnet0)
-device e1000,netdev=hostnet0,id=net0,mac=00:16:3e:66:90:9a,bus=pci.0,addr=0x3 (为hostnet0网卡添加e1000设备驱动)
-netdev tap,fd=32,id=hostnet1
-device e1000,netdev=hostnet1,id=net1,mac=00:16:3e:90:70:bd,bus=pci.0,addr=0x4
-chardev pty,id=charserial0 (添加一个ID为charserial0的pty设备)
-device isa-serial,chardev=charserial0,id=serial0 (为charserial0设备 添加isa-serial设备驱动)
-device usb-tablet,id=input0
-vnc 0.0.0.0:9,password
-vga cirrus
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
最后用virsh dumpxml inst-1219
<domain type='kvm' id='99'> <name>inst-1219</name> <uuid>1cf7a47c-18ec-11e2-92db-14feb5dc2c72</uuid> <memory unit='KiB'>2097152</memory> <currentMemory unit='KiB'>2097152</currentMemory> <vcpu placement='static'>2</vcpu> <os> <type arch='x86_64' machine='rhel6.3.0'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <cpu mode='custom' match='exact'> <model fallback='allow'>Westmere</model> <vendor>Intel</vendor> <feature policy='require' name='tm2'/> <feature policy='require' name='est'/> <feature policy='require' name='vmx'/> <feature policy='require' name='ds'/> <feature policy='require' name='smx'/> <feature policy='require' name='ss'/> <feature policy='require' name='vme'/> <feature policy='require' name='dtes64'/> <feature policy='require' name='rdtscp'/> <feature policy='require' name='ht'/> <feature policy='require' name='dca'/> <feature policy='require' name='pbe'/> <feature policy='require' name='tm'/> <feature policy='require' name='pdcm'/> <feature policy='require' name='pdpe1gb'/> <feature policy='require' name='ds_cpl'/> <feature policy='require' name='pclmuldq'/> <feature policy='require' name='xtpr'/> <feature policy='require' name='acpi'/> <feature policy='require' name='monitor'/> </cpu> <clock offset='localtime'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='block' device='disk'> <driver name='qemu' type='raw' cache='none' io='native'/> <source dev='/dev/drVG/SNDACLOUD_lv1567'/> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </disk> <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <interface type='bridge'> <mac address='00:16:3e:66:90:9a'/> <source bridge='br1'/> <target dev='vnet17'/> <model type='e1000'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <interface type='bridge'> <mac address='00:16:3e:90:70:bd'/> <source bridge='br2.201'/> <target dev='vnet18'/> <model type='e1000'/> <alias name='net1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </interface> <serial type='pty'> <source path='/dev/pts/25'/> <target port='0'/> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/25'> <source path='/dev/pts/25'/> <target type='serial' port='0'/> <alias name='serial0'/> </console> <input type='tablet' bus='usb'> <alias name='input0'/> </input> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5909' autoport='yes'/> <video> <model type='cirrus' vram='9216' heads='1'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </memballoon> </devices> <seclabel type='none'/> </domain>
参考:
XML格式文档:
http://libvirt.org/format.html
qemu-kvm XML格式文档:
http://libvirt.org/drvqemu.html#xmlconfig
另外qemu参数和XML可以互转,参考:
http://libvirt.org/drvqemu.html
使用命令:
virsh domxml-from-native qemu-argv demo.args (根据参数生成XML)
virsh domxml-to-native qemu-argv demo.xml (根据XML生成参数)
<name>QEmu-fedora-i686</name> <uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid> <memory>219200</memory> <currentMemory>219200</currentMemory> <vcpu>2</vcpu> <os> <type arch='i686' machine='pc'>hvm</type> <boot dev='cdrom'/> </os> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <disk type='file' device='cdrom'> <source file='/home/user/boot.iso'/> <target dev='hdc'/> <readonly/> </disk> <disk type='file' device='disk'> <source file='/home/user/fedora.img'/> <target dev='hda'/> </disk> <interface type='network'> <source network='default'/> </interface> <graphics type='vnc' port='-1'/> </devices> </domain>
<domain type='kvm'> <name>demo2</name> <uuid>4dea24b3-1d52-d8f3-2516-782e98a23fa0</uuid> <memory>131072</memory> <vcpu>1</vcpu> <os> <type arch="i686">hvm</type> </os> <clock sync="localtime"/> <devices> <emulator>/usr/bin/qemu-kvm</emulator> <disk type='file' device='disk'> <source file='/var/lib/libvirt/images/demo2.img'/> <target dev='hda'/> </disk> <interface type='network'> <source network='default'/> <mac address='24:42:53:21:52:45'/> </interface> <graphics type='vnc' port='-1' keymap='de'/> </devices> </domain>