发布于2022年11月4日3年前 应用virsh和xml文件创立虚拟机 (1)硬盘镜像文件:格局:raw或qcow2# qemu-img create -f raw fdisk.img 10G# qemu-img info fdisk.img(2)编写xml设置装备摆设文件,这一步在后面做具体先容(3)创立并运转虚构机# virsh define vm0.xml //导入虚构机设置装备摆设# virsh start vm0 //开启vm0# virsh list --all // 表现一切虚构机状况# virsh destroy vm0 //烧毁虚构机# virsh undefine vm1 //删除虚构机设置装备摆设# virsh dumpxml vm0 //表现虚构机xml设置装备摆设此中“vm0.xml”是步调(2)中创立的xml文件。虚构机XML文件<domain type="kvm"> //如果是Xen,则type=‘xen’ <name>vm0</name> //虚构机称号,统一物理机独一 <uuid>fd3535db-2558-43e9-b067-314f48211343</uuid> //统一物理机独一,可用uuidgen天生 <memory>524288</memory> <currentmemory>524288</currentmemory> //memory这两个值最佳设成同样 <vcpu>2</vcpu> //虚构机能够使用的cpu个数,检查物理机可用CPU个数:cat /proc/cpuinfo |grep processor | wc -l <os> <type arch="x86_64" machine="pc-i440fx-vivid">hvm</type> //arch指出体系架构范例,machine 则是机械范例,检查机械范例:qemu-system-x86_64 -M ? <boot dev="hd"> //启动介质,第一次必要装体系能够抉择cdrom光盘启动 <bootmenu enable="yes"> //表现启动按F12进入启动菜单 </bootmenu></boot></os> <features> <acpi> //Advanced Configuration and Power Interface,高档设置装备摆设与电源接口 <apic> //Advanced Programmable Interrupt Controller,高档可编程中止控制器 <pae> //Physical Address Extension,物理地点扩大 </pae></apic></acpi></features> <clock offset="localtime"> //虚构机时钟设置,这里表现当地本机光阴 <on_poweroff>destroy</on_poweroff> //突发事件举措 <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> //装备设置装备摆设 <emulator>/usr/bin/kvm</emulator> //如果是Xen则是/usr/lib/xen/binqemu-dm <disk device="disk" type="file"> //硬盘 <driver name="qemu" type="raw"> <source file="/opt/vm/vmdev/fdisk.img"> <target bus="virtio" dev="vda"><address bus="0x00" domain="0x0000" function="0x0" slot="0x06" type="pci"> //域、总线、槽、功效号,slot值统一虚构机上独一 <disk device="disk" type="file"> <driver name="qemu" type="raw"> <source file="/opt/vm/vmdev/fdisk2.img"> <target bus="virtio" dev="vdb"> </target></source></driver></disk> <disk device="cdrom" type="file"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img">//光盘 <driver name="qemu" type="raw"> <source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"> <target bus="ide" dev="hdc"> <readonly> </readonly></target></source></driver></source></source></source></source></source></source></disk> <interface type="bridge"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmdev/fdisk2.img"><source file="/opt/vm/vmiso/ubuntu-15.10-server-amd64.iso"><source file="/opt/vm/vmdev/fdisk2.img"> //应用Linux网桥衔接收集 <mac address="fa:92:01:33:d4:fa"> <source bridge="br100"> //设置装备摆设的网桥网卡称号 <target dev="vnet0"> //统一网桥下雷同 <alias name="net0"> //别号,统一网桥下雷同<address bus="0x00" domain="0x0000" function="0x0" slot="0x03" type="pci"> //留意slot值独一 /* 应用ovs网桥衔接收集 <interface type="bridge"> <source bridge="br-ovs0"> <virtualport type="openvswitch"> <target dev="tap0"> <model type="virtio"> </model></target></virtualport></source></interface>*//* 设置装备摆设成pci纵贯虚构机衔接收集,SR-IOV网卡的VF场景<hostdev managed="yes" mode="subsystem" type="pci"><source bridge="br-ovs0"><source bridge="br-ovs0"><source bridge="br-ovs0"><source bridge="br-ovs0"><source bridge="br-ovs0"><source bridge="br-ovs0"> <source><address bus="0x03" domain="0x0000" function="0x0" slot="0x00"> */interface type='network'> //基于虚构局域网的收集 <mac address="52:54:4a:e1:1c:84"> //可用敕令天生,见下面的弥补 <source network="default"> //默许 <target dev="vnet1"> //统一虚构局域网的值雷同 <alias name="net1"><address bus="0x00" domain="0x0000" function="0x0" slot="0x04" type="pci"> //留意slot值 <graphics autoport="yes" keymap="en-us" listen="0.0.0.0" port="5900" type="vnc" virsh="" vm0="" vncdisplay=""> <listen address="0.0.0.0" type="address"> </listen></graphics></address></alias></target></source></mac></address></source></source
创建帐户或登录后发表意见