Move VM and Snapshots to a new LVM volume

swinster

New Member
Jan 17, 2024
2
1
1
Hi,

I must move a VM with all its snapshots from one LVM volume to another. What is the best way to do this?

I realise that removing the snapshots is ideal - this is impossible for my scenario.

Cheers
 
  • Like
Reactions: dragonlinux
Hi,
unfortunately, it's not possible at the moment via Proxmox VE API/CLI. Feel free to open a feature request on our bugtracker (after checking if one exists). You'd need to do it manually.

Proceed at your own risk!

You'd need to, while the VM is down, copy the snap_vm-XYZ-disk-N_NAME and vm-XYZ-state-NAME volumes and the actual volumes (state volumes are only present for snapshots with RAM) to the new storage and adapt the VM configuration file accordingly (reference to disks, vmstate entries).

To be safe, I'd change the ID to something else while copying, and also copy the configuration file (adapting the ID everywhere), so you can work with the copy and only remove the original volumes after verifying that everything works as expected. You can even take a new snapshot, so you can test rollback to others without losing current state.
 
  • Like
Reactions: carles89 and Moayad
Maybe you have a vm in pve default installation with lvm, see lsblk, vgs, vgdisplay, lvs, lvdispaly,
So you have eg the vm disk /dev/pve/vm-139-disk-0.raw in default volume group (vg) pve.
You made on new disk(s) a new vg pve2 (as you don't wanted to expand pve and move from one lvm to another).
Then "dd if=/dev/pve/vm-139-disk-0.raw of=/dev/pve2/vm-1139-disk-0.raw bs=1024k" would do the job while even switch the vmid.
"cp /etc/pve/qemu-server/139.conf /etc/pve/qemu-server/1139.conf" and edit 1139.conf file accordingly to your other lvm storage which you defined in datacenter (as you don't expanded the vg pve named lvm-local).
 
waltar, big big thanks for your help. My situations is more or less as you say. Default installation with pve volume group and "data" thinpool in it and added local-lvm storage (LVM-Thin type). So I added aother disk, created another volume group pve2, another "data2" thinpool and added another storage. VM's disk in question named as "vm-154-disk-0 -> ../dm-111" if I look in /dev/pve. So now the dd command - will it copy everything - disks and snapshots? Or do I need some additional command to copy snapshots? Do I need to use .raw in this command?
 
Last edited:
When you have there some more snapshot files which have an additional ending you need to cp them by dd too. ".raw" is the format but you are right as if the files just end without ".raw" don't append it (We just use filestorage and so we don't have this kind of block usage problem at all, just take "cp" then).
 
When you have there some more snapshot files which have an additional ending you need to cp them by dd too. ".raw" is the format but you are right as if the files just end without ".raw" don't append it (We just use filestorage and so we don't have this kind of block usage problem at all, just take "cp" then).
Waltar, will this one command will copy main disk and related snapshots. I'm asking because my test VM has only one entry in /dev/pve directory even it has snapshots.
 
When there is just one with "*154*" then yes. When you are using the pve webui for snapshots (as most do but we normally not) then you should see your snapshots for vm 1154 also.
 
waltar, are you sure that dd command if enough? Because when I used this command, copied config, edited everything, VM is not able to start and complains that logical volume is not found. Maybe I need some additional command to fix this (before or after dd)? Even dir output shows that copied thing is different from others:

Code:
lrwxrwxrwx  1 root root           9 Dec 27 20:09 vm-117-disk-5 -> ../dm-109
lrwxrwxrwx  1 root root           8 Dec 28 01:17 vm-1180-cloudinit -> ../dm-98
-rw-r--r--  1 root root 10737418240 Dec 28 01:08 vm-1180-disk-0
lrwxrwxrwx  1 root root           9 Dec 27 20:10 vm-123-disk-0 -> ../dm-110
lrwxrwxrwx  1 root root           8 Dec 27 20:11 vm-123-disk-1 -> ../dm-93
 
Reboot and if not useable then first create the vm empty new and then again exchange the empty vm file with the dd command again.
Using block storage is like working with tex instead of ms word or adobe indesign etc, still it's possible but it's still not worth the effort.
Each can decide itself who wants to go the rocky road or a comfortable highway.
 
  • Like
Reactions: Kingneutron
Its not about comfortable way at all. VMs has snapshots, I can't delete them right now, they are needed. So I have no other options left. Its strange that Proxmox still does not support such thing. In Vmware's world its easy as 1 2 3... Reboot is not an option too. I guess we are missing something here, for example copilot is telling me that I need to create logical volume at first prior using dd command. And it works, I'm able to start VM but I'm missing something with tnapshots, because I stil can't rollback to older snapshot and end up with an error:

Logical volume "vm-1180-disk-0" successfully removed.
TASK ERROR: lvm rollback 'pvesataent/snap_vm-1180-disk-0_snap1' error: Snapshot origin LV snap_vm-1180-disk-0_snap1 not found in Volume group pvesataent.
 
Ok, going slowly ahead. So I've found that I need to create logical volume with the same size at first and use dd only then. So this is good for main disk. But I can't find how to copy snapshot in the similar way as it is not seen at the source. For example my snap info:
snap_vm-180-disk-0_snap1 pve2 Vri---tz-k 10.00g data2 vm-180-disk-0 /dev/pve2/snap_vm-180-disk-0_snap1
but if I look at /dev/pve2 byt issuing ls, its not seen there. So need to find the way how to copy this snapshot now...
 
Hi,
Ok, going slowly ahead. So I've found that I need to create logical volume with the same size at first and use dd only then. So this is good for main disk. But I can't find how to copy snapshot in the similar way as it is not seen at the source. For example my snap info:
snap_vm-180-disk-0_snap1 pve2 Vri---tz-k 10.00g data2 vm-180-disk-0 /dev/pve2/snap_vm-180-disk-0_snap1
but if I look at /dev/pve2 byt issuing ls, its not seen there. So need to find the way how to copy this snapshot now...
you might need to activate the logical volume first, with lvchange -ay -K <logical volume>.
 
  • Like
Reactions: waltar