xml文件
注意点: 1. 设置memory的时候,注意unit的写法 2. emulator的路径,写成一行 3. 能不分行写,一个标签,尽量写在一行 4. 使用
qemu-img管理工具创建虚拟机文件,例如:qemu-img create -f qcow2 test.qcow2 10G5. 创建的文件没有权限,需要将创建的虚拟机文件更改用户组sudo chown hgf:root /var/lib/libvirt/images/test.qcow2. 即执行start的用户的名下
1<domain type="kvm"> 2 <name>centos</name> 3 4 <memory unit="MiB">1024</memory> 5 <currentMemory unit="MiB">1024</currentMemory> 6 7 <vcpu>2</vcpu> 8 9 <os> 10 <type arch="x86_64" machine="pc">hvm</type> 11 <boot dev="hd" /> 12 <boot dev="cdrom" /> 13 </os> 14 15 <features> 16 <acpi /> 17 <apic /> 18 <pae /> 19 </features> 20 21 <clock offset="localtime" /> 22 23 <on_poweroff>destroy</on_poweroff> 24 <on_reboot>restart</on_reboot> 25 <on_crash>destroy</on_crash> 26 27 <devices> 28 <emulator>/usr/libexec/qemu-kvm</emulator> 29 30 <disk type="file" device="disk"> 31 <driver name="qemu" type="qcow2"/> 32 <source file="/var/lib/libvirt/images/test.qcow2" /> 33 <target dev="hda" bus="ide"/> 34 </disk> 35 36 <disk type="file" device="cdrom"> 37 <source file="/home/hgf/Dowmload/CentOS-7.0-1406-x86_64-DVD.iso" /> 38 <target dev="hdb" bus="ide"/> 39 </disk> 40 41 <interface type="bridge"> 42 <source bridge="virbr0"/> 43 </interface> 44 45 <input type="mouse" bus="ps2" /> 46 <graphics type="vnc" port="-1" autoport="yes" listen="0.0.0.0" keymap="en-us" /> 47 48 </devices> 49 50 51</domain> 52
定义虚拟机
virsh define test_virsh.xml
使用
virsh undefine [虚拟主机名]来取消虚拟机的定义
启动虚拟机
virsh start cetos
start后面的参数,是之前用xml定义的虚拟机的name标签指定的,也可以在define虚拟机后,使用命令
virsh list --alll
vnc查看虚拟机
查询虚拟机所使用的vnc端口 virsh vncdisplay centos
vncviewer安装
yum install vnc(安扎ungde是tiger vncviewer) 打开vnc viewer后,在地址栏输入IP地址:序号,如127.0.0.1:0
注意:此处的序号是使用
virsh vncdisplay 主机名查询出来的