KVM配置之(3)- 克隆

 1.KVM主機虛擬機直接克隆

virt-clone -o module-IT -n lb-test2 -f /data/vm/vmfiles/lb-tes2.img
說明:以modeule-IT做爲源,克隆module-IT以及module-IT.img,並創建名稱爲lb-test2,鏡像爲-f /data/vm/vmfiles/lb-tes2.img

啓動虛擬機配置主機名,IP地址等

2.通過複製配置文件與磁盤文件的虛擬機克隆(適用於異機的靜態遷移)

(1)確認源虛擬機:

[root@server ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     test1                          running
 2     lu-test1                       running
 3     module-IT-oa-test              running
 4     test2-IT                       running
 5     IT-clone-TEST                  running
 9     LB_test1                       running
 10    lb-test2                       running
 -     clean                          shut off
 -     module-IT                      shut off
 -     Winprinter                     shut off
[root@server ~]# virsh shutdown LB_test1
Domain lb-test2 is being shutdown

(2).導入KVM虛擬機配置文件

[root@server ~]# virsh dumpxml LB_test1 >/etc/libvirt/qemu/LB_test2.xml

(3).複製KVM虛擬機磁盤文件

[root@server vmfiles]# cp binzai.qcow2 binzai-test2.qcow2

(4).直接編輯配置文件

[root@server vmfiles]# vim /etc/libvirt/qemu/LB_test2.xml 
<domain type='kvm'>
  <name>LB_test1</name>  #由字母和數字組成,不能包含空格
  <uuid>9ea6f52f-1a18-5a8a-7920-611efa92c8c9</uuid>  #由命令行工具uuidgen生成
  <memory unit='KiB'>1048576</memory>   #在不reboot guest情況下,guset可以使用的最大內存,以KB爲單位
  <currentMemory unit='KiB'>1048576</currentMemory>  #guest啓動時內存,可以通過virsh setmem來調整,但是不能大於最大可使用內存
  <vcpu placement='static'>1</vcpu>  #分配的虛擬CPU
  <os>
    <type arch='x86_64' machine='rhel6.4.0'>hvm</type>  #架構:64位,machine:宿主機的操作系統
    <boot dev='hd'/>  #指定啓動設備,可以重複多行,指定不同的值,作爲一個啓動設備列表
  </os>
  <features>   #處理器特性
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>  #(utc該爲localtime)Kvm虛擬機採用utc時間,需要先修改配置文件使用KVM虛擬機的時間與虛擬主機同步。
  <on_poweroff>destroy</on_poweroff> #停止虛擬機,相當於關閉電源,Kill kvm進程也是一樣
  <on_reboot>restart</on_reboot>  
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>  #模擬元素
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/p_w_picpaths/binzai.qcow2'/>   #使用qumu-img命令創建該文件,kvm p_w_picpath的默認目錄爲:。。。。。
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>    
#採用普通的驅動,即硬盤和網卡都採用默認配置情況下,硬盤爲ide模式,採用virtio驅動,硬盤工作在SCSI模式下
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <interface type='bridge'>  #網卡
      <mac address='52:54:00:93:45:fe'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
</domain>

(5).定義新虛擬機配置文件

[root@server vmfiles]# virsh define /etc/libvirt/qemu/LB_test2.xml

(6).啓動虛擬

virsh start LB_test2


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章