Operations 7 min read

How to Perform Reliable KVM Live and Cold Migration Using NFS Shared Storage

This article explains the prerequisites, step-by-step commands, and best practices for both cold and live migration of KVM virtual machines using NFS shared storage, highlighting common pitfalls such as disk corruption and MAC address conflicts, and provides configuration tips to ensure seamless migration across hosts.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Perform Reliable KVM Live and Cold Migration Using NFS Shared Storage

Introduction

VM1 runs a KVM virtual machine. VM2 mounts VM1's shared disk path via NFS. After performing a hot migration on VM1, VM2 experiences disk corruption. Using a dedicated NFS server for shared storage avoids this issue for both hot and cold migrations.

Prerequisites

All KVM hosts (VM2…VMn) must have the same KVM version installed.

Bridge mode requires a bridge interface (e.g., br0) linked to eth0.

Mount paths must be identical on all hosts.

Cold Migration

Drawbacks:

The VM must be shut down during migration, causing business interruption (or risk MAC address conflicts if left running).

Migration takes longer, especially for large disk images.

Copy the disk image and VM XML to the target host:

# 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.qcow2

Define the VM on the target host: virsh define /tmp/<vm-name>.xml Start the VM:

virsh list --all
virsh start <vm-name>

Test connectivity (images illustrate the results):

VM1 network test
VM1 network test
Duplicate MAC addresses observed
Duplicate MAC addresses observed
Single MAC after shutting down VM on host1
Single MAC after shutting down VM on host1

Parameter explanation:

arping VIP -s <source IP> -c 1   # Check if two MAC addresses are returned

Hot Migration

Install NFS on VM3 (reference: https://www.cnblogs.com/rtnb/p/15584847.html).

Check NFS mounts on VM1 and VM2:

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   56G  5.7G   50G  11% /
/dev/sda1               1014M  183M  832M  19% /boot
192.168.64.12:/opt/kvm    36G  5.1G   31G  15% /opt/kvm
# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   36G   24G   12G   69% /
/dev/sda1               1014M  183M  832M   19% /boot
192.168.64.12:/opt/kvm    36G  5.1G   31G   15% /opt/kvm

Execute live migration (no network interruption):

# virsh migrate --live --verbose domain qemu+ssh://192.168.64.11/system --unsafe
virsh migrate --live --verbose test2-nat-network-2 qemu+ssh://192.168.64.11/system --unsafe   # migrate
virsh migrate --live --verbose test2-nat-network-2 qemu+ssh://192.168.64.14/system --unsafe   # rollback
virsh migrate --live --persistent --undefinesource --verbose myvm qemu+ssh://[email protected]/system --unsafe

Parameter explanation:

--live : perform online migration.

--verbose : show detailed progress.

qemu+ssh://IP/system : target host for migration via SSH.

--unsafe : allow migration without shared storage (useful for testing).

--undefinesource : remove VM definition from source after migration, keep disk files.

--persistent : keep VM definition on target after reboot.

Note: Disk paths in both XML files must point to the shared storage directory.

Configure host name resolution:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 kafka-1
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.64.14 kafka-1
192.168.64.11 kafka-2
192.168.64.12 kafka-3

Additional reference link:

https://www.cnblogs.com/rtnb/p/18331044

Diagram of migration setup
Diagram of migration setup
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

VirtualizationKVMLive MigrationNFS
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.