Moving a KVM virtual guest using cli
The following is the way to perform cold KVM migration. A cold migration involves shutting down the guest server during the migration. Generally speaking, to move KVM VM, you need to copy all the VM data from the source host to the destination host and then define the new VM. If you are using a shared storage – such as NFS or iSCSI you only need to confirm that the destination host system is connected to the same storage
You should note that the virtual environment on the destination host must be the same as that on the source host.
1. Since it is cold migration, the first step is to power off the target VM. You can list all the VMs on the source host to find the VM you would like to migrate.
virsh list --all
2. Remember the name of the target guest machine and you need shut down it.
virsh shutdown guest_name
3. You can also recheck its state to make sure it has been powered off:
virsh domstate guest_name
4. The next step is exporting the configuration of guest machine:
virsh dumpxml guest_name > /root/guest_name.xml
5. Copy the configuration file to the destination host:
scp /root/guest_name.xml destination_host_ip://etc/libvirt/qemu
6. Input the password of the destination host to start transferring.
Get the directory of the guest machine’s virtual disk:
virsh domblklist guest_name
7. Copy the hard disk to destination host in the same way.
The new VM needs to be defined on the destination host:
virsh define guest_name.xml
8. The you can start the VM to test whether it works:
virsh start guest_name
If it reports the error that the CPU is not compatible with host CPU, then the CPU of the VM needs to be modified.
virsh edit guest_name
Replace CPU configuration with <cpu mode=’host-passthrough’ check=’none’/>