Blog - comments

thank you very much. It was like a walk in the park


Hi Jan, thanks for your feedback.

Thanks Franck, for sharing this. It clears up again a number of things and blows some of the "market...
The below is the XML, which it is parsing and failing: select * from [dbo]...
hi david, I have used the above script for analyzing the trace table. But when I executed, I am gett...
Blog Michael Schwalm Scripts to duplicate an Oracle database virtual machine: step one

dbi services Blog

Welcome to the dbi services Blog! This IT blog focuses on database, middleware, and OS technologies such as Oracle, Microsoft SQL Server & SharePoint, EMC Documentum, MySQL, PostgreSQL, Sybase, Unix/Linux, etc. The dbi services blog represents the view of our consultants, not necessarily that of dbi services. Feel free to comment on our blog postings.

  • Home
    Home This is where you can find all the blog posts throughout the site.
  • Categories
    Categories Displays a list of categories from this blog.
  • Tags
    Tags Displays a list of tags that have been used in the blog.
  • Bloggers
    Bloggers Search for your favorite blogger from this site.

Scripts to duplicate an Oracle database virtual machine: step one

In my last posting of November 9, 2012, Manage templates manually with Oracle Virtual Box, I have presented a solution to duplicate virtual machines using Oracle/ Virtual Box. I did not show the scripts in this first publication, but I promised to tell you more about it...

Let me present the case.

In September 2012, I was asked to create a training environment consisting of five identical virtual machines, with the following constraints:

  • Virtual machines must be configured with Oracle Enterprise Linux 6.1
  • Three Oracle 11g R2 databases must be configured
  • Each virtual machine must have its own network configuration (meaning different hostnames and IP addresses) to co-exist over the network
  • Virtual machines are accessed by the participants via the network through a SSH connexion

All of these training virtual machines run on a powerful laptop which is used as a virtual host (based on Oracle Virtual Box).

The first question I asked myself: Am I going to clone five times the same virtual machine with the graphical user interface? How will I change each VM's hostname, IP address, Oracle configuration? It is a way to do, but if we have to create new training environments in the future, changing the operating system or the Oracle release, we will have to do that again and again. The GUI is not fitting this kind of requirements well.

The best solution for me is to automate this task using scripts. I spent some time writing these scripts, but now, I am able to create as many virtual machines as I want using a properly configured template.

Remember, the solution presented in my first blog acts at two levels:

  • At host level
  • At virtual machine guest level

Today, we are going to develop the host part.

What you need on your virtual host is simple:

  • A template virtual machine
  • The configuration file
  • The duplicate script

The Template

The template consists of a virtual machine, with temporary hostname and IP address, and configured with all required softwares (OS modules, rdbms...). Once the template corresponds to your final configuration, just power it off and keep it in the Virtual Box inventory.




Be careful not to delete it!


The configuration file

This file can register all data you plan to use to customize guest virtual machines. You just have to separate each parameter with a separation character. Let's see the example of my configuration file:





Below is an explanation of each value:

Value Definition

The name of the template to duplicate


The name of the new virtual machine


The path to store new virtual machine files


The hostname of the new virtual machine

The new IP of the new virtual machine

The new netmask of the new virtual machine


A flag used to specify the new virtual machine if it must be customized at its startup*


The path where the new virtual machine will find informations to be customized


* This flag is read by the script on the guest virtual machine and allows to run or not the customization process. If the flag is 0, the script exits. If the flag is 1, the script edits the machine configuration.

You can see that the configuration file contains as many rows as there are clones of the template to create. In our case, we have five rows, to create five virtual machines for the training.


The duplicate script

The duplicate script is written in MS-DOS batch language. It interacts with Virtual Box using VBoxManage.exe to clone, configure, and start cloned virtual machines. It is composed of a main script, which parses this configuration script, and a child script (or cloning script), run for each line of the configuration file.

Main script

The main script parses the configuration file in a loop. It must be run with the name of the configuration file as input parameter. See below:


C:\> duplicate_script.cmd "configuration_file.cfg"


Below is the content of the script:


REM        ## Beginning of the script
@echo off

