How to migrate instances between different machines

This content was contributed by @lars18 on GitHub: [GUIDE] How to migrate instances between different machines · Issue #3755 · canonical/multipass · GitHub


Guide to migrating an instance from one Linux host to another Windows host

  • The Linux machine is Ubuntu with a recent multipass package installed with snap. And the Windows machine is Windows 11 Pro with Hyper-V enabled and the same multipass version.
  • Copy the vdisk of the donor instance from the Linux machine to one directory of the Windows machine. Location of source: /var/snap/multipass/common/data/multipassd/vault/instances/<instance_name>/*.qcow2 (or “*.img” depending on the hypervisor used).
  • Convert the vdisk to VHDX format. You need to use qemu-img.exe (native win32 tool) or qemu-img (from WSL); or you can do the conversion in the original Linux machine: qemu-img convert <donor>.qcow2 -O vhdx -o subformat=<donor>.vhdx.
  • Create a new instance in the Windows machine with similar (but not necessary identical) configuration, but with the same name: multipass launch –n <instance_name> … .
  • Stop the new created instance and search for the disk. Common location: C:\ProgramData\Multipass\data\vault\instances\<instance_name>\*.vhdx (Warning: to complete this action and from this point you need administrator privileges).
  • Using WSL (or moving the *.vhdx disk to the Linux machine) mount the two root filesystems. For example with: sudo qemu-nbd --connect=/dev/nbd0 <donor>.vhdx; sudo qemu-nbd --connect=/dev/nbd1 <target>.vhdx; sudo mount /dev/nbd0p1 /media/donor; sudo mount /dev/nbd1p1 /media/target;
  • Now copy from “target” to “donor” the ssh config data of the instance used by the multipass daemon. The files are: /etc/ssh/ssh_host* (remove first all of them in donor, perhaps more formats exists in the donor filesystem) and the /home/ubuntu/.ssh/authorized_keys.
  • Umount all filesystems and move the <donor>.vhdx file to the directory where <target>.vhdx file exists.
  • Copy the permissions with PowerShell Get-Acl <target>.vhdx | Set-Acl <donor>.vhdx and delete the .vhdx file.
  • Rename the <donor>.vhdx file with the original filename of the target vdisk.
  • Start the instance and check it: multipass shell <instance_name>.

This works because the trick is to replace all the ssh data of the original instance with the data of the temporary instance. You don’t need to change anything else to migrate an instance to another machine. Just copy/convert the instance disk image. I have completed multiple migrations without any trouble using this technique.