Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUIDE] How to migrate instances between different machines #3755

Closed
lars18th opened this issue Oct 24, 2024 · 8 comments
Closed

[GUIDE] How to migrate instances between different machines #3755

lars18th opened this issue Oct 24, 2024 · 8 comments
Labels
enhancement needs triage Issue needs to be triaged

Comments

@lars18th
Copy link

Hi,

I want to share this mini-guide. The idea is to provide this technical information to other users. And at the same time propose a new functionality of a ‘migrate’ command. This functionality is already requested in other issues.

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.

I hope the developers will want to add support for this. Although at the moment we already have a manual process to achieve this.

Regards.

@lars18th lars18th added enhancement needs triage Issue needs to be triaged labels Oct 24, 2024
@ricab
Copy link
Collaborator

ricab commented Oct 24, 2024

HI @lars18th, thanks for sharing. The best place for this sort of info is our discourse. Would you mind posting there? Thanks.

@georgeliao
Copy link
Contributor

georgeliao commented Oct 24, 2024

Hi @lars18th
About the migrate instance feature, since we already have a feature request on this. I am gotta close this one.

@georgeliao georgeliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
@giuliazanchi
Copy link
Contributor

Hi @lars18th , if you want you can create a new Discourse topic in our Community Knowledge category. Or, I can create if for you if you like. Thanks for your input!

@lars18th
Copy link
Author

lars18th commented Nov 4, 2024

Or, I can create if for you if you like. Thanks for your input!

Dear @giuliazanchi ,
I recommend that you do so. 👍

@lars18th
Copy link
Author

lars18th commented Nov 8, 2024

Or, I can create if for you if you like. Thanks for your input!

Dear @giuliazanchi , I recommend that you do so. 👍

Hi @giuliazanchi ,
Do you do it?

@giuliazanchi
Copy link
Contributor

Hi @lars18th , sorry for the belated reply. I had this in my backlog, I've just posted it to our Community Knowledge section: https://discourse.ubuntu.com/t/how-to-migrate-instances-between-different-machines/50569
Thanks again for your contribution!

P.s. If you comment on that post, or let me know your username on Discourse, I can tag you properly :)

@melutovich
Copy link

@lars18th @giuliazanchi I'm just wondering since the .vhdx is edited, perhaps a comment that one should ensure that this is a copy of the original disk that is being edited until one has verified the next instance is functional and one does not need the original instance as well.

In "Copy the permissions with PowerShell Get-Acl .vhdx | Set-Acl .vhdx and delete the .vhdx file." the 'delete the .vhdx file' is specially for deleting the .vhdx

@lars18th
Copy link
Author

Hi @melutovich ,

Thank you for pointing this. At start my post was only to describe that the migration process could be done. And describe more or less the process. With the idea of pointing the key aspects: 1) the configuration, 2) the ssh key to access to the instance.

My suggestion now is to write a PowerShell script that could complete the process. The problem is that multiple use cases could exist. For example: Linux QEmu --> Windows Hyper-V. And this is only one case of the multiple sources and targets.

But if someone will develop such script, then perhaps the main developers will want to incorporate the process internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants