How to Perform Safe Cold and Live Migration of KVM VMs Using NFS Shared Storage
This guide explains the prerequisites, step‑by‑step procedures, and command‑line options for both cold and live migration of KVM virtual machines using NFS‑based shared storage, highlighting common pitfalls such as service interruption and MAC address conflicts.
Introduction
vm1 runs a KVM virtual machine; vm2 mounts the VM disk via NFS from vm1. After a hot migration on vm1, vm2 shows disk corruption. Using a dedicated NFS storage server avoids the issue.
Prerequisites
All KVM hosts (vm2…vmn) must have the same KVM version installed.
Bridge networking: create a bridge interface and attach eth0 to br0.
Mount paths must be identical on all hosts.
Cold Migration
Disadvantages:
VM must be shut down, causing service interruption (or risk MAC address conflict).
Migration takes longer, especially for large disk images.
Steps:
# scp /etc/libvirt/qemu/qianyi-bridge-vm.xml kafka-2:/etc/libvirt/qemu/qianyi-bridge-vm.xml
# scp /opt/kvm/vm/qianyi-bridge-vm.qcow2 kafka-2:/opt/kvm/vm/qianyi-bridge-vm.qcow2Define the VM on the destination host: virsh define /tmp/<vm-name>.xml Start the VM:
virsh list --all
virsh start <vm-name>Test connectivity:
Live Migration
Install NFS on vm3 and ensure all hosts mount the same shared directory.
# virsh migrate --live --verbose domain qemu+ssh://192.168.64.11/system --unsafe
# virsh migrate --live --persistent --undefinesource --verbose myvm qemu+ssh://[email protected]/system --unsafeParameter explanations: --live: perform live migration. --verbose: show detailed progress. qemu+ssh://.../system: target host connection via SSH. --unsafe: allow migration without shared storage. --undefinesource: remove VM definition from source after migration. --persistent: keep VM definition on target after host reboot.
Note: Disk paths in both XML files must point to the shared storage directory.
Configure /etc/hosts for name resolution on all hosts.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
