2

I want to perform Linux fstrim or Windows degrag retrim on a file system within VM to shrink VMware vSphere thin disks. However this should be performed only if there is no snapshot present as fstrim-ing a snapshoted file system will cause it to grow to full size on VMware vSphere thin disks.

Limitation: VM guest OS does not have access to vSphere/vCenter management interfaces.

Is there a way to detect presence of snapshot from within VM guest OS - for example via via VMware tools?

Don Zoomik
  • 1,533
  • 9
  • 14

1 Answers1

0

Q: Is there a way to detect presence of snapshot from within VM guest OS*

A: not that I know. However, you can use the sg_vpd to check if UNMAP is supported. For example:

# sg_vpd /dev/sdb -p lbpv
Logical block provisioning VPD page (SBC):
 Unmap command supported (LBPU): 1
 Write same (16) with unmap bit supported (LBWS): 0
 Write same (10) with unmap bit supported (LBWS10): 0
 Logical block provisioning read zeros (LBPRZ): 1
 Anchored LBAs supported (ANC_SUP): 0
 Threshold exponent: 1
 Descriptor present (DP): 0
 Provisioning type: 2

Some explanations:

  • provision type is 2, so you are running from a "thin" disk;
  • unmap command supported (LBPU) is 1, so your disk claims to support UNMAP/TRIM

That said, issuing fstrim on a snapshotted disk should not have any adverse effect. On VMWare <= 6.5, it should have no effect at all, while VMWare >= 6.7 seems to support TRIM even when using snapshots.

EDIT: as detailed in the comments below, the problem is related to original disk inflation during/after "trimmed" snapshot consolidation. As shown here, this side effect seems not avoidable even on latest VMWare 6.7

shodanshok
  • 47,711
  • 7
  • 111
  • 180
  • The second link is only half-true. It will trim data written during snapshot. However if you trim data written before snapshot (or never written, during formating new file system or full fstrim), it will will cause base VMDK to grow with zero-filled data. See here https://kb.vmware.com/s/article/56608 - while it's about Windows, it's the same for Linux and any other UNMAP capable guest. This problem exists to this day (6.7 U3). See this thread https://communities.vmware.com/thread/610062 as well. the last post is mine, 100% reproducable. – Don Zoomik Sep 30 '19 at 20:18
  • @DonZoomik ah, I see, you are speaking about *consolidating* trimmed snapshots. Yes, this can inflate the original disk size during/after consolidation. After reading the VMWare post you linked, I don't think you can avoid that. I'll update my answer to reflect that. You should try `sg_vpd` to check if it can help you detecting the presence of an active snapshot. – shodanshok Sep 30 '19 at 20:25
  • Well snapshots need to be consolidated eventually... sg_vpd will always show that UNMAP support is present so I don't think I can rely on that. – Don Zoomik Sep 30 '19 at 20:35