Duplicate Virtual Machines: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
(→‎Introduction: link to templates-page)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Introduction==
This page is meant for Kernel Virtual Machines (KVM) only.
Cloning an existing VM is problematic because of the points mentioned in this article. You may want to create a [[VM Templates and Clones|VM Template]] for this purpose.
== Create virtual machines by copying a previous one ==
== 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.
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.
Line 17: Line 22:
** change the /etc/hosts file content accordingly (eg: "#nano /etc/hosts")
** change the /etc/hosts file content accordingly (eg: "#nano /etc/hosts")
** reboot the vm ("#reboot now")
** reboot the vm ("#reboot now")
Beware: if necessary also edit /etc/network/interfaces


== How to change the mac address(es) ==
== 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 ;-).
Any '''n'''etwork '''i'''nterface '''c'''ard has its (supposedly) unique MAC address, you know. Virtual NICs are pretty much the same as real, but easier to manage ;-).
When you duplicate an existing vm, also its MAC address gets duplicated, and that is BAD.
When you duplicate an existing vm, its MAC address also gets duplicated, and this is DANGEROUS.


Supposing your vm has only one virtual nic, you can  
Supposing your vm has only one virtual NIC, you can  
* stop the vm
* stop the vm
* from pve web interface, remove the virtual nic (eg: eth0)  
* 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.
* create a new one, this will get a new MAC, and your vm will always see it as eth0.
* start again the vm and check if everything works fine
* restart the vm and check if everything works fine


This is done at the host level, so is guest OS independent.
This is done at the host level, so is guest OS independent.
Line 35: Line 42:
* ON a Linux OS
* ON a Linux OS
** access a vm terminal as root
** access a vm terminal as root
** remove the previous keys like: "#rm /etc/ssh/ssh_host_*"
** remove the previous keys: "rm /etc/ssh/ssh_host_*"
** reconfigure openssh like: "#dpkg-reconfigure openssh-server"
** reconfigure openssh: "dpkg-reconfigure openssh-server"
** your ssh keys should have been regenerated (even if you're on a ssh session!)
** your ssh keys should have been regenerated (even if you're on a ssh session!)


you should see an output lie:
you should see an output like:
<pre>
<pre>
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 RSA key; this may take some time ...
Line 47: Line 54:


source: http://www.cyberciti.biz/faq/howto-regenerate-openssh-host-keys/
source: http://www.cyberciti.biz/faq/howto-regenerate-openssh-host-keys/
[[Category: HOWTO]]

Latest revision as of 11:44, 23 August 2016

Introduction

This page is meant for Kernel Virtual Machines (KVM) only.

Cloning an existing VM is problematic because of the points mentioned in this article. You may want to create a VM Template for this purpose.

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: "#nano /etc/hostname")
    • change the /etc/hosts file content accordingly (eg: "#nano /etc/hosts")
    • reboot the vm ("#reboot now")

Beware: if necessary also edit /etc/network/interfaces

How to change the mac address(es)

Any network interface card has its (supposedly) unique MAC address, you know. Virtual NICs are pretty much the same as real, but easier to manage ;-). When you duplicate an existing vm, its MAC address also gets duplicated, and this is DANGEROUS.

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 always see it as eth0.
  • restart 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: "rm /etc/ssh/ssh_host_*"
    • reconfigure openssh: "dpkg-reconfigure openssh-server"
    • your ssh keys should have been regenerated (even if you're on a ssh session!)

you should see an output like:

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]

source: http://www.cyberciti.biz/faq/howto-regenerate-openssh-host-keys/