Shrink a VM hardisk size

3

I have a giant VM (Ubuntu 14, ext4) which takes about 150GB. I've did some cleaning up and I'd like to shrink this VM to take about 60GB.

I've used gparted live CD to redistribute the partitions, and now there's 90GB of unallocated space in the drive, and 60GB of actual partitions.

The VM is hosted on VMWare workstation 12 on Windows 10. There used to be a "Shrink" button somewhere in the VMWare Workstation interface, but there isn't now.

I've tried compacting the HD using vmware tools, but that only freed like 10GB.

I've searched everywhere but all I can find is compacting the unused space. I don't want the VM to think it has 150GB. I'd like to make the virtual disks smaller.

How do I resize the virtual hard disks size?

Nitay

Posted 2016-05-23T18:17:04.853

Reputation: 183

Answers

2

Apparently there is currently no way to properly resize a virtual hard disk, only to expand it. So what I did was basically to repartition the virtual hard drive (from inside the VM) so the VM will use only the space I allow it to. Then I wiped the reserve space, and ran vdiskmanager as figgycity50 suggested.

In steps:

  1. Repartition the virtual HD: Download and run gparted live cd on the VM, resize all the partitions you need so all the space you which to subtract from this VM is unallocated. Now create a new partition on all the space you've just cleared.

  2. Wipe the empty space: Now mark the new empty partition as unused space - Wipe it to zeros. This command line should do the trick (in the host):

    dd if=/dev/zero of=/media/user/{GUID} seek=10000 obs=512 count=20000 bs=512

    replace /media/user/{GUID} with the path of the partition you've created in step 1.

  3. Shrink the virtual HD: Like figgycity50 answered, use this command line on the virtual disk (from the host):

    "C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe" -k yourdiskfile.vmdk

  4. Make sure the VM doesn't use the space: Run gparted again to delete the empty partition. This way the VM will not have access to the space you've just cleared, and the virtual HD will not grow beyond what you want.

Hope this helps future shrinkers.

(Used this as reference)

Nitay

Posted 2016-05-23T18:17:04.853

Reputation: 183

1

This article provides instructions on how to use the vmware-vdiskmanager tool to, among other things, shrink the disk with the -k <diskname> argument.

The tool should be included with VMWare Workstation in the C:\Program Files\VMware\VMware Workstation directory provided you have not changed the install directory. Therefore, you could open your virtual machine's folder on the host, shift-right click and click "Open command window here", then type:

"C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe" -k yourdiskfile.vmdk

Please note that for whatever reason, this tool does not work if the VM has any snapshots according to the documentation.

figgycity50

Posted 2016-05-23T18:17:04.853

Reputation: 141

If I understood correctly, -k <diskname> doesn't resize the HD, but only shrinks it to it's minimum size. Not really changing the actual maximum size of the HD, like the 'compact` option. I'm running it now anyway, I'll let you know how it went. – Nitay – 2016-05-24T08:07:15.877

The shrink was completed but I'm sorry to say that it didn't change the VM disk size... – Nitay – 2016-05-24T09:30:31.513