For a couple years now, Citrix App Layering has supported the ability to provide user persistence on non-persistent VDI platforms through user layer technology. The user layer is implemented by creating a VHD file on a share. The VHD file is mounted just prior to logon, and the App Layering filter drivers are used to direct changes made to the registry or file system to and from the VHD. This technology includes some very interesting file and registry virtualization.

I know many customers have taken advantage of user layers for use cases that require more persistence than can be had using a persona management solution like Citrix Profile Management. User layers enable users to store things like OST files, user-installed apps, and Microsoft OneDrive caches in the user layer for reuse on non-persistent, pooled desktops. Citrix has also introduced a replacement technology for the Personal vDisk called the User Personalization Layer (UPL). This is basically the same as the full user layer but without App Layering. It is a feature of the VDA installer. Most of this blog post applies to both of these technologies.

One thing that I have noticed about customers who use user layers is that they generally end up storing large amounts of file data in the user layer. I often see questions in the discussion groups about how to increase the size of user layers to much higher amounts than the default 10 GB per user layer. Also, it is not a great idea to just assign 50 GB per user because the way NTFS works, it will always prefer to use new unused blocks rather than using deleted blocks. So, the 50 GB will fill up with a lot of real files and even more deleted files until the entire allocated space is used up. The only way to keep it efficient is to put pressure on the file system to actually use deleted blocks.

The size and location of a user layer or UPL when it is created is governed by the following logic:

  1. Location varies depending on whether a user layer or UPL is used:
    1. User layer locations are defined by AD groups in the App Layering appliance. If a user is assigned to more than one group, these groups have an associated priority and the user layer will be created in the location with the higher priority. Once created, the user layer is never moved. If you change the location defined on the appliance, you must move already created user layers to that location and ensure appropriate permissions are assigned.
    2. UPL is defined by Citrix Studio policy
  2. If there is a disk quota on the user layer or the UPL share for a user, that setting will govern the size of the VHD unless this feature is disabled in the registry.
  3. If there is no disk quota or disk quota sizing is disabled, the user layer or UPL size is determined by the following registry key (DWORD): HKLM\SOFTWARE\Unidesk\ULayer\DefaultUserLayerSizeInGb. This key is created when an image is published. It can be changed using a GPO or GPP.
  4. If neither of those options are found, the default value of 10 GB is used.

In App Layering version 2003, our engineers introduced a great new feature that applies to user layers and that  will be added to User Personalization Layers in upcoming releases. If a user layer size was increased either as a quota or via the registry, the VHD will automatically be expanded during the next user logon. That change makes it easy to upgrade some or all of an organization’s user layers or UPLs. To use different classes of service for different machines, it would work best to configure a different OU for each class, then change the GPP that defines DefaultUserLayerSizeInGb for each OU.

To change the setting by user, applying a user quota would be the easiest method if your share allows for that.

But what if that option is not available to you?

You can increase the size of a single VHD in one of two ways. If you have Hyper-V servers available or want to set one up for this purpose, you can use a PowerShell CMDLET called Resize-VHD. The CMDLET would be run like this to expand the disk to 20 GB:

Resize-VHD -Path \\Server\Share\Users\Domain_Username\4968002_Win10-1909\username.vhd -SizeBytes 20GB

If you don’t have a Hyper-V server around, you can do the same thing with Diskpart, which is great because it is on every Windows system. The basic commands for Diskpart are as follows (also to expand the disk to 20 GB):

select vdisk file=\\Server\Share\Users\Domain_Username\4968002_Win10-1909\username.vhd
expand vDisk maximum=20480 (this is 1024 X 20)
attach vDisk
list volume (note the volume number)
select volume 2 (based on the volume found above, this will mount the disk and open it)
extend (This will increase the size)
detach vdisk (This will close the disk and detach it from your computer)
detail vdisk (will show the new details)

It’s actually pretty simple, although there are a lot of steps. The vdisk must not be in use to run these commands.

