Profile Management

Enable VHD disk compaction

VHD disk compaction is a process that reduces the size of a VHD file by removing empty space and combining the data within the file. With the Enable VHD disk compaction policy, you can enable VHD disk compaction for Profile Management. VHD files created by Profile Management are automatically compacted on user logoff when certain conditions are met, thus saving space on central or cloud storage.

This article provides guidance on enabling VHD disk compaction and adjusting the default compaction settings and behavior.

Overview

VHDX disk compaction applies to the following VHDX files in Profile Management:

With the Enable VHD disk compaction policy enabled, a VHDX file is automatically compacted on user logoff when one of the following conditions is met:

  • The free space ratio of the VHD file exceeds a specified value (by default, 20%)

    Free space ratio = (current VHD file size – required minimum VHD file size*) ÷ current VHD file size

    * Obtained using the GetSupportedSize method of the MSFT_Partition class from the Microsoft Windows operating system. See Get the required minimum size for a VHD file for details.

  • The number of logoffs since the last compaction reaches a specified value (by default, 5)

    Note:

    When a user logs off, the process of compacting VHD disks occurs in parallel with the logoff process. Thus, disk compaction does not prolong logoff time. If the VHD disk compaction process is not complete when the user attempts to log back on, Profile Management prevents the logon attempt.

Depending on your needs and the resources available, you can adjust those default settings using the following policies in Advanced settings:

  • Free space ratio to trigger VHD disk compaction
  • Number of logoffs to trigger VHD disk compaction

When VHD disk compaction is enabled, the VHD disk file is first defragmented using the Windows built-in defrag tool, and then compacted. VHD disk defragmentation produces better compaction results while disabling it can save system resources. If needed, you can disable defragmentation using the following policy in Advanced settings:

  • Disable defragmentation for VHD disk compaction

Enable VHD disk compaction

With VHD disk compaction enabled, you can save storage space consumed by profile container, OneDrive container, and folder mirroring container.

To enable VHD disk compaction using a GPO, follow these steps:

  1. Open the Group Policy Management Editor.
  2. Access Policies > Administrative Templates: Policy definitions (ADMX files) > Citrix Components > Profile Management > Profile Container settings.
  3. Double-click the VHD disk compaction policy.
  4. In the policy window that appears, select Enabled, and then click OK.

The configuration precedence is as follows:

  1. If this setting isn’t configured using a GPO, Studio, or Workspace Environment Management (WEM), the value from the .ini file is used.
  2. If this setting isn’t configured anywhere, the feature is disabled.

Change the compaction settings and behavior

Enabling VHD disk compaction can save storage space, but it also consumes system I/O and network bandwidth. You can monitor the system and network resource usage during the compaction process to determine whether to adjust the following settings:

  • Free space ratio to trigger VHD disk compaction
  • Number of logoffs to trigger VHD disk compaction
  • Disable defragmentation for VHD disk compaction

To change the default compaction settings and behavior using a GPO, follow these steps:

  1. Open the Group Policy Management Editor.
  2. Access Policies > Administrative Templates: Policy definitions (ADMX files) > Citrix Components > Profile Management > Advanced settings.
  3. To change the free space ratio to trigger the compaction, follow these steps:
    1. Double-click the Free space ratio to trigger VHD disk compaction policy.
    2. In the policy window that appears, select Enabled, enter a percentage as needed, and then click OK.
  4. To change the number of logoffs (since the last compact) to trigger the compaction, follow these steps:
    1. Double-click the Number of logoffs to trigger VHD disk compaction policy.
    2. In the policy window that appears, select Enabled, enter a value as needed, and then click OK.
  5. To disable defragmentation for VHD disk compaction, follow these steps:
    1. Double-click the Disable defragmentation for VHD disk compaction policy.
    2. In the policy window that appears, select Enabled, and then click OK.

The configuration precedence is as follows:

  • Free space ratio to trigger VHD disk compaction
    1. If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
    2. If this setting isn’t configured anywhere, the default value 20 (%) is used.
  • Number of logoffs to trigger VHD disk compaction
    1. If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
    2. If this setting isn’t configured anywhere, the default value 5 is used.
  • Disable defragmentation for VHD disk compaction
    1. If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
    2. If this setting isn’t configured anywhere, defragmentation is enabled by default.

Get the required minimum size for a VHD file

Detailed steps are as follows:

  1. Ensure that the VHD file is attached to the operating system.
  2. Run this PowerShell command as an administrator:

    Get-WmiObject -Class MSFT_Partition -Namespace ROOT\Microsoft\Windows\Storage

    All partitions of your current desktop appear.

  3. Locate the partition corresponding to the VHD file, and then get the required minimum size (SizeMin) using the GetSupportedSize method.
Enable VHD disk compaction