VM Migration
VM migration moves a running or stopped virtual machine from one physical host to another. Offline migration copies the VM's disk image and configuration to a new host while the VM is stopped. Live migration moves the VM while it is running by copying memory pages to the destination host, then doing a final cutover when the VM state has been fully transferred — the VM experiences only a very brief pause (milliseconds to seconds) depending on memory size and network speed.
Migration types
Migration comparison:
Offline migration:
Stop VM → copy disk image → define VM on destination → start
Downtime: minutes (proportional to disk size)
No shared storage required
Suitable for: planned maintenance, data center moves
Live migration:
Copy memory to destination while VM runs → final sync → cutover
Downtime: milliseconds
Requires: shared storage (NFS/Ceph) OR disk copy can be combined
Suitable for: host maintenance without service interruptionOffline migration
# Step 1: Shut down the VM
virsh shutdown ubuntu-test
# Wait for shutdown, then verify:
virsh list --all # Should show 'shut off'
# Step 2: Export VM configuration
virsh dumpxml ubuntu-test > /tmp/ubuntu-test.xml
# Step 3: Copy disk image to destination host
scp /var/lib/libvirt/images/ubuntu-test.qcow2 desthost:/var/lib/libvirt/images/ubuntu-test.qcow2
# Step 4: Copy and import VM definition on destination
scp /tmp/ubuntu-test.xml desthost:/tmp/ubuntu-test.xml
ssh desthost 'virsh define /tmp/ubuntu-test.xml && virsh start ubuntu-test'
# Step 5: Verify VM started correctly on destination
ssh desthost 'virsh list'
Live migration
# Prerequisites for live migration:
# - Both hosts must have the same CPU architecture
# - Hosts must have shared storage (NFS, Ceph) OR use --copy-storage-all
# - SSH key-based authentication between hosts (libvirt uses SSH)
# - Both hosts running the same libvirt/QEMU version
# Live migrate to destination host (shared storage):
virsh migrate --live ubuntu-test qemu+ssh://desthost/system
# Live migrate with disk copy (no shared storage):
virsh migrate --live --copy-storage-all ubuntu-test qemu+ssh://desthost/system
# Watch migration progress:
virsh domjobinfo ubuntu-test
virsh domjobinfo output during migration
Job type: Unbounded
Operation: Outgoing Migration
Time elapsed: 3250 ms
Data processed: 512 MiB
Data remaining: 128 MiB
Memory total: 2048 MiB
Conclusion
For planned maintenance on a KVM host, live migration is the right tool — it moves VMs to other hosts without service interruption while you patch the host kernel or replace hardware. Offline migration is simpler and works without shared storage, but requires a maintenance window. When planning live migration, ensure destination host has sufficient RAM and CPU capacity for the migrating VMs before initiating. Use virsh domjobinfo to monitor progress and estimate completion time.
FAQ
Is VM Migration important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support