Please note, if you use “list vdisks” you will always see a listing for the vdisks that were previously mounted until the next time you reboot your computer; but if you use the detach vdisk, they will no longer be attached.

User Layer Repair Utility

Back in January 2020, I wrote a utility to make managing the process of repairing user layers easier. We have a great feature included with full user layers that allows an admin to remove any files or registry settings installed into an application layer from a user’s user layer. This is handy if a user has installed an application that the admin later wants to deploy as an app layer. It also allows admins to clean out files and settings from the user layer by creating an app layer just for that purpose.

The utility is called the User Layer Repair Utility and you can read about it here. Every time I saw a user ask how they could increase the user layer size for just one user (or a few users), I thought that process would be easy to add to my repair utility. I finally had a chance to do this.

If you open the utility now, there is a new tab called “Expand”.


To use it, the utility should be run “as administrator” or there will be constant prompts to elevate. Then, follow these steps:

  1. Click Get OS Layers and the utility will query the app layering appliance to get a list of OS layers.
  2. Choose the OS layer for the user layers to be expanded
  3. Select the desired layers.
    1. The list can be filtered by searching
    2. Select All and UnSelect All can be used on the list
  4. To get the current size of the selected user layers and to see if they are locked, click “Get User Layers Size” and it will be added to the table as shown in the red box.
  5. Enter the new size of the User Layers
  6. Click Expand Selected User Layer VHD Size
    1. The disks will be expanded and the new size or any errors will be listed in the blue box as shown above

Logs

Two log files will be created each time the utility is run. They will be created under the folder where you install the utility in a Logs\Expand folder. The logs are named using ExpandLog-DateTime.txt and ExpandLog-DateTime-Transcript.txt. The transcript file will include all the log information plus any PowerShell errors encountered.

Here’s an example of the log:

09-10-2020-10-25-20-AM – ======================================================
09-10-2020-10-25-20-AM – Expanding User Layer [\\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd] to [52 GB]
09-10-2020-10-25-20-AM – ======================================================
09-10-2020-10-25-21-AM – Current size for disk \\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd is 50
09-10-2020-10-25-21-AM – Expanding Disk [\\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd]
09-10-2020-10-25-23-AM – Getting Disk Volume
09-10-2020-10-25-28-AM – The volume added is [2]
09-10-2020-10-25-28-AM – Extending the disk size for volume [2]
09-10-2020-10-25-30-AM – Getting new disk size
09-10-2020-10-25-32-AM – New size for disk \\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd is 52
09-10-2020-10-25-32-AM – Disk [\\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd] was Successfully updated to 52 GB
09-10-2020-10-25-32-AM – Detaching vDisk \\zdc2\unidesk\Users\DOMA_fletl\4968002_Win10-1909\fletl.vhd
09-10-2020-10-25-33-AM – Cleaning Up Text Files DetachvDisk.TXT SizevDisk.TXT ExtendVolume.TXT ListVolume.TXT ExpandDisk.TXT
09-10-2020-10-25-33-AM – Script complete for User Layer [\\zdc2\unidesk\Users\ZYLOWSKI_fletl\4968002_Win10-1909\fletl.vhd]
09-10-2020-10-25-33-AM – Result:Success

Setting Up the Utility

To set up the utility, download it and unblock the zip file. Then extract it to a folder and run the hta file as admin. I include a simple reg file in the script folder that will allow you to right click on an hta file and choose run as administrator. You will see the user interface. Click on the Setup tab and follow the directions below:

  1. First enter your Citrix App Layering appliance FQDN or IP address.
  2. Type the root password for the appliance or choose to be prompted with every use. If the password is saved, it will be encrypted. However, the file can be unencrypted by anyone with access to the utility hta file. Click Save to save these settings for 1 and 2.
  3. Enter the network share defined in the system settings on the appliance (for example, \\server\share). Do not enter the entire path to the user layer folders; the utility will add the folders past the share.
  4. Enter the User Layers Share (for example, \\server\share). Do not enter the entire path to the user layers; the utility will add the folders past the share. Click Save to save the settings for 3 and 4. Because you can only enter one User Layer Share, if you use more than one User Layer Share, you will need a version of the utility created for each User Layer Share you want to manage. Just copy the utility into a different folder and set it up for the different share.
  5. This feature is not required to expand a user layer; it is used for the repair file functionality. See this blog post for more details.

