Saturday, April 27, 2013

Scripting VirtualBox Appliance move to VMWare ESXi

As an addendum of an article I wrote to explain how to move from the delivered VirtualBox Appliance for Peoplesoft to VMWare ESXi, there were several manual steps to be done in order to get it works.

It can be tedious to make some changes manually in the ovf file (see the details in the given link above). We all know that manual steps are subject to human error. Moreover, make one script may save your time, launch it and you can enjoy something else instead of waiting for the unzip to be completed, the untar, the push to ESXi host... And who like to do more than once the same tedious job ? 
Lastly, since Peoplesoft will deliver these VirtualBox Appliances every 8 weeks (!), this task has to be done quite often. So, no way but a script must be written somehow.

You can actually script every single step that I explained in the other blog entry (see the link above).
Even the download, within the wget option available on My Oracle Support, can be scripted, as shown below.
First accept the licence terms, and download the wget script.
This wget script is a shell script, you have to put your user’s password in it, and run it. There’s a timeout though, 8 hours to download all the 8 files (about 24.5Gb), depending of your bandwidth, it may or may not be enough. 
Mine is not that fast (sic), so I won’t use it for now and the following is assuming the zipped files are already there, previously downloaded by one or other way.

As I showed in the other blog entry, to move from VirtualBox Appliance to VMWare ESXi, I use the VMWare ovftool, so it is also assumed that you have it installed.

To be short, once you have the zipped files and the ovftool installed, you are ready to go.

As shown in the other blog post (see link above), there manual changes in the ovf file – and it can be confusing. Let’s use sed, that will change all at once.

I’ll use a parameter file replace.sed, and a script (see below).
Let’s say your are downloading FSCM92000 image, the zip files name format will be like
The script takes one parameter as input, here it will be FSCMDB-SES-85302d. The destination VM name in VMWare ESXi will also be FSCMDB-SES-85302d.
All is in the same folder, zip files, replace.sed and

So, here we go (test below done from a CentOS 6.4 VM hosted on my ESXi server):
[root@omsa FSCM92000]# ls -l
total 25118780
-rwxrw-rw- 1 root root        969 Apr 24 16:24
-rwxrw-rw- 1 root root 3703776794 Apr 24 19:34
-rwxrw-rw- 1 root root 3475881883 Apr 24 19:15
-rwxrw-rw- 1 root root 3721073992 Apr 24 19:25
-rwxrw-rw- 1 root root 3702449335 Apr 24 23:48
-rwxrw-rw- 1 root root 3730977958 Apr 25 01:09
-rwxrw-rw- 1 root root 3709152935 Apr 25 08:16
-rwxrw-rw- 1 root root 3653153461 Apr 25 20:12
-rwxr-xr-x 1 root root       1049 Apr 26 18:36
-rwxr-xr-x 1 root root        938 Apr 24 18:00 replace.sed
[root@omsa FSCM92000]# more replace.sed
s/<OperatingSystemSection ovf:id="109">/<OperatingSystemSection ovf:id="101">/
s/<vbox:OSType ovf:required="false">Oracle_64<\/vbox:OSType>/<vbox:OSType ovf:required="false">oracleLinux64Guest<\/vbox:OSType>/
s/<rasd:Caption>sataController0<\/rasd:Caption>/<rasd:Caption>SCSI Controller0<\/rasd:Caption>/
s/<rasd:Description>SATA Controller<\/rasd:Description>/<rasd:Description>SCSI Controller<\/rasd:Description>/
s/<rasd:ElementName>sataController0<\/rasd:ElementName>/<rasd:ElementName>SCSI Controller0<\/rasd:ElementName>/

echo `date`
echo "Start"
#Unzip the input zipfiles
for zipfile in `ls ${myVM}*.zip`
echo `date`
echo "unzipping file "$zipfile
unzip $zipfile

#Concatenation to one ova file
rm -f ${myVM}.ova
for ovafile in `ls ${myVM}.ova_?of?`
echo `date`
echo "concatenation file "$ovafile
cat $ovafile >> ${myVM}.ova

#Extract files from ova
echo `date`
echo "untar the ova file"
tar xvf ${myVM}.ova

#Backup the ovf
mv ${myVM}.ovf ${myVM}.ovf.orig

#Replace the string to be replace as defined in replace.sed file
sed -f replace.sed < ${myVM}.ovf.orig > ${myVM}.tmp

#Take the item line corresponding to the sound item group
line=`grep -ni -B7 sound ${myVM}.tmp|grep  "<Item>"|awk -F- '{print $1}'`
#It will replace the <Item> for the sound card item to be deactivated
sed -e "${line}s/<Item>/<Item ovf:required=\"false\">/" < ${myVM}.tmp > ${myVM}.ovf
rm -f ${myVM}.tmp

echo `date`
echo "Moving to ESXi"
ovftool --lax -ds=vm "--net:HostOnly=VM Network" ${myVM}.ovf "vi://root:adam2008@"
echo `date`
echo "End"
[root@omsa FSCM92000]#
[root@omsa FSCM92000]# ./ FSCMDB-SES-85302d
Fri Apr 26 18:36:56 CEST 2013
Fri Apr 26 18:36:56 CEST 2013
unzipping file
  inflating: 16660432Readme.html
Fri Apr 26 18:36:56 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_1of7
Fri Apr 26 18:45:11 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_2of7
Fri Apr 26 18:53:24 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_3of7
Fri Apr 26 19:01:57 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_4of7
Fri Apr 26 19:10:20 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_5of7
Fri Apr 26 19:18:43 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_6of7
Fri Apr 26 19:27:05 CEST 2013
unzipping file
  inflating: FSCMDB-SES-85302d.ova_7of7
Fri Apr 26 19:35:15 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_1of7
Fri Apr 26 19:43:45 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_2of7
Fri Apr 26 19:52:27 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_3of7
Fri Apr 26 20:00:55 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_4of7
Fri Apr 26 20:09:25 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_5of7
Fri Apr 26 20:17:58 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_6of7
Fri Apr 26 20:26:30 CEST 2013
concatenation file FSCMDB-SES-85302d.ova_7of7
Fri Apr 26 20:34:51 CEST 2013
untar the ova file
Fri Apr 26 21:35:49 CEST 2013
Moving to ESXi
Opening OVF source: FSCMDB-SES-85302d.ovf
Opening VI target: vi://root@
Deploying to VI: vi://root@
Transfer Completed
- No manifest file found.
- No manifest entry found for: 'FSCMDB-SES-85302d-disk1.vmdk'.
- No manifest entry found for: 'FSCMDB-SES-85302d-disk2.vmdk'.
- No manifest entry found for: 'FSCMDB-SES-85302d-disk3.vmdk'.
- No manifest entry found for: 'FSCMDB-SES-85302d-disk4.vmdk'.
- No manifest entry found for: 'FSCMDB-SES-85302d-disk5.vmdk'.
Completed successfully
Fri Apr 26 21:59:11 CEST 2013
[root@omsa FSCM92000]#
Again, the manifest warning may be ignored.
Actually, took approximately  1 hour to unzip all the files, 1 hour to concatenate them all in one, 1 hour to extract and 20 minutes to move to ESXi.

And now, from vSphere Client, you can see the new virtual machine (I added already the CD/DVD drive for further VMWare tools installation): 
You can see above the HD1 is an IDE, whether the HD2,3,4 and 5 are SCSI (below). No idea why HD1 must be IDE.OVA_ESXi_047
As of now, you can start the VM and follow the instructions given by the Oracle doc.

Obviously, it’s just an example of script, everyone can adjust, add error handler or more parameters…



No comments: