govmomi icon indicating copy to clipboard operation
govmomi copied to clipboard

govc: datastore.disk.shrink doesn't appear to thin disk size

Open HeroCC opened this issue 4 years ago • 9 comments

Hello! I'm trying to thin a VMDK using govc datastore.disk.shrink. However, once I run the command on the VMDK, it finishes almost immediately, and the space doesn't appear to change. I see the task execute in vSphere, but the VMDK is still as large as before. Migrating the VM between datastores from vCenter works fine however, so I believe I'm not zeroing the disk incorrectly. Is there something wrong with what I'm doing? The only other way to thin I know of is to use vmkfstools --punchzero on the host, but I don't have SSH access run it.

$ govc datastore.disk.shrink -ds=/MyDc/datastore/DataStoreCluster/Datastore123 NAME-OF-VM/NAME-OF-VM.vmdk
[26-06-20 11:34:06] Shrinking [Datastore123] NAME-OF-VM/NAME-OF-VM.vmdk...OK

HeroCC avatar Jun 26 '20 15:06 HeroCC

ShrinkVirtualDisk_Task doc says:

Shrink a sparse virtual disk.

Which disk type are you trying to shrink?

dougm avatar Jun 26 '20 17:06 dougm

It's a thin virtual disk -- is that supported? Sorry, I'm not very clear on the distinguishment between a sparse and a thin disk. I don't recall ever seeing a 'sparse' option when provisioning but then again I'm no expert. Running vSphere 6.5.0 if it makes a difference.

$ govc datastore.disk.info -ds=/MyDc/datastore/DataStoreCluster/Datastore123 NAME-OF-VM/NAME-OF-VM.vmdk
Name:      NAME-OF-VM/NAME-OF-VM.vmdk
  Type:    thin
  Parent:

HeroCC avatar Jun 26 '20 17:06 HeroCC

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Mar 24 '21 01:03 github-actions[bot]

/remove-lifecycle stale

Isn't explicitly needed by my workflow anymore, but still deserves a peek IMO if there are cycles to spare

HeroCC avatar Mar 24 '21 01:03 HeroCC

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Mark as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Jun 23 '21 01:06 github-actions[bot]

Is there a way to disable the inactivity bot? Would rather not close this as it isn't resolved, but if the bot keeps pestering & the maintainers want to close this so be it.

/remove-lifecycle stale

HeroCC avatar Jun 27 '21 21:06 HeroCC

@embano1 any pointers? Other projects such as Kubernetes have a label (e.g. lifecycle/frozen) that can be added for this.

Regarding the issue itself.. To shrink the size of the vmdk, you probably need to zero out unused disk space from inside the VM. Have seen it done in VMs built by packer, example here: https://github.com/boxcutter/ubuntu/blob/aa1bba14aeafa54a49d41787cb970bb2127c6b67/script/cleanup.sh#L55 While the packer scripts are meant to shrink the exported vmdk, I assume this approach would also apply to ShrinkVirtualDisk_Task, but have yet to try myself.

dougm avatar Jun 28 '21 18:06 dougm

I believe even with zeroing out the free space, the shrink command wasn't restoring the space, which is why we migrate back and forth between a datastore before the using the image.

HeroCC avatar Jun 28 '21 18:06 HeroCC

@embano1 any pointers? Other projects such as Kubernetes have a label (e.g. lifecycle/frozen) that can be added for this.

That is exactly the label (lifecycle/frozen) the bot will use to determine whether to skip stale issue/PR.

embano1 avatar Jun 29 '21 06:06 embano1