Syn*_*r0r 14 linux kvm libvirt
我对 virt-manager / libvirt / KVM 有点迷茫。
我有一个运行良好的 KVM VM (Windows XP)。
VM 由一个 4GB 左右的文件(一个.img)支持。
现在我想做一些非常简单的事情:我想复制我的虚拟机。
我想“好吧,没问题,让我们复制 4GB 文件并复制 XML”文件。
但随后 libvirt 常见问题解答以全部大写表示:“你不应该关心 XML 存储在哪里”
好吧,我不应该在意。但是我该如何复制我的虚拟机呢?
我想创建一个新的 VM,它是该 VM 的副本。
小智 44
最方便的就是:
# virt-clone --connect=qemu://example.com/system -o this-vm -n that-vm --auto-clone
Run Code Online (Sandbox Code Playgroud)
它将制作this-vm
、 命名的副本that-vm
,并负责复制存储设备。除了细节,这里没有什么新东西。
更重要的是,FAQ 说的是 XML 域描述不能直接编辑,您需要通过libvirt。要完成virt-clone
命令所采取的步骤,您可以:
source_vm=vm_name
new_vm=new_vm_name
# You cannot "clone" a running vm, stop it. suspend and destroy
# are also valid options for less graceful cloning
virsh shutdown "$source_vm"
# copy the storage.
cp /var/lib/libvirt/images/{"$source_vm","$new_vm"}.img
# dump the xml for the original
virsh dumpxml "$source_vm" > "/tmp/$new_vm.xml"
# hardware addresses need to be removed, libvirt will assign
# new addresses automatically
sed -i /uuid/d "/tmp/$new_vm.xml"
sed -i '/mac address/d' "/tmp/$new_vm.xml"
# and actually rename the vm: (this also updates the storage path)
sed -i "s/$source_vm/$new_vm" "/tmp/$new_vm.xml"
# finally, create the new vm
virsh define "/tmp/$new_vm.xml"
virsh start "$source_vm"
virsh start "$new_vm"
Run Code Online (Sandbox Code Playgroud)
小智 5
除了“virt-clone”,您还可以通过以下方式复制虚拟机: