Difference between revisions of "Moving disk image from one KVM machine to another"

From Proxmox VE
Jump to navigation Jump to search
(add a note for steps 2 and 3)
Line 1: Line 1:
1.- Find out what disk image you want to migrate and wich tags it has with the command:
+
== Disk Image to Migrate ==
 +
Find out what disk image you want to migrate and which tags it has with the command:
 
<pre>lvs -o +lv_tags</pre>
 
<pre>lvs -o +lv_tags</pre>
 
This will give you something like:
 
This will give you something like:
Line 19: Line 20:
 
   vm-108-disk-4 pve-pulpo      -wi-a-  50.00G                                      pve-vm-108</pre>
 
   vm-108-disk-4 pve-pulpo      -wi-a-  50.00G                                      pve-vm-108</pre>
  
2.- Once you know exactly wich disks want to migrate and the volume group they are allocated to and their tags, we delete de tags from the disks and then add the tags for the new VM with a command like:
+
== Substitute tags for new VM ==
 +
Once you know exactly which disks want to migrate and the volume group they are allocated to and their tags, we delete the tags from the disks and then add the tags for the new VM with a command like:
 
<pre>lvchange --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
 
<pre>lvchange --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
 
In this example, I am moving vm-108-disk3 and vm-108-disk-4 from VM 108 to VM 101.
 
In this example, I am moving vm-108-disk3 and vm-108-disk-4 from VM 108 to VM 101.
  
3.- Next, we add the tag for VM 101 to both disks:
+
== Add tags for both VMs ==
 +
Now add the tag for VM 101 to both disks:
 
<pre>lvchange --addtag @pve-vm-101 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
 
<pre>lvchange --addtag @pve-vm-101 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
  
Line 29: Line 32:
 
<pre>lvchange --addtag @pve-vm-101 --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
 
<pre>lvchange --addtag @pve-vm-101 --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4</pre>
  
4.- as a convenience, it's better to rename the disk images to reflect the machine they belong to:
+
As a convenience, it's better to rename the disk images to reflect the machine they belong to:
 
<pre>lvrename pve-pulpo/vm-108-disk-3 pve-pulpo/vm-101-disk-1
 
<pre>lvrename pve-pulpo/vm-108-disk-3 pve-pulpo/vm-101-disk-1
 
lvrename pve-pulpo/vm-108-disk-4 pve-pulpo/vm-101-disk-2</pre>
 
lvrename pve-pulpo/vm-108-disk-4 pve-pulpo/vm-101-disk-2</pre>
  
5.- Now, using Proxmox Web Admin, we can delete the disks from the "old VM" and on the new one, we'll have the disks as "unused", so we can add them.
+
== Delete Disk in Old VM ==
 +
Using Proxmox Web Admin, delete the disks from the "old VM" and on the new one the disks are now available as "unused", so we can add them.
  
 
''Credits : From kawarmc in Proxmox Forums''
 
''Credits : From kawarmc in Proxmox Forums''
 +
 
[[Category: HOWTO]]
 
[[Category: HOWTO]]

Revision as of 11:50, 27 October 2015

Disk Image to Migrate

Find out what disk image you want to migrate and which tags it has with the command:

lvs -o +lv_tags

This will give you something like:

:~# lvs -o +lv_tags
  LV            VG             Attr   LSize   Origin Snap%  Move Log Copy%  Convert LV Tags   
  data          pve            -wi-ao  38.12G                                                 
  root          pve            -wi-ao  16.75G                                                 
  swap          pve            -wi-ao   8.38G                                                 
  vm-101-disk-1 pve-compartido -wi-a-  80.00G                                       pve-vm-101
  vm-102-disk-1 pve-compartido -wi-ao  35.00G                                       pve-vm-102
  vm-104-disk-2 pve-compartido -wi-a-  50.00G                                       pve-vm-104
  vm-105-disk-1 pve-compartido -wi-ao  50.00G                                       pve-vm-105
  vm-106-disk-1 pve-compartido -wi-ao  22.00G                                       pve-vm-106
  vm-108-disk-1 pve-compartido -wi-ao  32.00G                                       pve-vm-108
  vm-108-disk-2 pve-compartido -wi-ao 150.00G                                       pve-vm-108
  vm-113-disk-1 pve-compartido -wi-ao   2.00G                                       pve-vm-113
  vm-113-disk-2 pve-compartido -wi-ao   2.00G                                       pve-vm-113
  vm-108-disk-3 pve-pulpo      -wi-a- 300.00G                                       pve-vm-108
  vm-108-disk-4 pve-pulpo      -wi-a-  50.00G                                       pve-vm-108

Substitute tags for new VM

Once you know exactly which disks want to migrate and the volume group they are allocated to and their tags, we delete the tags from the disks and then add the tags for the new VM with a command like:

lvchange --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4

In this example, I am moving vm-108-disk3 and vm-108-disk-4 from VM 108 to VM 101.

Add tags for both VMs

Now add the tag for VM 101 to both disks:

lvchange --addtag @pve-vm-101 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4

Note : you can do steps 2 and 3 in one command :

lvchange --addtag @pve-vm-101 --deltag @pve-vm-108 pve-pulpo/vm-108-disk-3 pve-pulpo/vm-108-disk-4

As a convenience, it's better to rename the disk images to reflect the machine they belong to:

lvrename pve-pulpo/vm-108-disk-3 pve-pulpo/vm-101-disk-1
lvrename pve-pulpo/vm-108-disk-4 pve-pulpo/vm-101-disk-2

Delete Disk in Old VM

Using Proxmox Web Admin, delete the disks from the "old VM" and on the new one the disks are now available as "unused", so we can add them.

Credits : From kawarmc in Proxmox Forums