Duplicate Virtual Machines
Create virtual machines by copying a previous one
Virtual machine environments allow to create vm from scratch, of course, but it is also possible and sometimes useful to be able to create one vm as a perfect copy of another one you already have.
There are issues you have to take care of, anyway:
- a duplicated vm will have exactly the same hostname of the original one
- a duplicated vm will have exactly the same mac address(es) of the original one
- a duplicated vm will have exactly the same ssh keys of the original one
- a duplicated vm will have exactly the same SID of the original one (windows machines only)
if both the original vm and the "copy" are running together in the same network, this will cause issues and/or unsafe vm environments.
How to change vm hostname
It should be sufficient to
- On Linux guest OSes
- log into a vm terminal as root
- change the /etc/hostname file content to the new hostname (eg:
- change the /etc/hosts file content accordingly (eg:
- reboot the vm (
How to change the mac address(es)
Any network card has its (supposedly) unique MAC address, you know. Virtual nics are pretty much ethe same as real, but easier to manage ;-). When you duplicate an existing vm, also its MAC address gets duplicated, and that is BAD.
Supposing your vm has only one virtual nic, you can
- stop the vm
- from pve web interface, remove the virtual nic (eg: eth0)
- create a new one, this will get a new MAC, and your vm will see it always as eth0.
- start again the vm and check if everything works fine
This is done at the host level, so is guest OS independent.
How to change the SSH keys
The SSH host keys should be unique of each machine, much like MAC address above, but for security reasons. So, after duplicating a virtual machine as a new one, you need to re.generate the vm host ssh keys.
- ON a Linux OS
- access a vm terminal as root
- remove the previous keys like:
- reconfigure openssh like:
- your ssh keys should have been regenerated (even if you're on a ssh session!)
you should see an output lie:
Creating SSH2 RSA key; this may take some time ... Creating SSH2 DSA key; this may take some time ...
- Restarting OpenBSD Secure Shell server: sshd. [OK]