Posts Tagged ‘esxi’

VMware ESXi: adding files which survive reboot

August 5th, 2009 juergens 3 comments

ESXi replace all manual added files, except datastores, at booting time.
Keeping a ssh key for passwordless login, e.g. for initiating a backup script or apc shutdown, is not possible without a little trick.

At booting time, the script /etc/rc.local is executed. Furthermore it’s possible to modify this script and it still survives the reboot.

1) Copy the needed files to /vmfs/volumes/datastore1/
2) edit /etc/rc.local to your needs
e.g. for copying ssh keys into the right place:

cp -r /vmfs/volumes/datastore1/.ssh/ /.ssh

This trick works for all data that won’t survive a regular reboot.
It’s also possible to customize the /bootbank/oem.tgz, but if it fails the ESXi won’t boot till the oem.tgz is recovered. Therefor, the solution above is really uncritical to me.

Categories: it Tags:

VMware ESXi: copying vmdk without blowing up

August 5th, 2009 juergens 2 comments

If you copy a vmdk from a ESXi system via ‘cp’ or anything similar, your so called sparse-vmdk, will blow up to the maximum size which was defined.
For example, a VM with a 25G partition shows up with 25G but needs only the space which consumes the data you really have.

The parameter ‘-s’ in the command ‘ls’ presents the really needed space.

 ls –slh *.vmdk
140K -rw------- 1 root root 8,0G  3. Aug 14:20 bac-test-flat.vmdk
4,0K -rw------- 1 root root  424  3. Aug 14:22 bac-test.vmdk

The vmdk was freshly created and no operating system was installed. It consumes only 140k instead of the defined 8G.

So far so good, but a copy with ‘cp’ will replace the null-pointer in this file with real zeros. The result is a 8G consuming file with only zeros in it and the storage efficiency is gone.

For copying vmdk files, there is a tool called ‘vmkfstools’ available on the ESXi server.

vmkfstools -i "source.vmdk" -d thin "destination.vmdk"

There should be no snapshot and source and destination are the meta vmdk files. e.g. vmname.vmdk (not flat or delta).

‘thin’ is the secret of keeping the null-pointer in the flat file.
The tool also reverts a vmdk which was blown up, back into a thin file!

For an easier usage i wrote a tiny script to copy like it is with ‘cp’:

if [ -n "$1" ] || [ -n "$2" ]; then
echo "Error: Usage $0 [source] [destination]"
echo "Use only vmdk-meta files! no flat or delta allowed!"
echo " "
vmkfstools -i "$1" -d thin "$2"

create a script called ‘vmcp’,
save it in /usr/bin
and set execution rights (chmod +x /usr/bin/vmcp)

Now you can copy with

 vmcp source.vmdk destination.vmdk
Categories: it Tags: