As I expained in the previous blog entry, the intend of the “Prompt-free Applicance deployment” series is to avoid to enter manually all the VM details on the very first start. Whether there’re a lot of steps, in the end it all can be scripted.
It can be done by only one way: modification of the scripts started on VM startup. To do so, we must have access to the scripts which are hosted on one of the 5 given disks. As shown in that other blog entry, the first one is the one we want to go through.
Unfortunately, whether VMWare offers the utility vmware-mount, it cannot be in read/write mode, the vmdk being compressed.
There’s no straightaway and easy method. The only way I found is to push the VM to ESXi, get back the file corresponding to the first disk, mount it, modify the script, and push back the file.
Here we’ll see how to get back and mount the file corresponding to the first disk.
A) First of all, we should “push” the appliance to ESXi.
I’m using the tool OVFTool as below.
Create a local .ovftool file, it will be taken by the command line:
echo "lax" > .ovftool
echo "datastore=vm" >> .ovftool
echo "skipManifestCheck" >> .ovftool
echo "overwrite" >> .ovftool
echo "powerOffTarget" >> .ovftool
echo "net:HostOnly=VM Network 2" >> .ovftool
#echo "powerOn" >> .ovftool
echo "name="myVM_name >> .ovftool
Note that it should not be configured to start the VM automatically.
Then, run the command line:
ovftool inputVM.ovf vi://root:pwd@192.168.1.10:443
B) Second, get the file from ESXi.
Here we have first to check what is the file.
From ESXi server, we have something like:
/vmfs/volumes/506c2d23-01dbe48d-7940-001ec9deb63b/HCMDB-SES-85302d # ls -l
-rw------- 1 root root 7543455744 Jun 5 19:12 HCMDB-SES-85302d-flat.vmdk
-rw------- 1 root root 472 Jun 5 19:11 HCMDB-SES-85302d.vmdk
-rw-r--r-- 1 root root 0 Jun 5 19:11 HCMDB-SES-85302d.vmsd
-rwxr-xr-x 1 root root 1766 Jun 5 19:11 HCMDB-SES-85302d.vmx
-rw-r--r-- 1 root root 271 Jun 5 19:11 HCMDB-SES-85302d.vmxf
-rw------- 1 root root 5782896640 Jun 5 19:15 HCMDB-SES-85302d_1-flat.vmdk
-rw------- 1 root root 479 Jun 5 19:12 HCMDB-SES-85302d_1.vmdk
-rw------- 1 root root 36709597184 Jun 5 19:22 HCMDB-SES-85302d_2-flat.vmdk
-rw------- 1 root root 479 Jun 5 19:15 HCMDB-SES-85302d_2.vmdk
-rw------- 1 root root 13119782912 Jun 5 19:28 HCMDB-SES-85302d_3-flat.vmdk
-rw------- 1 root root 479 Jun 5 19:22 HCMDB-SES-85302d_3.vmdk
-rw------- 1 root root 18351128576 Jun 5 19:36 HCMDB-SES-85302d_4-flat.vmdk
-rw------- 1 root root 479 Jun 5 19:28 HCMDB-SES-85302d_4.vmdk
/vmfs/volumes/506c2d23-01dbe48d-7940-001ec9deb63b/HCMDB-SES-85302d #
Disk one does not get any number, disk 2 is *_1, disk3 is *_2 and so on.
Within a simple command line, we can get it back to a local machine in a given directory:
vifs --server 192.168.1.10:443 --username root --password pwd --get '[vm] 'HCMDB-SES-85302d/HCMDB-SES-85302d-flat.vmdk' ./HCMDB-SES-85302d-esxi
Once done, on local machine:
[root@omsa:/nfs/software/PeopleSoftCD/OVA/HCMDB-SES-85302d/HCMDB-SES-85302d-esxi]# ls -l
total 7373864
-rw-r--r-- 1 root root 7543455744 Jun 5 21:49 HCMDB-SES-85302d-flat.vmdk
[root@omsa:/nfs/software/PeopleSoftCD/OVA/HCMDB-SES-85302d/HCMDB-SES-85302d-esxi]#
C) Now, mounting the file as a disk.
This is probably the trickiest past of that series. Well, unless you are a good Linux administrator.
We will use the Linux command losetup, from the man, here is a small explanation of what it is:
DESCRIPTION
losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device.
Briefly speaking, mounting a flat file as a disk.
We should start by finding a free loop device:
[root@omsa:]# losetup --find
/dev/loop0
[root@omsa:]#
Then associating this loop device to the flat file:
[root@omsa:]# ls -l
total 7373864
-rw-r--r-- 1 root root 7543455744 Jun 5 21:49 HCMDB-SES-85302d-flat.vmdk
[root@omsa:]# losetup /dev/loop0 ./HCMDB-SES-85302d-flat.vmdk
[root@omsa:]#
We can now see the loop device as a result of a disk:
[root@omsa:]# fdisk -lu /dev/loop0
Disk /dev/loop0: 7543 MB, 7543455744 bytes
255 heads, 63 sectors/track, 917 cylinders, total 14733312 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00064cf9
Device Boot Start End Blocks Id System
/dev/loop0p1 * 63 208844 104391 83 Linux
/dev/loop0p2 208845 10522574 5156865 83 Linux
/dev/loop0p3 10522575 14731604 2104515 82 Linux swap / Solaris
[root@omsa:]#
We recognize here the swap space as I describe a the previous post in the third partition, the first partition is the grub partition (see previous post for the content).
From the output above, we can say that the second partition is our.
The unit is 512 bytes, the starting point of the second partition is 208845. The starting offset of our partition will be 512*208845=106928640
We will be able to create a new loop device from the first within the computed offset:
[root@omsa:]# losetup --find
/dev/loop1
[root@omsa:]# losetup /dev/loop1 /dev/loop0 -o 106928640
Now we can really mount the disk itself from within the last loop device:
[root@omsa:]# mkdir /mnt/HCMDB-SES-85302d
[root@omsa:]# mount /dev/loop1 /mnt/HCMDB-SES-85302d -o rw,user
As of now, we will be able to go on the mount point and modify whatever we want. Any change will remains onto the disk.
For instance:
[root@omsa:]# cd /mnt/HCMDB-SES-85302d
[root@omsa:/mnt/HCMDB-SES-85302d]# ls
bin boot dev etc home lib lib64 lost+found media misc mnt opt proc root sbin selinux srv sys tmp u01 usr var
[root@omsa:/mnt/HCMDB-SES-85302d]# cd tmp
[root@omsa:/mnt/HCMDB-SES-85302d/tmp]# touch test
[root@omsa:/mnt/HCMDB-SES-85302d/tmp]# rm -f test
[root@omsa:/mnt/HCMDB-SES-85302d/tmp]# cd ../
[root@omsa:/mnt/HCMDB-SES-85302d]# ls
bin boot dev etc home lib lib64 lost+found media misc mnt opt proc root sbin selinux srv sys tmp u01 usr var
[root@omsa:/mnt/HCMDB-SES-85302d]# cd ./opt/oracle/psft/vm/
[root@omsa:/mnt/HCMDB-SES-85302d/opt/oracle/psft/vm]# ls
appbatch-start expect-sftp oraclevm-template-appbatch.sh oraclevm-template-pia.sh oraclevm-template-utils.sh template-cleanup.sh
appliance.props expect-ssh oraclevm-template-db.sh oraclevm-template-search.sh ptem_variables.properties tnsnames.ora
apply-hotfix.sh installpia.sh oraclevm-template-env.sh oraclevm-template-ses.sh README tnsnames.ora.exa
cmppropsfile.py network-update oraclevm-template-ext.sh oraclevm-template.sh sql updatepiahost.sh
[root@omsa:/mnt/HCMDB-SES-85302d/opt/oracle/psft/vm]# cp oraclevm-template.sh oraclevm-template.sh.orig
[root@omsa:/mnt/HCMDB-SES-85302d/opt/oracle/psft/vm]#
Ok, it will be serious time for script modification.
To be continued.
Nicolas.
No comments:
Post a Comment