Migrating systems via network & SSH with minimal downtime
Hi everyone! Today I have a follow-up on a blog post I made earlier this year about 1:1 cloning of a physical or virtual system (SSD upgrade, notebook change or similar)... this time done live over ethernet or wifi!
But... why?
There are two reasons:
-
Time: If it's e.g. a notebook and you cannot have the two disks on the same machine at the same time (which is most of the times imho), you will have to insert the usb on the old machine, boot linux, have another drive to save a temporary dump of the disk (for example 250gb), then shut down the old machine, remove and reinsert the usb on the new one, boot linux and mount the second drive in which you have the dump, mount it and recopy it in the new machine's disk... which is very time consuming indeed!
-
Cost: You can just not have a secondary hard drive, and you also avoid double-copying the drive which is cumbersome and saves your disk from futile writes on it, which is always nice :)
Compatibility
The main dependencies are two USBs for booting a linux distro, both with ethernet or wifi access, and they need to be accessible from both parties to work with.
The clever trick is...
...using dd in conjunction with ssh to copy it in-place over the network!
We need both machines with root user and ssh access over the network (I suggest the Arch Linux ISO available here), so configure them and try ssh-ing each other and make sure the tunnels are properly configured (you probably need to enable PermitRootLogin under sshd_config file), and then just run the following command (adapted with the correct disk paths on each side, obviously!):
dd if=/dev/old_disk_path bs=1M conv=noerror,sync | ssh root@IP_OF_NEW_MACHINE "dd of=/dev/new_disk_path"
... it's simply... ✨ magic ✨!
You will not need additional drives, you will not use write cycles on anything other than the new drive, which you can't even avoid, so :)
Conclusions
I hope it helped someone as it always has helped me in my work and homelab projects!
If you fancy see what I'm working on, have a look at my GitHub or write me an email!