Possible to create quick copy of KVM VM by using snapshot?

alexc

Renowned Member
Apr 13, 2015
125
4
83
Recently I faced situation when I needed to create exact copy of running VM for maybe 5 minutes to test some setting in it. The common way was to create the backup via snapshot, then create new machine and "restore" this new VM from recently created backup. It is quite easy to understand but it takes time and not needed for the task as I can see this.

But if it is possible to create disks snapshots (using LVM or qcow2 features) and use these snapshots as disks for new VM? This way I'll be able to boot the new VM, check my settings in it and then off the machine and delete it and disk snapshots.

I can't find this idea in PVE wiki, so I suspect it is not that easy to implement. What I try to archive is not wait to have disks copied to backup and right after that unpack it back to disk - pretty huge time overhead, isn't it?

Please advice! I'd be happy to know it is possible by PVE core functionality but I can also do the same by writing some scripts to implement that fast and in good fashion.

Thank you!
 
It will still take some time since you will need to make a clone of the snapshot to be able to detach it from the master disk.
 
>>But if it is possible to create disks snapshots (using LVM or qcow2 features) and use these snapshots as disks for new VM?

For qcow2 (or ceph,zfs), create a template in proxmox (it's create a snasphot in background), then create a linked clone.
It's not possible with lvm/
 
So if I got the idea right, all I need is to have qcow2 volumes in my VM and that's all, even no requirements like need to have LVM underneath? Good news, really!

I've tried that but with raw disks so clone creation was very long since Proxmox copied the whole disks. Will check with qcow2 now, thank you!

>>But if it is possible to create disks snapshots (using LVM or qcow2 features) and use these snapshots as disks for new VM?

For qcow2 (or ceph,zfs), create a template in proxmox (it's create a snasphot in background), then create a linked clone.
It's not possible with lvm/
 
So if I got the idea right, all I need is to have qcow2 volumes in my VM and that's all, even no requirements like need to have LVM underneath? Good news, really!

I've tried that but with raw disks so clone creation was very long since Proxmox copied the whole disks. Will check with qcow2 now, thank you!

I forgot to say that's it's working too with .raw as template
 
That's tha catch. My tests confirmed that, too.

No, this is not the problem I try to overcome. Here is the example:

Say, I have a running VM with some software in it. It is running continuously day by day and there is no reason to stop it. But, for example, we want to check what is we do some upgrade to software that's running in the VM, and want to test the upgrade on exact copy of the VM?

Yes we can do a backup and restore to another VM next to our initial one (say, we do not care for disk space and RAM, we just have plenty of it), but if the VM uses say 50 or 100 Gb of disks (not rare situation), we'll spend a lot of time in dumb coping data over. As an alternative, if we run the new VM on disks that are snapshots of initial VM disks, we'll be able to run new ("cloned") VM in no time.

The problem is, Proxmox can do linked clones based on templates and not on "real" VM. But what is I do this trick: my VM's disks are on local LVM volume, so I can create LVM snapshot volume, then mount it as another partition, and create anothe .conf file in /etc/pve/qemu-server so new VM will use disks from this new mounted path? I suspect there should be some way like this one to do liked cloning from PVE interface or with PVE API.

Thank you for your help, hope we'll find a way out! :)
 
Say, I have a running VM with some software in it. It is running continuously day by day and there is no reason to stop it. But, for example, we want to check what is we do some upgrade to software that's running in the VM, and want to test the upgrade on exact copy of the VM?

Currently, you can create a full clone (full copy) of a running vm (right click->clone).
This work with any storage. (so you don't need to backup/restore).

linked clone of vm is not implemented.
 
Here is how to make a copy-on-write clone of a container when storage is rbd on ceph.
In this example we take a snapshot of 184 which is in ceph pool "mypool" and copy-on-write clone will be 199.

  • pct snapshot 184 snap1
  • rbd snap protect mypool/vm-184-disk-0@snap1
  • pct create 199 /some/directory/empty.tar.gz --arch amd64 --description 'snapshot of 184' --memory 5000 --net0 name=eth0,bridge=vmbr0,firewall=0,ip=dhcp,ip6=auto,hwaddr=16:25:97:B1:B9:D5 --unprivileged 1 --hostname snap184 --ostype unmanaged --storage mypool
  • rbd remove mypool/vm-199-disk-0
  • rbd clone mypool/vm-184-disk-0@snap1 mypool/vm-199-disk-0
  • vi /etc/pve/lxc/199.conf (change correct ostype)

Removing
  • pct stop 199
  • pct destroy 199
  • rbd snap unprotect mypool/vm-184-disk-0@snap1
  • pct delsnapshot 184 snap1
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!