Skip to content

Instantly share code, notes, and snippets.

@kkumar-fk
Created November 29, 2021 13:42
Show Gist options
  • Save kkumar-fk/7d3a78864097fa76f79fe9f3ea0cfbd1 to your computer and use it in GitHub Desktop.
Save kkumar-fk/7d3a78864097fa76f79fe9f3ea0cfbd1 to your computer and use it in GitHub Desktop.
Migration script to run on the source hypervisor
#!/bin/bash
DOMAIN=vm-01
PF=ens6np0
VF=ens6v1 # VF attached to the bridge.
VF_NUM=1
TAP_IF=vmtap01 # virtio-net interface in the VM.
VF_XML=vf.xml
MAC=52:54:00:00:12:53
ZERO_MAC=00:00:00:00:00:00
# Set the virtio-net interface up.
virsh domif-setlink $DOMAIN $TAP_IF up
# Remove the VF that was passthrough'd to the VM.
virsh detach-device --live --config $DOMAIN $VF_XML
ip link set $PF vf $VF_NUM mac $ZERO_MAC
# Add FDB entry for traffic to continue going to the VM via
# the VF -> br0 -> vnet interface path.
bridge fdb add $MAC dev $VF
bridge fdb add $MAC dev $TAP_IF master
# Migrate the VM
virsh migrate --live --persistent $DOMAIN qemu+ssh://$REMOTE_HOST/system
# Clean up FDB entries after migration completes.
bridge fdb del $MAC dev $VF
bridge fdb del $MAC dev $TAP_IF master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment