11

EHLO everyone! My first post on the StackOverflow network :)

We're running some ESXi 5.0/vCenter infrastructure to host mainly Debian 6/amd64 guest systems with ext3 partitions and open-vm-tools compiled from source per debian bug 471784.

Got an issue that is seen being raised all around the internet, but without a conclusive answer given anywhere.

When trying to shrink a thin-provisioned disk in independent-persistent mode, with no snapshots, parents, clones whatsoever, I consistently get the following error:

root@linux64:~# vmware-toolbox-cmd disk list
Shrink disk is disabled for this virtual machine.

Shrinking is disabled for linked clones, parents of linked clones,
pre-allocated disks, snapshots, or due to other factors.
See the User's manual for more information.

(By the way, what are the "other factors", and which of the ton of white papers and technical manuals is the User's manual?:)

I know that I can stuff the partitions with zeros (in fact, I do use shred -fuzn0 when deleting large files) then shut down the guest in question and use various methods like vmkfstools, cloning or vMotioning disks around in thin-provision mode, etc, but all of them either incur the downtime penalty for the guest being shirnked, or result in an unwarranted moving of data between datastores and/or hosts.


And the answer is: No shrinking under ESX/ESXi (as of version 5).

The documentation reads:

IMPORTANT Shrinking disks is not allowed under the following circumstances:

  1. The virtual machine is hosted on an ESX/ESXi server. ESX/ESXi Server can shrink the size of a virtual disk only when a virtual machine is exported. The space occupied by the virtual disk on the ESX/ESXi server, however, does not change.

  2. The virtual machine has a Mac guest operating system.

  3. You preallocated all the disk space to the virtual disk when you created it.

  4. The virtual machine contains a snapshot.

  5. The virtual machine is a linked clone or the parent of a linked clone.

  6. The virtual disk is an independent disk in nonpersistent mode.

  7. The file system is a journaling file system, such as an ext4, xfs, or jfs file system.

No wonder there is an option to shrink in VMWare Workstation but not in vSphere client connected to an ESXi or vCenter instance.

  • 2
    could you show a value of the isolation.tools.diskShrink.disable key which can be found on the vmx file? – cikuraku Jun 13 '12 at 9:28
  • 1
    It wasn't there. Adding isolation.tools.diskShrink.disable="false" didn't change anything. – NekojiruSou Jun 13 '12 at 9:43
3

http://www.vmware.com/pdf/vmware-tools-cli.pdf Page 13 :

Shrinking disks is not allowed under the following circumstances:

The virtual machine is hosted on an ESX/ESXi server. ESX/ESXi Server can shrink the size of a virtual disk only when a virtual machine is exported. The space occupied by the virtual disk on the ESX/ESXi server, however, does not change.

18

Actually, there is a way to shrink a VM on ESXi, although you need to shut down the VM for it. Here's how:

  1. Zero all unused space inside the VM:

    dd if=/dev/zero bs=1048576 of=/zero ; sync ; rm /zero

  2. Do the same with other mount points, swap partitions, etc.

  3. Shut down the VM.

  4. SSH to ESXi, and issue this command:

    vmkfstools -K /vmfs/volumes/volumename/vmname/vmname.vmdk

This will take some time... vmkfstools "punches holes" inside your VMDK, e.g. deallocates all blocks that are filled with zeros, effectively shrinking your VMDK.

  • 6
    For Windows, you can grab a copy of Virtual Server 2005, extract the Precompact.iso file from it, it contains a Procompact.exe program that will zero all the unused disk pace in Windows. – Chris S Aug 1 '13 at 13:39
  • vmkfstools are not working when the VM is on a NFS storage. – Sven 31415 Nov 13 '19 at 10:59
0

The only way to shrink a VMDK in vSphere ESXi would be to export or to migrate/Storage vMotion to another datastore. I do this a lot with live servers that can handle a migration (not SQL or Exchange). A previous server admin built all VMs with Thick Provisioned disks. I migrate the VMs from one datastore to another and change the VMDK to thin-provisioned.

You can also do the vmkfstools if the server is offline.

-1

Shrinking disks is possible on ESXi.

  1. Find the large file and delete them.

    find / -type f -size +50M

  2. Defragment (no need to un/remount anything). Ignore any errors. Some files like symlinks and device files can't be defragmented.

    sudo e4defrag /

  3. Zero-fill all unused space so VMware knows it's indeed unused:

    dd if=/dev/zero of=wipefile bs=1M; sync; rm wipefile

  4. Run the shrink operation: If 4 fails, proceed to 5.

    sudo vmware-toolbox-cmd disk shrinkonly

  5. Reboot the linux system with try option and edit the partition table with gparted. Shrink the root file system and delete & move swap partition near to root partition.

  6. SSH to ESXi, and issue this command:

    vmkfstools -K /vmfs/volumes/volumename/vmname/vmname.vmdk

  7. We need to edit the *.vmdk file. After the letters RW, defines the size of the VMware virtual disk (VMDK)

    *40 GB = 40 * 1024 * 1024 * 1024 / 512 = 83886080*

  8. Migrate it to another datastore to reflect the new size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.