设为首页 收藏本站
查看: 2154|回复: 0

[经验分享] qemu-kvm创建参数分析

[复制链接]
发表于 2016-1-8 10:56:05 | 显示全部楼层 |阅读模式
  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生成参数)
  


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>
<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>
 
KVM hardware accelerated guest on i686
  

<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>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-161806-1-1.html 上篇帖子: ubuntu安装kvm虚拟机(转) 下篇帖子: ubuntu kvm+qemu 加载USB
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表