使用xml文件建立虚拟机

步骤一:建立一个空镜像文件(空磁盘)用来存放虚拟机 windows

Qemu-img create -f qcow2/raw  /mnt/sunwei.qcow2 10G dom

步骤二:更改libvirt.xml文件 ide

<name>vm1</name> #更更名字 spa

<memory>8388608</memory> #更改内存 xml

<source file='/bcshare/cluster/instance/i-02672D9E/instance'/ #空镜像文件位置 内存

 <disk type='file' device='cdrom'> get

              <target dev='hdc' bus='ide'/>  虚拟机

              <source file="" />   #iso文件存放位置 io

              <readonly/>   #建立好虚拟机后注释这行,不然启动不了 配置

            </disk>

            <disk type='file' device='cdrom'>

              <target dev='hdd' bus='ide'/>

              <source file="" />      #建立windows虚拟机时,驱动存放位置

              <readonly/>

            </disk>

<graphics type='vnc' port='16606' passwd='ACAEA20F' autoport='no' keymap='en-us' listen='0.0.0.0'/>  #vnc设置

<interface type='bridge'><source bridge='eucabr102'/><mac address='D0:0D:02:67:2D:9E'/><model type='virtio'/></interface> #网卡桥接模式设置,须要更改mac地址,以及桥接名称(br0

步骤3:若是在xml文件内没有设置网卡的话,那么此时就须要手动添加网卡

virsh attach-interface --domain vm1 --type bridge --source br0

步骤4:此时物理机上面就会将br0vnet0绑定在一块儿,这只是临时添加的,若是须要永久添加的话,就须要执行下面的这条语句

Virsh dumpxml vm1 >/mnt/libvirt.xml  #将生成的新的配置文件导入原始的xml文件,达到永久保存。

[root@localhost libvirt]# ls

libvirt.conf  libvirtd.conf  lxc.conf  nwfilter  qemu  qemu.conf  qemu-lockd.conf  storage  virtlockd.conf

[root@localhost libvirt]# cd qemu/

[root@localhost qemu]# ls

networks  rhel7.0.xml  vm1.xml  vm2.xml  

[root@localhost qemu]# pwd #本身建立的虚拟机xml文件存放位置

/etc/libvirt/qemu

[root@localhost qemu]# cd /var/lib/libvirt/images/

[root@localhost images]# ls

rhel7.0.qcow2  vm1  vm2

[root@localhost images]# pwd

/var/lib/libvirt/images #镜像存放位置

相关文章
相关标签/搜索