Best way to clone a raw image

  • Thread starter Thread starter Smaon
  • Start date Start date
S

Smaon

Guest
Hello,

I have a 150GB raw image for one of my virtual machines that I would like to clone many times to create other VM's on the same template.

I tried to simply create a new VM and replace the new raw with a copy of my template and it works ok. The only problem is that it's very long to copy these 150GB and I'm looking for more effective way to clone. So here are my questions:

Is there a command to clone an image and to copy only the effective data (not empty disk space) from the first one?
Is there a way to shrink my template raw image so I can copy it quickly and then expand it to the size I want?

If I could avoid to recreate my template from scratch it would be really great.

Many thanks in advance!

Smaon
 
use backup/restore ('vzdump' for backup, 'qmrestore' to restore)
 
Thank you for your answer, but I tested vzdump in --stop and --suspend mode and it looks like it creates a very large backup file (the size of the VM disk) and it takes hours. Is this normal?

If I try with --snapshot, I have the following error:

Code:
Insufficient free extents (1) in volume group pve: 256 required
 
Could just somebody confirm that using vzdump with '--snapshot' is what I'm looking for, meaning a way to backup only the modified data of a virutal machine?
 
Sorry but I think vzdump will not be of any help in this case - it always makes a complete backup of a VM. However you are free to experiment yourself with qcow2 images using qemu-img. Search for "base images". That should make it possible to make incremental images.
 
You might consider using a LiveCD (mount it virtually and boot from it) of Clonezilla or some such. Clone the server as you would a physical server, then use the LiveCD to push the clone to a new VM. I believe Clonezilla (or Ghost or whatever) will only take the used space rather than the whole drive.
 
Thank you very much for your answers. I'm experimenting with qemu-img right now, and if it doesn't help I'll give Clonezilla a try.
 
If you would clone just data not the hole virtual harddisk maybe that could be intereresting for you: http://www.andybotting.com/wordpress/how-do-you-clone-an-lvm-partition
It is no final "How-To". To use this with proxmox you must think about additional steps. For example you should use LVM as storage instead of .raw files (that way you can make snapshots). If you copy just the snapshot of the HD it would not be faster (just downtime if your template should run again quick).

On our server I remove the logical volume pve/data after unmounting /var/lib/vz and mounting temporary on /mnt to copy the content of it into /var/lib/vz (which is just a directory on /dev/mapper/pve-root if nothing is mounted on it). So now I have "just" about ~75GB of free space for OpenVZ machines (which I don´t really use) and .iso files but the rest of my real HD space for creating VM-HDs on LVM directly (not as .raw files) and I am able to make snapshots that way. You can add a LVM-Group in "Storage" of the Proxmox webinterface (but in default installation of proxmox there is no left LVM space free because everything is used already for pve/data and so on (which make sense if you plan to use OpenVZ but...)). I´m pretty sure there is a way to mount the partitions of the virtual harddrives so you can copy the data instead of the HD.


Greetings,
user100