Move/clone your VPS from one provider to another

How to move your VPS to a new provider

Posted by Luke on Mon, 18 Nov 2019 10:01:00

Recently I decided to change my VPS provider. I’ve chosen Contabo instead of OVH. Since I had Debian 10 installed in OVH I also ordered Debian in Contabo. After they established my new machine I checked for differences in partition layout and found that Contabo VPS has two partions and OVH has just one. It looks like this:

contabo# df -h

Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 16M 380M 4% /run
/dev/sda2 294G 6.6G 272G 3% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 922M 47M 812M 6% /boot
ovh# df -h

Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 386M 39M 347M 11% /run
/dev/sda1 40G 7.3G 31G 20% /
tmpfs 1.9G 396K 1.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup

The difference is that /boot partition on Contabo VPS.

I’m lazy 🙂 So I was looking for a way to just “clone” my old VPS from OVH to Contabo and I came up with the following solution.

First backup entire filesystem on your old machine excluding some directories especially /boot directory. We will leave that partition mounted on /boot on Contabo machine untouched. So on old VPS (if you don’t have swapfile you don’t have to exclude it):

# cd /

# tar ––exclude=’./swapfile’ ––exclude=’./proc’ ––exclude=’./sys’ ––exclude=’./dev’ ––exclude=’./run’ ––exclude=’./boot’ -zcvf os.tgz .

Transfer the file with your old OS (os.tgz in my case) to your new VPS (being logged in on your new VPS):

# cd /

# sftp user@oldmachine

# cd /  (make sure you have permissions to read the os.tgz file)

# get os.tgz

Make a backup of the OS on new VPS similar way:

# cd /

# tar ––exclude=’./sys’ ––exclude’./dev’ ––exclude’./proc’ ––exclude=’./run’ ––exclude=’./boot’ ––exclude=’./os.tgz -zcvf os_orig.tgz .

I also copied two additonal files to have them around:

# cp /etc/fstab /

# cp /etc/network/interfaces /

After that restart your new VPS in rescue mode and mount root partition somewhere:

# mkdir /mnt/root

# mount /dev/sda2 /mnt/root (it was /dev/sda2 in my case)

# cd /mnt/root

Now remove directories that will be overwritten by those from the backup (in case you are moving to some different provider than Contabo or the OS is not Debian 10 then this list might not be precise):

# cd /mnt/root

remove below listed directories

lrwxrwxrwx 1 root root 7 Nov 29 17:58 bin -> usr/bin
drwxr-xr-x 74 root root 4096 Nov 29 13:49 etc
drwxr-xr-x 3 root root 4096 Nov 29 11:32 home
lrwxrwxrwx 1 root root 7 Nov 29 17:58 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Nov 29 17:58 lib32 -> usr/lib32
lrwxrwxrwx 1 root root 9 Nov 29 17:58 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 Nov 29 17:58 libx32 -> usr/libx32
drwxr-xr-x 2 root root 4096 Nov 29 10:15 media
drwxr-xr-x 2 root root 4096 Nov 29 10:15 mnt
drwxr-xr-x 2 root root 4096 Nov 29 10:15 opt
drwx—— 3 root root 4096 Nov 29 11:44 root
lrwxrwxrwx 1 root root 8 Nov 29 17:58 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Nov 29 10:15 srv
drwxrwxrwt 8 root root 4096 Nov 29 13:49 tmp
drwxr-xr-x 13 root root 4096 Nov 29 10:15 usr
drwxr-xr-x 11 root root 4096 Nov 29 10:15 var

Unpack your old OS from backup (note the p switch which is there to preserve permissions):

# cd /mnt/root

# tar xvzfp os.tgz

Now the two last steps. Restore fstab and interfaces files you have copied earlier:

# cd /mnt/root

# cp fstab etc/

# cp interfaces etc/network/

Now reboot. If everything went well than all you have to do is reconfigure your services like apache, openvpn etc.

Also check what is in your /etc/resolv.conf – that too might have to be taken care of.

Good luck 😛