How to 'relink' an hd from one vm to another?

mmenaz

Renowned Member
Jun 25, 2009
835
26
93
Northern east Italy
(pve-manager/1.7/5323, 2.6.32 kernel)
I've a KVM VM, let's say 101, with 2 disks on additional LVM storage. The first disk has the OS, Win2003-64 (50GB), the second is pure data (200GB).
Due to the crashes this VM is facing, and that seem related to the fact that is 64 bit (or so I hope, see http://forum.proxmox.com/threads/5317-Windows-2003-64-Bit-Random-Crashes-APIC-related), I want to create a new VM, let's say 102,
with a 50GB hd, install the Win2003-32, replicate the domain, then shut down 101 and "move" the 200GB from VM 101 to the new 102. Or just the opposite,
remove the 101 50GB and use the new one of 102 VM.
I know I could "dd" from one block device to the other, but it takes time (especially if I have to dd the 200GB one), so I ask if is there a simpler
(and faster/cleaner and secure) way to do so?
In abstract (I'm not a LVM expert) should be a matter of dropping sas-data:vm-101-disk-1 from VM 101, rename the Logical Volume of 102 so it fits the name had sas-data:vm-101-disk-1, and restart.
But when I will destroy VM 101 maybe it will complain that the LV is not there anymore, or there are tags or whatever I'm not aware of that identify the LV to belong to VM 102,
or whatever.
In fact I've tried this:
Created vm 116 with 2 HD, then "deleted" the second one (vm-116-disk-2) without destroying it.
Created vm 117 with 1 HD
Code:
proxmox:~# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  pve    1   3   0 wz--n- 930,50G   4,00G
  sas    1   7   0 wz--n- 836,62G 643,61G

# lvs
  LV            VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
[...]
  vm-116-disk-1 sas  -wi-a-   1,00G                                      
  vm-116-disk-2 sas  -wi-a-   1,00G                                      
  vm-117-disk-1 sas  -wi-a-   1,00G                                      
  
# lvrename sas vm-116-disk-2 vm-117-disk-2
but under the 116 VM now I still see the "deleted HD" that now has the new name, and I can't see it under 117.

Any clue?
Would be nice if Proxmox 2.0 (or 2.1) will let you "play" from web interface with storage <-> VMs (if on the same storage)? Even if file based (so you can't just rename, you have to move from one subdir to another)?
Or maybe the kind of storage supported by Proxmox does not permit a "generalised" approach... in any case, would love to have when applicable.
 
(pve-manager/1.7/5323, 2.6.32 kernel)
In abstract (I'm not a LVM expert) should be a matter of dropping sas-data:vm-101-disk-1 from VM 101, rename the Logical Volume of 102 so it fits the name had sas-data:vm-101-disk-1, and restart.
But when I will destroy VM 101 maybe it will complain that the LV is not there anymore,

You can simple remove the line in the config file.

or there are tags or whatever I'm not aware of that identify the LV to belong to VM 102,
or whatever.

Yes, there is a tag 'pve-vm-<vmid>' - so it is a good idea to change that tag too.

To view the tags you can use:

# lvs --options 'vg_name,lv_name,lv_size,tags'
 
Thanks for pointing me to the right direction.
Just in case if someone else needs to do the same:
Code:
# lvs --options 'vg_name,lv_name,lv_size,tags'
  VG   LV            LSize   LV Tags   
[...]
  sas  vm-116-disk-1   5,00G pve-vm-116
  sas  vm-116-disk-2   6,00G pve-vm-116
  sas  vm-117-disk-1   5,00G pve-vm-117
We want to "relink" (a sort of "mv" for files) disk 2 of vm 116 as disk 2 of vm 117.
Better shutdown vm 116 (for sure), and possibly 117 as well (who knows...).
Let's rename the LV and then change it's tag:
Code:
lvrename sas vm-116-disk-2 vm-117-disk-2
lvchange --deltag pve-vm-116 --addtag pve-vm-117 sas/vm-117-disk-2
Now we have:
Code:
# lvs --options 'vg_name,lv_name,lv_size,tags'
  VG   LV               LSize   LV Tags   
[...]
  sas  vm-116-disk-1      5,00G pve-vm-116
  sas  vm-117-disk-1      5,00G pve-vm-117
  sas  vm-117-disk-2      6,00G pve-vm-117
In web interface we still see 2 HD for 116, and an available storage of 6GB in vm117.
Let's fix it editing
Code:
vim /etc/qemu-server/116.conf
and removing the line related to the storage we have "moved":
Code:
ide1: sas-data:vm-116-disk-2
Now you could edit 117.conf as well and add it, or simply, as I did, go to web interface and add the "unused disk images" from there.
Boot bot VM and you are done.