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:
- Open the Group Policy Management Editor.
- Access Policies > Administrative Templates: Policy definitions (ADMX files) > Citrix Components > Profile Management > Profile Container settings.
- Double-click the VHD disk compaction policy.
- In the policy window that appears, select Enabled, and then click OK.
The configuration precedence is as follows:
- If this setting isn’t configured using a GPO, Studio, or Workspace Environment Management (WEM), the value from the .ini file is used.
- 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:
- Open the Group Policy Management Editor.
- Access Policies > Administrative Templates: Policy definitions (ADMX files) > Citrix Components > Profile Management > Advanced settings.
- To change the free space ratio to trigger the compaction, follow these steps:
- Double-click the Free space ratio to trigger VHD disk compaction policy.
- In the policy window that appears, select Enabled, enter a percentage as needed, and then click OK.
- To change the number of logoffs (since the last compact) to trigger the compaction, follow these steps:
- Double-click the Number of logoffs to trigger VHD disk compaction policy.
- In the policy window that appears, select Enabled, enter a value as needed, and then click OK.
- To disable defragmentation for VHD disk compaction, follow these steps:
- Double-click the Disable defragmentation for VHD disk compaction policy.
- 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
- If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
- If this setting isn’t configured anywhere, the default value 20 (%) is used.
- Number of logoffs to trigger VHD disk compaction
- If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
- If this setting isn’t configured anywhere, the default value 5 is used.
- Disable defragmentation for VHD disk compaction
- If this setting isn’t configured using a GPO, Studio, or WEM, the value from the .ini file is used.
- 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:
- Ensure that the VHD file is attached to the operating system.
-
Run this PowerShell command as an administrator:
Get-WmiObject -Class MSFT_Partition -Namespace ROOT\Microsoft\Windows\Storage
All partitions of your current desktop appear.
- Locate the partition corresponding to the VHD file, and then get the required minimum size (
SizeMin
) using the GetSupportedSize method.