Live Migration of KVM Virtual Machines with virsh migrate

Move running KVM VMs between hosts with zero downtime. Learn how pre-copy live migration works, the prerequisites, shared vs non-shared storage, and tuning.

Published November 27, 2026

Live migration moves a running virtual machine from one physical host to another while it keeps serving traffic. Users notice at most a pause of a few hundred milliseconds. It is how cloud providers patch hosts without rebooting your server, and KVM supports it out of the box with virsh migrate.

The concept

The default algorithm is pre-copy. QEMU first copies all of the guest's memory to the destination while the VM keeps running on the source. Pages the guest modifies during that copy are marked dirty and sent again in the next round. Each round should be smaller than the last. When the remaining dirty memory is small enough to send within the allowed downtime, the source pauses the VM, sends the final pages and device state, and the destination resumes it.

Storage must be reachable from both hosts. With shared storage (NFS, Ceph, iSCSI) only memory and state move. Without shared storage, libvirt can copy disks too (--copy-storage-all), which works but takes much longer. Networking must also match: the destination needs the same bridge or network names, and the VM keeps its MAC and IP.

How pre-copy migration works

Source hostDestination hostprepare: define VM, open portround 1: copy all RAMround 2..n: dirty pagespause, last pages + CPU stateresumed, source cleans up
Pre-copy live migration: memory streams over while the VM keeps running.

Convergence

Round 18 GiBRound 22.4 GiB dirtyRound 3720 MiBRound 4240 MiBStop-and-copy≈60 MiB → pause
Each round sends less as the dirty set shrinks (example numbers).

Prerequisites checklist

Migration fails fast and clearly when something is missing. Check these before trying:

  • Compatible CPUs: use a named CPU model or host-model rather than host-passthrough across different hardware
  • Same libvirt network or bridge names on both hosts
  • Disk paths reachable on both hosts (shared storage), or use --copy-storage-all
  • Hosts can resolve each other by hostname and SSH between them as the managing user
  • Firewall open for libvirt migration ports (49152-49215 by default) or use --tunnelled
  • Clocks in sync (chrony/NTP)

Running a migration

virsh migrate --live --persistent --undefinesource --verbose \
web01 qemu+ssh://kvm02/system
Migration: [ 31 %]
Migration: [ 78 %]
Migration: [100 %]
virsh -c qemu+ssh://kvm02/system list
Id Name State
5 web01 running
A live migration with shared storage.

Practical examples

Migration without shared storage

Copies the whole disk across, then memory.

# pre-create an empty disk of the same size on the destination first
virsh migrate --live --persistent --copy-storage-all --verbose \
  web01 qemu+ssh://kvm02/system

Limit downtime and bandwidth

Set targets before or during migration.

virsh migrate-setmaxdowntime web01 300     # milliseconds
virsh migrate-setspeed web01 1000          # MiB/s
virsh domjobinfo web01                     # watch progress

Help a busy VM converge

Auto-converge throttles the guest CPU; post-copy switches over early.

virsh migrate --live --auto-converge web01 qemu+ssh://kvm02/system
# or: start pre-copy, then switch to post-copy if it is not converging
virsh migrate --live --postcopy web01 qemu+ssh://kvm02/system &
virsh migrate-postcopy web01

Common mistakes

  • Using host-passthrough CPUs on hosts with different CPU generations: the guest may crash on the destination.
  • Forgetting --persistent, so the VM exists on the destination only until it shuts down.
  • Migrating a write-heavy database VM over 1 Gbit links; it may never converge without auto-converge or post-copy.
  • Mismatched bridge names, which make the migration fail at the prepare step.

Key takeaways

  • Pre-copy sends memory in rounds while the VM runs, then pauses briefly for the final copy.
  • Shared storage makes migration fast; --copy-storage-all works without it but is slower.
  • Use compatible CPU models, matching networks and open migration ports.
  • auto-converge and post-copy help VMs that dirty memory faster than the link can send it.

FAQ

How long is the downtime?

Usually tens to a few hundred milliseconds, controlled by migrate-setmaxdowntime and the dirty rate of the guest.

What is post-copy migration?

The VM switches to the destination immediately and missing pages are fetched on demand. It always converges but a network failure mid-migration can lose the VM.

Do TCP connections survive?

Yes. The VM keeps its IP and MAC, and libvirt announces the new location with a gratuitous ARP, so existing connections continue.

More Linux articles