kvm系列02|克隆虚拟机
1、同宿主机克隆
被克隆的虚拟机先关机,然后命令克隆:
[root@localhost centos]# virt-clone -o vm1 -n centos74-01 -f /data1/kvm/centos/centos74-01.img
WARNING Setting the graphics device port to autoport, in order to avoid conflicting.
Allocating 'centos74-01.img' | 40 GB 00:00:03
Clone 'centos74-01' created successfully.
修改vnc
端口:[root@localhost kvm]# virsh edit centos74-01
<graphics type='vnc' port='5914' autoport='no' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
启动虚拟机:
[root@localhost data1]# virsh list
Id Name State
----------------------------------------------------
[root@localhost data1]# virsh start centos74-01
Domain centos74-01 started
[root@localhost data1]# virsh list
Id Name State
----------------------------------------------------
6 centos74-01 running
[root@localhost data1]#
2、异宿主机克隆或迁移
异宿主机克隆、迁移,操作之前最好也先把虚拟机关机。三个步骤:
-
1、拷贝模板虚拟机 -
2、 dumpxml
并修改xml
配置 -
3、去定义虚拟机。
步骤一:拷贝模板虚拟机 拷贝克隆,一般用于异宿主机。直接把宿主机的虚拟机关机,然后整个文件夹拷贝过去。
<domain type='kvm'>
<name>vm1</name>
<memory>2194304</memory>
<currentMemory>2194304</currentMemory>
<vcpu>2</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/> //硬盘启动
<boot dev='cdrom'/> //光盘启动
<boot dev='network'/> //网络启动
</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='qcow2' cache='none'/>
<source file='/data/kvm/vm1/vm1-01.qcow2'/> //目的镜像路径
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/data/kvm/vm1/vm1-02.qcow2'/> //目的镜像路径
<target dev='vdb' bus='virtio'/>
</disk>
<interface type='bridge'>
<source bridge='br0' />
<model type='virtio' />
</interface>
<interface type='bridge'>
<source bridge='br1' />
<model type='virtio' />
</interface>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<graphics type='vnc' port='5917' listen = '0.0.0.0' passwd='12345678' keymap='en-us'/>
</devices>
</domain>
步骤三:去定义虚拟机。
virsh define vm1.xml # 定义虚拟机
virsh start vm1 # 启动虚拟机
感谢阅读,如有帮助,欢迎赞赏、转发、点在看