Live Migration
PiVirt supports live migration of running virtual machines between cluster nodes with sub-second cutover, enabling non-disruptive host maintenance, dynamic resource rebalancing, and high availability.
Migration Types
Section titled “Migration Types”Live Migration (Shared Storage)
Section titled “Live Migration (Shared Storage)”flowchart TB
subgraph Source["Source Node"]
VM_SRC["VM (running)<br/>- memory state"]
end
subgraph Target["Target Node"]
VM_TGT["VM (running)<br/>- memory state"]
end
STORAGE[("Shared Storage<br/>(iSCSI / OCFS2)")]
VM_SRC -->|"migrate memory"| VM_TGT
VM_SRC --- STORAGE
VM_TGT --- STORAGE
Live Migration (Shared-Nothing)
Section titled “Live Migration (Shared-Nothing)”flowchart LR
subgraph Source["Source Node"]
VM_SRC["VM (running)<br/>- memory state<br/>- disk images"]
end
subgraph Target["Target Node"]
VM_TGT["VM (running)<br/>- memory state<br/>- disk images"]
end
VM_SRC -->|"migrate memory + disk copy"| VM_TGT
Prerequisites
Section titled “Prerequisites”Network Requirements
Section titled “Network Requirements”# Verify network connectivityping target-node
# Check migration port rangenc -zv target-node 49152-49215
# Check bandwidthiperf3 -c target-nodeCPU Compatibility
Section titled “CPU Compatibility”# Check CPU model on sourcepvcli node get source-node -o json | jq '.status.cpu'
# Check CPU model on targetpvcli node get target-node -o json | jq '.status.cpu'
# Verify compatibility# Both nodes must have compatible CPU models# Or use "host-model" instead of "host-passthrough"Storage Accessibility
Section titled “Storage Accessibility”# For shared storage - verify mountssh target-node "mount | grep shared-storage"
# For NBD - check NBD serverssh target-node "nbd-client -l source-node"Performing Migration
Section titled “Performing Migration”Live Migration
Section titled “Live Migration”# Basic live migrationpvcli vm migrate web-01 --target node-02 --live
# With bandwidth limitpvcli vm migrate web-01 \ --target node-02 \ --live \ --bandwidth-limit 1000 # Mbps
# With downtime limitpvcli vm migrate web-01 \ --target node-02 \ --live \ --downtime-limit 500 # ms
# With compressionpvcli vm migrate web-01 \ --target node-02 \ --live \ --compressCold Migration
Section titled “Cold Migration”# Stop VM, migrate, startpvcli vm stop web-01pvcli vm migrate web-01 --target node-02pvcli vm start web-01Migration with Disk Copy
Section titled “Migration with Disk Copy”# Migrate VM with disk copy (shared-nothing)pvcli vm migrate web-01 \ --target node-02 \ --copy-disks \ --bandwidth-limit 500 # MbpsMigration Configuration
Section titled “Migration Configuration”pivirtd Configuration
Section titled “pivirtd Configuration”migration: enabled: true transport: "tcp" # tcp, unix, rdma bind_address: "0.0.0.0" port_range: "49152-49215" bandwidth_limit_mbps: 0 # 0 = unlimited downtime_limit_ms: 500 compression: true compression_threads: 4Network Configuration
Section titled “Network Configuration”# Firewall rules for migration# Allow migration portsiptables -A INPUT -p tcp --dport 49152:49215 -j ACCEPT
# Or with nftablesnft add rule inet filter input tcp dport 49152-49215 acceptMonitoring Migration
Section titled “Monitoring Migration”Migration Status
Section titled “Migration Status”# Check migration statuspvcli vm get web-01 -o json | jq '.status.migration'
# Output:# {# "status": "migrating",# "target_node": "node-02",# "progress_percent": 45,# "remaining_time_seconds": 120,# "downtime_ms": 0# }Migration Metrics
Section titled “Migration Metrics”# View migration metricscurl http://localhost:9002/metrics | grep migration
# Key metrics:# pivirtd_migration_count{status="completed"} 42# pivirtd_migration_duration_seconds{vm="web-01"} 123.45# pivirtd_migration_downtime_ms{vm="web-01"} 250Migration Logs
Section titled “Migration Logs”# View migration logsjournalctl -u pivirtd -f | grep -i migrat
# Example log:# {"level":"info","msg":"Starting live migration","vm":"web-01","target":"node-02"}# {"level":"info","msg":"Migration progress","vm":"web-01","progress":45}# {"level":"info","msg":"Migration completed","vm":"web-01","downtime_ms":250}Troubleshooting
Section titled “Troubleshooting”Migration Fails
Section titled “Migration Fails”# Check network connectivitync -zv target-node 49152-49215
# Check disk accessibility# For shared storage - verify mount# For NBD - check NBD server
# View migration logsjournalctl -u pivirtd -f | grep -i migrat
# Check CPU compatibilitypvcli node get source-node -o json | jq '.status.cpu'pvcli node get target-node -o json | jq '.status.cpu'High Downtime
Section titled “High Downtime”# Increase bandwidth limitpvcli vm migrate web-01 \ --target node-02 \ --live \ --bandwidth-limit 10000 # 10 Gbps
# Enable compressionpvcli vm migrate web-01 \ --target node-02 \ --live \ --compress
# Reduce dirty page rate# Pause non-critical workloads during migrationMigration Stuck
Section titled “Migration Stuck”# Cancel migrationpvcli vm migrate cancel web-01
# Check migration statuspvcli vm get web-01 -o json | jq '.status.migration'
# View detailed logsjournalctl -u pivirtd -f | grep -i migratBest Practices
Section titled “Best Practices”1. Pre-Migration Checks
Section titled “1. Pre-Migration Checks”# Verify network connectivityping target-nodenc -zv target-node 49152-49215
# Check CPU compatibilitypvcli node get source-node -o json | jq '.status.cpu'pvcli node get target-node -o json | jq '.status.cpu'
# Check storage accessibilityssh target-node "mount | grep shared-storage"2. Bandwidth Management
Section titled “2. Bandwidth Management”# Set appropriate bandwidth limitpvcli vm migrate web-01 \ --target node-02 \ --live \ --bandwidth-limit 1000 # Don't saturate network3. Downtime Optimization
Section titled “3. Downtime Optimization”# Set downtime limitpvcli vm migrate web-01 \ --target node-02 \ --live \ --downtime-limit 500 # 500ms max downtime4. Compression
Section titled “4. Compression”# Enable compression for slow networkspvcli vm migrate web-01 \ --target node-02 \ --live \ --compress