Migrating a physical Ubuntu 20.04 server into ESXi
In a not-so-recent upgrade to our homelab (my brother’s and mine) i installed an ESXi server meant to replace our old bare-metal one. After the deployment I procrastinated the migration of the old server for a long time, but this weekend it was finally time to do something about it.
During the migration i ran into some problems and i hope this post might help someone in a similar situation.
VMware vCenter Converter Standalone
VMware provides (or rather provided1) a nifty program called vCenter Converter Standalone. This program allows - among other things - to migrate physical servers into VMs without any hassle.
So here are the two problems i encountered:
Network error at 3%
The migration would fail at 3% with the following error:
FAILED: A general system error occurred:
Network error. Host x.x.x.x key can’t be retrieved. (return code 2)
This was a quick fix, my mistake was setting the IP of the new VM to the same one of the physical server, causing an IP conflict (I mistakenly thought not having the VM automatically start after migration was enough to prevent this).
Note that other people with this issue either used a FQDN and had to
switch to using an IP or had to modify the rules in
/etc/hosts.allow. Both these fixes are well documented, so i won’t go into more
GRUB installation issue at 97%
After overcoming the previous issue, the migration failed again at a frustrating 97% with the following error:
FAILED: An error occurred during the conversion: ‘GrubInstaller::InstallGrub: /usr/lib/vmware-converter/installGrub.sh failed with return code: 127, and message: FATAL: kernel too old Error running vmware-updateGrub.sh through chroot into /mnt/p2v-src-root Command:
chroot “/mnt/p2v-src-root” /vmware-updateGrub.sh “GRUB2” “(hd0)” “(hd0,1)” /vmware-device.map “grub2-install” ‘
The following posts were helpful, although they didn’t ultimately work for me (if you’re facing the same problem you should give them a shot though):
- VMware Knowledgebase Article on the issue
- VMware Community Post with a possible alternative solution
After a couple hours of trying to salvage the VM, which had all the data from the old server and just couldn’t boot because GRUB was missing, i gave up and searched for alternatives.
Cloning the server using dd and netcat
The solution to my troubles was cloning the server using dd and netcat. To do this, follow these steps:
- Create a blank VM with enough storage for all files
- Boot into an Ubuntu ISO and open a shell (in the server installer it’s under “Help” in the top right)
Run this command:
nc -l 9001 | dd of=/dev/sda
Run this command on the server you want to clone:
dd if=/dev/sda | nc x.x.x.x 9001
After the entire disk has been transferred you can disconnect the virtual disk and restart the server.
Thanks to reddit user u/Loan-Pickle for documenting this method on a reddit thread about alternatives to the vCenter Converter Standalone (They used it to convert CentOS machines, but it worked for Ubuntu without issue).
After the server is running there are still some cleanup tasks left:
- Removing any changes to the sudoers file made for the vCenter Converter
- Removing any changes to /etc/hosts.allow made for the same reason
- Fixing the adapter name in /etc/netplan/*.yml if it changed (and changing IP to avoid conflicts)