Importing server using initramfs shell
When all you have is a remote KVM (this, not this), management console doesn’t have image import/export feature, and you need to migrate a VPS.
Fortunately, during usual Linux boot process, there is a stage when it is not dependent on the OS partition because we’re running from RAM - logically enough it is called initramfs. Let’s use it to import the image!
On donor:
open port on firewall, ideally only to acceptor’s IP.
-
freeze all filesystems mounted on local disk:
-
mount / -o remount,ro- do for each partition - or
echo u > /proc/sysrq-trigger
-
-
start fake HTTP server:
(printf 'HTTP/1.0 200 OK\r\n\r\n'; cat /dev/sda) | pv | nc -l -p 1234
On acceptor:
in
/etc/default/grubchangeGRUB_TIMEOUTto10update-grubnote ip address, netmask, gateway
reboot
open KVM console
enter bootloader, edit options, add
break=premountto command line and bootmanually add ip address, netmask, gateway (
ip…)but initramfs in Ubuntu doesn’t have netcat, so…
wget -O /dev/sda http://DONOR:1234reboot
should work
Security considerations:
if doing it between VPSes in the same server room and everything is in well-protected network, then nothing to worry about, as VPS provider has access to all the content of the disk anyway.
Otherwise: verify sha512sum before reboot, revoke & regenerate keypairs, or don’t use this method at all if disk content is confidential