REM        ## Open the configuration file and run the cloning procedure ##
for /f "tokens=1-8 delims=;" %%A in ('type %1') do (
    start clone.bat %%A %%B %%C %%D %%E %%F %%G %%H %%I
REM        ## End of the script


For each line found in the configuration file, the cloning script is run by passing the input parameters. This way to run the cloning script has two advantages:

  • All virtual machines are created at the same time (gain of time)
  • You can monitor the creation of each virtual machine in its own window




Child (or cloning) script

This script is run for each new virtual machine to create, depending of the number of line registered in the configuration file.

The first thing the script does is to initialize variables for next use.




Note that %DIRECTORY% and %SHARED_FOLDER% use respectively the name of the virtual machine and the hostname to create the complete path for virtual machine data and shared folder location.

Next, it creates the shared folder path if it does not exist.


        echo The directory %SHARED_FOLDER% does not exist and will be created.
        mkdir %SHARED_FOLDER%


Once the shared folder created, the script duplicates the template into the new virtual machine.


echo Cloning virtual machine %TEMPLATE%...
"C:\Program Files\Oracle\VirtualBox\VBoxManage" clonevm "%TEMPLATE%" --name "%VMNAME%" --basefolder %DIRECTORY% --register


The option "--register" enables the virtual machine to appear in the Virtual Box inventory.

The shared folder and the new virtual machine are created, the shared folder must now be attached to the virtual machine.


echo Adding shared folder %SHARED_FOLDER% to %VMNAME%...
"C:\Program Files\Oracle\VirtualBox\VBoxManage" sharedfolder add "%VMNAME%" --name "vmform" --hostpath "%SHARED_FOLDER%"


The option "--name" specifies the name of the shared folder as it is seen by the virtual machine. For exemple, with netuse on Windows or with mount on Linux.

The shared folder is intended to store a parameter file, required for the new virtual machine customization. The creation of this parameter file is done with a basic OS command:


echo Generation of the parameter file %SHARED_FOLDER%\conf.ini for %VMNAME%...


You can see that the parameter file is created with a fictive fifth parameter (no value after the last separator character). It is to guarantee that Windows does not add blank space after the last parameter which is the flag. A blank space after this parameter causes troubles when customizing Windows environment...

To finish, the script starts automatically the new virtual machine inorder to start its customization without user intervention:


echo Starting %VMNAME%...
"C:\Program Files\Oracle\VirtualBox\VBoxManage" startvm "%VMNAME%" --type headless


The option "--type headless" is facultative. It allows to start the virtual machine without opening its window in the Virtual Box interface. The virtual machine starts in background on a virtual host.


That's it!

If you have correctly followed my advice, you are now able to clone a virtual machine from a template and to start it automatically with the free tool Oracle Virtual Box. Next time, we will see how to configure the template to allow a duplicated virtual machine to configure itself at startup.

To be continued...

Rate this blog entry:

Michael Schwalm is Consultant at dbi Services and has more than two years of experience in Oracle database administration. He has a broad knowledge in the realization of virtualization infrastructures such as vMware vSphere. He took his first steps in database administration as an integrator of a web applications on Unix, Oracle, and Websphere environments. Michael Schwalm is Oracle Certified Professional 11g and RAC Implementation Specialist 11g. Prior to joining dbi services, Michael Schwalm was application administrator at SOGETI Est (F) on behalf of PSA Peugeot Citroen and responsible for the realization and managing of Unix environments and Oracle databases in the context of migration projects. Michael Schwalm holds a BTS diploma in Information System Management from Belfort (F) and a TSAR diploma in advanced network administration from Strasbourg (F). His branch-related experience covers Automotive, Software industry, Financial Services / Banking, etc.


  • Guest
    Ryan adams Wednesday, 27 February 2013

    I read your blog completely which is better than first one and here is some unique stuff discussing about the oracle virtualization. template, scripts and some useful guidance so I would like to thanks for sharing it did great job regularly.

Leave your comment

Guest Wednesday, 01 July 2015
AddThis Social Bookmark Button
Deutsch (DE-CH-AT)   French (Fr)


Contact us now!

Send us your request!

Our workshops

dbi FlexService SLA - ISO 20000 certified.

dbi FlexService SLA ISO 20000

Expert insight from insiders!

Fixed Price Services

dbi FlexService SLA - ISO 20000 certified.

dbi FlexService SLA ISO 20000

A safe investment: our IT services at fixed prices!

Your flexible SLA

dbi FlexService SLA - ISO 20000 certified.

dbi FlexService SLA ISO 20000

ISO 20000 certified & freely customizable!

dbi services Newsletter