KVM虚拟化笔记(六)------kvm虚拟机的克隆
  TEZNKK3IfmPf 2023年11月12日 25 0

  kvm虚拟机的克隆分为两种情况:kvm主机本机虚拟机直接克隆和通过复制配置文件与磁盘文件的虚拟机复制克隆。接下来我们一一进行测试:

(一)kvm主机虚拟机的直接克隆

1,查看虚拟机的配置文件和磁盘文件:

[root@KVM qemu]# cat /etc/libvirt/qemu/hadoop1.xml 
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE 
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit hadoop1
or other application using the libvirt API.
-->
<domain type='qemu'>
  <name>hadoop1</name>
  <uuid>919f0921-0736-ad5b-780b-a440de2f35cb</uuid>
  <memory unit='KiB'>524288</memory>
  <currentMemory unit='KiB'>524288</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='rhel6.6.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <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='raw' cache='none'/>
      <source file='/p_w_picpaths/test/hadoop1.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
    </controller>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:b6:bf:1f'/>
      <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='mouse' bus='ps2'/>
    <graphics type='vnc' port='5911' autoport='no' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <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>

查看磁盘文件

[root@KVM test]# ll  /p_w_picpaths/test/
total 2688992
-rwxr-xr-x 1 root root 10737418240 Feb  4 14:38 hadoop1.img
-rwxr-xr-x 1 qemu qemu 10737418240 Feb  4 14:43 hadoop4.img
-rwxr-xr-x 1 qemu qemu  8589934592 Feb  2 15:03 win7.img
[root@KVM test]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     win7                           running
 3     hadoop4                        running
 -     hadoop1                        shut off

2,开始克隆

[root@KVM qemu]# virt-clone -o hadoop1 -n hadoop2 -f /p_w_picpaths/test/hadoop2.img
Cloning hadoop1.img                                                                    |  10 GB     02:52     
Clone 'hadoop2' created successfully.

KVM虚拟化笔记(六)------kvm虚拟机的克隆KVM虚拟化笔记(六)------kvm虚拟机的克隆_kvm_02

3,然后启动虚拟机,配置主机名,ip地址等等相关的信息,相关详细配置都是经常使用的略。


 (二)复制配置文件与磁盘文件克隆

这里采用以hadoop4作为模板,来进行克隆。

1,关闭hadoop4虚拟机

[root@KVM qemu]# virsh destroy hadoop4
Domain hadoop4 destroyed
[root@KVM qemu]# virsh list --all     
 Id    Name                           State
----------------------------------------------------
 1     win7                           running
 6     hadoop2                        running
 -     hadoop1                        shut off
 -     hadoop4                        shut off

2,克隆hadoop4.xml文件

[root@KVM qemu]# virsh dumpxml hadoop4 > /etc/libvirt/qemu/hadoop3.xml
[root@KVM qemu]# ll /etc/libvirt/qemu/
total 32
drwxr-xr-x 2 root root 4096 Feb  2 17:18 autostart
-rw-r--r-- 1 root root    1 Feb  2 17:13 hadoop1.bak.xml
-rw------- 1 root root 2998 Feb  2 13:54 hadoop1.xml
-rw------- 1 root root 2998 Feb  4 14:54 hadoop2.xml
-rw-r--r-- 1 root root 2740 Feb  4 15:12 hadoop3.xml
-rw------- 1 root root 2965 Feb  2 17:25 hadoop4.xml
drwx------ 3 root root 4096 Jan 26 16:47 networks
-rw------- 1 root root 3036 Feb  2 15:52 win7.xml

KVM虚拟化笔记(六)------kvm虚拟机的克隆_笔记_033,复制kvm虚拟机磁盘文件,该磁盘文件的路径也可以通过配置文件xml, <source file='/p_w_picpaths/test/hadoop4.img'/>路径进行查看

[root@KVM test]# cp hadoop4.img hadoop3.img
[root@KVM test]# ls
hadoop1.img  hadoop2.img  hadoop3.img  hadoop4.img  win7.img

KVM虚拟化笔记(六)------kvm虚拟机的克隆

    <boot dev='hd'/>

  </os>

  <features>

    <acpi/>

    <apic/>

    <pae/>

  </features>

  <clock offset='utc'/>

  <on_poweroff>destroy</on_poweroff>

  <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='raw' cache='none'/>

      <source file='/p_w_picpaths/test/hadoop4.img'/>

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

      <address type='drive' controller='0' bus='0' target='0' unit='0'/>

    </disk>

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

      <driver name='qemu' type='raw'/>

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

      <readonly/>

      <address type='drive' controller='0' bus='1' target='0' unit='0'/>

    </disk>

    <controller type='usb' index='0' model='ich9-ehci1'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci1'>

      <master startport='0'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci2'>

      <master startport='2'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci3'>

      <master startport='4'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>

    </controller>

    <controller type='ide' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

    </controller>

    <interface type='network'>

      <mac address='52:54:00:fe:f5:a3'/>

      <source network='default'/>

      <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='mouse' bus='ps2'/>

    <graphics type='vnc' port='5913' autoport='no' listen='0.0.0.0'>

      <listen type='address' address='0.0.0.0'/>

    </graphics>

    <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='0x05' function='0x0'/>

    </memballoon>

  </devices>

</domain>


4,重新定义新虚拟机的配置文件

[root@KVM qemu]# virsh define /etc/libvirt/qemu/hadoop3.xml 
Domain hadoop3 defined from /etc/libvirt/qemu/hadoop3.xml
[root@KVM qemu]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     win7                           running
 6     hadoop2                        running
 -     hadoop1                        shut off
 -     hadoop3                        shut off
 -     hadoop4                        shut off

KVM虚拟化笔记(六)------kvm虚拟机的克隆_虚拟化_05


5,最后启动该虚拟机,登录进行相关的配置等等。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月12日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2023年11月15日   37   0   0 KVM
  TEZNKK3IfmPf   2023年11月13日   71   0   0 磁盘KVM虚拟机
  TEZNKK3IfmPf   2023年11月13日   45   0   0 KVM虚拟机
  TEZNKK3IfmPf   2023年11月13日   42   0   0 虚拟化CPU
TEZNKK3IfmPf