/ proxmox

Migrating Proxmox LVM-Thin Volumes to another Proxmox Host

Introduction

In an earlier post, i've discribed how to migrate VMWare ESXi Virtual Machines (or mostly their disks) to a new Proxmox KVM machine. This time i had to move a Proxmox VM to another Proxmox host. Both hosts using LVM-Thin Logical Volumes to store guest data instead of disk files like VirtualBox.

This small guide shows you how you can accomplish moving rather large logical volumes between hosts without storing any intermediate files (to save precious disk space).

Preparations

The method i've used is basically simply using dd to read and also write the actual data on both sides. For the network communication i've used ssh. This is rather simple to use with ssh keys and all the data copied over the network is secure.
You can even use this method to move data over the Internet safely.

We first have to add the ssh's public key from the source host - let's call him shost - to the authorized_keys file from the root user of the destination host, called dhost.

# Get the shost's ssh public key
~$ cat /root/.ssh/id_rsa.pub

Then insert it's contents to the destination hosts authorized_keys file

# Paste the shost's ssh public key in a newline here
~$ vim /root/.ssh/authorized_keys

After saving, try to establish a connection from the source to the destination host, and add the dhost's SSH Host key once.

# I expect that you're already root on shost, so there is no need to add a login user to the ssh command. The logged-in user is used by default here
~$ ssh dhost

The authenticity of host 'dhost (192.168.1.3)' can't be established.
ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yey
Warning: Permanently added 'dhost,192.168.1.3' (ECDSA) to the list of known hosts.

Now that you can login from shost to dhost without a password, we can continue with the actual migration

Data Migration over SSH

As i said, i've used dd to read and write the data. I also used pv, so i have a nice progress bar as well.

First check the used Logical Volume on shost of the machine you want to use. For that, go to the machine, then into the hardware tab. The logical volume path should read like local-lvm:vm-100-disk-1. We need the vm-100-disk-1 part and will call it <shost lv>. Also check the actual disk size. In our example it's 100 Gigabytes.

Now create the same machine on dhost with the same disk size like on shost. After creating it, also read the logical volume name here. We will call this one <dhost lv>.

Now let us copy the stuff over. Make sure the Virtual Machine is actually shutdown.

~$ dd if=/dev/pve/<shost lv> conv=sparse | pv -s 100G | ssh dhost dd of=/dev/pve/<dhost lv>

Execute this command and dd will read off of the source hosts logical volume but will seak and ignore NUL blocks (zeroes) to save disk space, shift it through pv with a pre-defined size, so it can calculate the progress you see while copying and then pipe it through ssh to the destination hosts dd which writes the data back to the new logical volume bit by bit.

Start the machine on the new host

After successfully copying the data, and after you made sure that you recreated the VM correctly on the new host, you can simply start it there and see it booting. That's it! If it wasn't successful you can simply boot the old VM at any time.

Disclaimer

I don't take any responsibilities for any damage this may cause.