15. Clone an existing VM

To duplicate an existing VM, you should execute the following steps. First, copy the template folder to a new VM specific folder, we will use the folder name vm2 in this example.

cd /hv/VMs
cp -R vm_template vm2

Then you need to copy several files from the VM to be cloned and overwrite the one from the template. In this example we assume to clone the VM stored in folder vm1:

cd /hv/VMs/vm2
cp ../vm1/vmconfig.sh .
cp ../vm1/OVMF*.fd .

The following files need to be copied in case automatic network configuration is used for the external network (which is the default case). It assures, the network settings are identical for both VMs. If you do not copy these files, the VM may be not connected to the external network.

cp ../vm1/netif_conf.sh .
cp ../vm1/dns_conf.sh .
cp ../vm1/br_conf.sh .

Hint

If automatic network configuration is enabled, the VM started first will set up the overall networking. When a VM is started using the vmrun.sh script, this script is not aware that another VM may already run. Thus, the startup of the second VM will also try to initialize the overall networking. This will fail and an error message is generated. After a timeout of 5 seconds, the settings stored in the files netif_conf.sh and br_conf.sh will be used. This timeout can be eliminated by adjusting the file /hv/VMs/config/vmconfigbase.sh

cd /hv/VMs/config
gedit vmconfigbase.sh
# set the timeout to 0
echo "use automatic settings for external network"
# 1.) determine default gateway
###############################
((netif_auto_timeout=5))

Caution

If automatic network configuration is enabled the IP address which the hypervisor host will get will most likely change from time to time. The same is true for the DNS server IP address. This would lead to networking issues because only the VM which initializes the network (the one which is started first) will run properly. To avoid this, the br_config.sh and dns_config.sh scripts of the first VM which is started need to be copied to the location where the second VM is running. For example, if the VM started first is located in /hv/VMs/vm1 and the second one is located in /hv/VMs/vm2 the following highlighted command lines be added into the vmrun.sh script:

cd /hv/VMs/vm2
gedit vmrun.sh
    :  :  :  :
    :  :  :  :
    :  :  :  :
export bootvm=1
source $vmdir/vmconfig.sh
# copy the bridge and DNS configuration script
cp $vmsdir/vm1/br_conf.sh .
cp $vmsdir/vm1/dns_conf.sh .
$vmsdir/vmctl/vms.sh&
    :  :  :  :
    :  :  :  :

We need to copy the VM disk image and rename it to vm2 (if you chose another name for the VM folder, please use this name for the disk image name!).

cd /hv/VMs/vm2
cp ../vm1/vm1.qcow2 vm2.qcow2

The VM configuration file needs to be adjusted. The name of the VM needs to be the same as the VM folder. The VM id (vmid) needs to be adjusted, it has to be unique over all VMs. You may have to adjust the number of CPUs to be used (num_cpus) and the RAM size (ramsize) of the new VM. Please also consider to adjust the number of CPUs and RAM size used for other VMs. The total number of CPUs should not be higher than the overall number of CPUs for all non real-time guests. Also the cumulated RAM size should not be higher than the available RAM size for all non real-time guests (total RAM size reduced by the size for the Real-time OS partition).

gedit /hv/VMs/vm2/vmconfig.sh
# Adapt following lines to your system and needs:
vmname=vm2
vmid=2
num_cpus=...
ramsize=...

The second Windows VM has to be added to the configuration.

gedit /hv/config/windowsvm.config
# Add the following configuration block at the very end of the file:
[Rtos2]
    "Name"="WindowsVM"
    "Description"="General purpose operating system"
    "AttachOnly"=dword:1
    "MemorySize"=dword:FFFFA11A

Furthermore the following .config file must be also adjusted (Rtos2 activated):

gedit /hv/config/memory.config
[Rtos2]
    "MemorySize"=dword:2000000              ; 2nd RTOS
[Rtos2-End]

In case the second OS to be started is configured to start a second instance of the RTOS, this has to be deactivated.

gedit /hv/config/cpu.config
# comment the following two lines:
;[Rtos2]
;    "ProcessorMask"=dword:4       ; (bit mask, bit 0 = core 0, bit 1 = core 1, ...)

and the following entry must be activated:

gedit /hv/config/membase.config
[Rtos2]
    "MemoryStartAddress"=dword:6000000          ; 96Mb

In case of RT-Linux, if the RTOS configuration is prepared for 2 RTOS instances you need to remove the entry for the second instance.

gedit /hv/lx/hv.config
# comment the following line:
;#include "../config/hwdevbase_rtos2.config"

The same is required for other RTOS like VxWorks (/hv/vx/vxworks.config)

After starting the second Windows VM instance, some settings have to be adjusted. First, you need to change the OSID to which the Windows guest is attached from 1 to 2. Select the “Hypervisor Attach” Shortcut on the Desktop and change the command line to:

%RTE_ROOT%\RtosUpload.exe -attach -osid 2

Also the Virtual Network settings need to be adjusted. You need to change the IP address of the Virtual Network adapter.

  • open the Network and Sharing Center

  • Select “change adapter settings”

  • Select the “Realtime OS Virtual Network Adapter”

  • Open the Properties and set the IP Version 4 address to 192.168.157.4

You need to change the MAC address of the Virtual Network adapter.

  • open the Device Manager

  • Open the Properties of the “Realtime OS Virtual Network Adapter”

  • Go to the Advanced Tab and set the MAC address to AA-BB-CC-DD-EE-03

Finally you should be able to use the Virtual Network connection to the RTOS as well as the RTOS-Library in both Windows VM instances.

Caution

You should start the second VM at least 1 second after the first one to assure the network configuration executed by the VM started first is already finished. Please also note, the autostart mechanism described in the previous chapters is not implemented for a second VM instance. You will have to duplicate and adjust the respective script and configuration files.