使用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 #鏡像存放位置

相關文章
相關標籤/搜索