VMware Communities
jaimea
Contributor
Contributor

Shrinking a preallocated, single file disk

Hello,

I'm posting this as I just successfully managed to do so, and really failed to find much help in the forums or anywhere before.

vmware-vdiskmanager was not of help - I tried many things, steps that worked are:

- 1) in the guest OS, shrink the partition, so there's unused space at the end. This is the space we aim to remove from the disk. Let's say we manage to reduce the useful disk to 150 Gb, with some waste above.

- 2) shut down the guest.

- 3) using some tool (there are many, I used the "truncate" linux command) truncate the disk file (whatever-flat.vmdk) to a bit more (just in case :-), I truncated to 152Gb)

- 4) in VMware workstation, settings for the VM:

- 4.a) remove the hard disk we're trying to shrink

- 4.b) add a new one, same type, just size the same as the truncated size (so 152Gb) and a new name (whatever-shrunk.vmdk); this will create both this file and the big, 152Gb long whatever-shrunk-flat.vmdk.

- 4.c) overwrite the newly created whatever-shrunk-flat.vmdk with the one we truncated in step 3 (with our data). In steps, delete the new file (delete whatever-shrunk-flat.vmdk), then rename the one with our data (ren whatever-flat.vmdk whatever-shrunk-flat.vmdk)

And that's it. Of course a backup is advised before!

Hope this helps someone.

jaime

Tags (3)
0 Kudos
0 Replies