PowerShell

The user interface for the utility is written as a simple hta. All the work for the utility is performed using PowerShell scripts. These scripts are in the PowerShell folder. The new ones added for User Layer Expanding are called:

  • GetUserLayers.ps1
  • GetULSize.ps1
  • ExpandUL.ps1

Each script is explained below:

GetUserLayers.ps1

This script uses the following command to get a list of user layers.

$AllFiles = Get-ChildItem -path “$UserLayerShare\Users” -Depth 2 -Filter *.vhd

If a user layer is in the path that’s for the selected OS Layer ID, then that user layer is written to a text file to present in the utility UI. As seen below, the OS layer ID is part of the path to a user layer for the user.

GetULSize.ps1

This script uses diskpart to attach the vdisk and get its current size. The script writes diskpart commands into text files that are then run using:

DISKPART /S TextFile.txt

As an example, the code to get the disk details is shown below:

#Lets see how big it
NEW-ITEM –name SizevDisk.TXT –itemtype file –force | OUT-NULL
ADD-CONTENT –path SizevDisk.TXT “Select vdisk FILE=$disk”
ADD-CONTENT –path SizevDisk.TXT “Detail vDisk”
ADD-CONTENT –path SizevDisk.TXT “exit”
$DetailVDISK=(DISKPART /S SizevDisk.TXT)
$DetailVDISK | Out-File -LiteralPath DiskDetail.txt -Encoding ASCII
$SizeData = $DetailVDISK
foreach ($line in $SizeData)
{
    $arrLine = $line -split ‘\s+’
    if ([string]::IsNullorEmpty($arrLine[1])){continue}
    if ($arrLine[0] -eq “Virtual”)
       {
            $NewDiskSize = $arrLine[2]
           Write-Host “New size for disk $disk is $NewDiskSize”
}
}

ExpandUL.ps1

This script uses similar commands as the last, just more of them, and also creates a log where the others do not. The general flow of the script is as follows:

  1. Define the log files
  2. Start the log transcript
  3. Select the disk and get the current disk size
  4. Make sure the new disk size is larger than the current
    1. If not, clean up and exit the script
  5. Write the current size to a file called CurrentDiskSize.txt for use in the UI
  6. Expand the disk
  7. Get the disk volume number
  8. Select the volume and extend the disk
  9. Check the new disk size
  10. Detach the disk
  11. Write the new size out to NewDiskSize.txt
  12. Delete all the text files except those used by the UI

I encourage everyone to take a look at the scripts and learn how they work.

Don’t Forget!

This is totally new functionality added to the utility. I have tested it in my lab, but it has not been tested by customers at the of publication. Please start by using this in your lab. Treat it like any script you would develop yourself and test it well before adding it to your production environment.

Remember this is to be used at your own discretion and is not supported by Citrix. You can download the utility at the bottom of the original blog post and report any issues in the comments.


This software application is provided to you “as is” with no representations, warranties or conditions of any kind. You may use and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the software application may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the software application fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the software application. In no event should the code be used to support of ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SOFTWARE APPLICATION, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the code.


Citrix Tech Bytes – Created by Citrix Experts, made for Citrix Technologists! Learn from passionate Citrix Experts and gain technical insights into the latest Citrix Technologies.

Click here for more Tech Bytes and subscribe.

Want specific Tech Bytes? Let us know! tech-content-feedback@citrix.com.