Cloning in Proxmox VE

xldata

New Member
Oct 10, 2009
14
0
1
Since one of the advantages of virtualization is the ability not to install every server (vm) from scratch I tried to clone a linux vm using openvz containers. I've seen people asking for this option a few times on this forum so I decided to give it a try...

Some specs of my vm :

Type : Open-VZ
OS : CentOS 5.x X64_64
Disk : 40GB
Networking : 1 bridged interface (eth0)

What I did to clone this vm was very simple :

  1. I first created a 'template' vm containing all stuff I need and using a temporarily ip adres.
  2. In the network config file of eth0 (/etc/sysconfig/network-scripts/ifcfg-eth0) I comment out the HWADDRESS line, else it will not come up with another mac address...
  3. Stop this 'template' vm as it is just used for cloning.
  4. Create a backup : vzdump --dumpdir /path/to/backupdir --snapshot 101
  5. Restore in new container : vzrestore /path/to/backupdir/backupfile_of_container_101 102
  6. Create a new mac for eth0 : vzctl set 102 --netif_add eth0
  7. Modify the hostname in the proxmox webinterface.
  8. Bootup the vm and open a vnc console.
  9. Change the ip address in /etc/sysconfig/network-scripts/ifcfg-eth0
  10. Go to /etc/ssh and remove all keys : rm -f /etc/ssh/*key*
  11. Restart the ssh server so it will regenerate keys : service sshd restart
And we have a fresh new copy of the original vm containing unique keys and network configuration... Depending on the size of the filesystem content of the original vm this can be done really quick...

Of course this example was CentOS based, since we're using the DirectAdmin control panel on these vm's and the only option for a 64bit version is CentOS when using DirectAdmin... So other distro's can have slight differences when performing the steps inside the vm... The same will be true when you use venet instead of bridged networking, the step for regenerating a new mac will be different...

I guess there will be a similar way to clone kvm guests...however I'm not completely sure how to handle Windows guests... When working with Xenserver a lot of my customers used sysprep to be able to clone Windows guests...this tool takes care of the unique id's in Windows...

Best regards,

Werner Reuser
XL-Data Hosting, Virtualization & Storage Solutions