时间同步字段
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock>
特殊业务使用字段
<interface type='bridge'>
<mac address='52:54:2f:63:36:0c'/>
<source bridge='br_bond0_65'/>
<model type='e1000'/>
<boot order='1'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</interface>
网卡驱动
<interface type='bridge'>
<mac address='${vmmac}'/>
<source bridge='br_bond0_115'/>
<model type='virtio'/>
<boot order='1'/>
<alias name='net0'/>
</interface>
kvm: vcpu 0: requested 7812 ns lapic timer period limited to 200000 ns 虚拟机内部重启
kvm: 1 guest now active api推送重启过
kvm: 0 guest now active 关机
<domain type='kvm'>
<name>vm64-1</name> //虚拟机名称
<memory unit='MiB'>2300</memory> //最大内存,单位M
<currentMemory unit='MiB'>2300</currentMemory> //可用内存,单位M
<vcpu>3</vcpu> //虚拟cpu个数
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/> //硬盘启动
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/home/kvm/images/vm64-1.raw'/> //目的镜像路径
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> /*硬盘使用virtio驱动后识别为pci总线*/
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/home/kvm/images/ex.img'/> //目的镜像路径
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/> /*硬盘使用virtio驱动后识别为pci总线*/
</disk>
<interface type='bridge'> //虚拟机网络连接方式
<source bridge='vm1_br_debug'/> //当前主机网桥的名称 vm-eth0
<virtualport type='openvswitch'/>
<model type='virtio'/>
<driver name='vhost' queues='8'/>
<mac address="00:16:3E:64:01:00"/> //为虚拟机分配mac地址,务必唯一,否则dhcp获得同样ip,引起冲突
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
<interface type='bridge'> //虚拟机网络连接方式
<source bridge='vm1_br_protocol'/> //当前主机网桥的名称 vm-eth1
<virtualport type='openvswitch'/>
<model type='virtio'/>
<driver name='vhost' queues='8'/>
<mac address="00:16:3E:64:01:01"/> //为虚拟机分配mac地址,务必唯一,否则dhcp获得同样ip,引起冲突
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</interface>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>//vnc方式登录,端口号自动分配,自动加1,可以通过virsh vncdisplay来查询
</devices>
</domain>
qcow2转成raw:将CentOS-6.9.qcow2转为 CentOS-6.9.raw
$ qemu-img convert -f qcow2 -O raw CentOS-6.9.qcow2 CentOS-6.9.raw
raw转qcow2:
$ qemu-img convert -f raw -O qcow2 CentOS-6.9.raw CentOS-6.9.qcow2
[root@10-117-154-95 opt]# qemu-img convert -f raw -O qcow2 nenlyimage2008051pwd12345678_m-2zecj7a5r3os9hnqgd7n_system.raw nenlyimage2008051pwd12345678_m-2zecj7a5r3os9hnqgd7n_system.qcow2
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/kvmdata/centos7.0-02.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/kvmdata/centos7.0-02.qcow2'/>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x17' function='0x0'/>
</disk>
磁盘盘符信息
dev='vda'
dev='vdb'
硬件pci信息
slot='0x07'
slot='0x17'
对于Intel CPU 可用命令 grep "vmx" /proc/cpuinfo 判断
对于AMD CPU 可用命令 grep "svm" /proc/cpuinfo 判断
1. 查看原磁盘大小。
qemu-img info kvm-win10_add.qcow2
2.增加150G
qemu-img resize kvm-win10_add.qcow2 +150G
3. 查看增加后的磁盘大小
qemu-img info kvm-win10_add.qcow2
创建硬盘
qemu-img create -f qcow2 -o preallocation=metadata /data/disk.qcow2 80G 创建一个80G的硬盘,可以用于挂在到kvm虚拟机
限速5M
<bandwidth>
<inbound average='1000'
peak='5000' burst='5120'/>
<outbound average='1000'
peak='5000' burst='5120'/>
</bandwidth>
模板
<interface type='network'>
<mac address='52:54:00:8d:60:f9'/>
<source network='default'/>
<bandwidth>
<inbound average='10' peak='10' burst='10'/>
<outbound average='10' peak='10' burst='10'/>
</bandwidth>
<target dev='vnet39'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>