Crmgo Blog

KVM, cloning error in CentOS 7

KVM, cloning error in CentOS 7

When cloning a VM, an unpleasant bug occurs related to its configuration file. This file contains a section where `test` is the VM name. When cloning using the command: `virt-clone -o test -n test2 -f /tmp/test2.img`, the name in the path does not change with…

KVM, cloning error in CentOS 7

When cloning a VM, an unpleasant bug occurs related to its configuration file. This file contains a section:

<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-test/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>

where test is the VM name. When cloning using the command:

virt-clone -o test -n test2 -f /tmp/test2.img

the name in the path does not change from test to test2, and if the VM test is not running, the new VM test2 will not start and will display the following error:

Quote
error: Failed to start domain test2 error: internal error: Process exited while connecting to monitor: 2016-02-12T06:02:41.024054Z qemu-kvm: -chardev socket,id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/domain-test/org.qemu.guest_agent.0,server,nowait: Failed to bind socket: No such file or directory 2016-02-12T06:02:41.024121Z qemu-kvm: -chardev socket,id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/domain-test/org.qemu.guest_agent.0,server,nowait: chardev: opening backend "socket" failed

To fix this, you need to manually change the VM name in the path from test to test2, resulting in:

<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-test2/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>

and then execute the command:

systemctl restart libvirtd.service
To avoid restarting, you can edit using virsh edit
Sometimes when cloning, the link remains pointing to the old qcow2 file <source file='/var/lib/libvirt/images/Old.qcow2'/>
I handle this as follows:
cp /var/lib/libvirt/images/Old.qcow2 /var/lib/libvirt/images/New.qcow2
And then fix it in virsh edit New
<source file='/var/lib/libvirt/images/New.qcow2'/>

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.

Categories: KVM