Disk Space Shrink

 

Overview


VMWare does not support shrinking disks on ESX server. However, you can shrink files using the Digital Dump command. Doing so destroys the partition space at the end of the disk, but this is usually acceptable when you have more than one partition. To issue the 'dd' command, you need two find out two things.

  • Find the disk's block size
  • Calculate the number of blocks in your disk file.
The block size helps you calculate the end size you want. The file is the vmdk file you want to resize.

Block Size


To find the block size on a vmfs device; type the following

vmkfstools /vmfs/volumes/SAN5 -P

On of the lines it returns should look like this

Capacity 466540822528 (444928 file blocks * 1048576), 278777561088 (265863 blocks) avail

This shows our block size as 1048576 bytes. Now that we know that, we can calculate how many blocks we have in our source file.

File Size


Files in Unix are listed in bytes. Simply divide by the block size to get the number of blocks. For instance, a directory list shows the file OLD-flat.vmdk as being 73014444032 bytes.
[root@vm1 TEST]# ll
-rw - - - - - - - 1 root root 73014444032 Apr 17 03:06 OLD-flat.vmdk

Divide 73014444032 by the block size we determined earlier, 1048576, and we know that the file is made of 69632 blocks. If we want to cut the file in half, we simply use half that number when we 'dd' it, as follows;

dd bs=1048576 if=TEST-flat.vmdk of=NEW-flat.vmdk count=34816

It's best to remove what ever partition is on the end of the drive before you chop it off. After issuing the command you must rename the new file to match the old one, and then recreate the last partition from inside the virtual machine.

Comments