Operations 6 min read

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.

Raymond Ops
Raymond Ops
Raymond Ops
How to Perform Safe Cold and Live Migration of KVM VMs Using NFS Shared Storage

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

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

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

Test connectivity:

Test access
Test access

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 --unsafe

Parameter 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.

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.

linuxVirtualizationKVMLive MigrationNFSVM migrationcold migration
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

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.