Home > it > VMware ESXi: copying vmdk without blowing up

VMware ESXi: copying vmdk without blowing up

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’:

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
if [ -n "$1" ] || [ -n "$2" ]; then
SRC="$1"
DST="$2"
else
echo "Error: Usage $0 [source] [destination]"
echo "Use only vmdk-meta files! no flat or delta allowed!"
echo " "
exit
fi
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:
  1. pk
    April 10th, 2013 at 07:58 | #1

    for i in `ls` ; do dd if=$i of=../NewDirectory/$i ; done

  2. Tobias
    January 7th, 2014 at 15:27 | #2

    Hi,
    I have the use case to copy VMDK files from source to destination datastore with exact same VMDK file type because the files I would like to copy are VM templates. I want to copy the whole DS content (= alll Templates) 1:1 without VMDK type change.

    What would you propose?

    Regards
    Tobias

  1. No trackbacks yet.

Spam protection by WP Captcha-Free