Forum Discussion
AxelGlzs31
Jan 29, 2025Copper Contributor
AVD image - No paging file ?
Hello, While optimizing my template for AVD, I noticed that the Virtual Memory settings were configured to ‘No Paging File.’ I was wondering if this is expected behavior? Do you have any recommendat...
- Feb 20, 2025
For those coming across this post, I used a PowerShell script executed via ‘Custom configuration script’ during the creation of machines in the pool. This is the only way I found to keep the paging file enabled.
URL script HERE
AxelGlzs31
Feb 03, 2025Copper Contributor
Hello,
Thank you for your response. I have already enabled the paging file on the C drive in automatic mode, but after running sysprep, capturing my image, and deploying new machines in the pool, the paging file configuration is not retained, and my virtual desktops end up without a paging file. I would like this setting to persist after sysprep. Any idea how to achieve this?
aasimtek
Feb 03, 2025Copper Contributor
When using Azure Virtual Desktop (AVD) or any virtual desktop environment, the paging file (pagefile.sys) configuration is often lost after running sysprep and deploying new machines. This happens because sysprep generalizes the system, resetting certain configurations, including the paging file settings. To ensure the paging file configuration persists after sysprep, you need to configure it in a way that survives the sysprep process.
Here’s how you can achieve this:
Solution: Configure the Paging File via a Custom Script or Unattend.xml
Option 1: Use an Unattend.xml File
The unattend.xml file is an answer file used during the Windows setup process to automate configurations. You can configure the paging file settings in this file so that they are applied after sysprep.
- Create or Modify the Unattend.xml File:
- If you don’t already have an unattend.xml file, create one.
- Add the following section to configure the paging file:
- xml<settings pass="specialize"> <component name="Microsoft-Windows-SystemRestore-Main" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <DisableSR>0</DisableSR> </component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <PageFile> <Size>2048</Size> <Path>%SystemDrive%\pagefile.sys</Path> </PageFile> </component> </settings>Run HTML
- Copy
- Adjust the <Size> value to your desired paging file size (in MB). Use 0 for system-managed size.
- Place the Unattend.xml File in the Correct Location:
- Save the unattend.xml file in the %WINDIR%\System32\Sysprep directory on your image.
- Run Sysprep with the Unattend.xml File:
- When running sysprep, specify the unattend.xml file using the /unattend flag:
- cmdsysprep /generalize /oobe /shutdown /unattend:unattend.xml
- Copy
- Capture and Deploy the Image:
- Capture the image and deploy it to your AVD pool. The paging file configuration should now persist.
Option 2: Use a Post-Deployment Script
If you prefer not to use an unattend.xml file, you can configure the paging file via a script that runs after deployment.
- Create a PowerShell Script:
- Create a PowerShell script to configure the paging file. For example:
- powershell$pageFileSetting = Get-WmiObject -Query "SELECT * FROM Win32_PageFileSetting WHERE Name='C:\\pagefile.sys'" if (-not $pageFileSetting) { $pageFileSetting = Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{Name="C:\\pagefile.sys"; InitialSize=2048; MaximumSize=4096} } else { $pageFileSetting.InitialSize = 2048 $pageFileSetting.MaximumSize = 4096 $pageFileSetting.Put() }
- Copy
- Adjust the InitialSize and MaximumSize values as needed.
- Run the Script During Deployment:
- Add the script to your deployment process so it runs after the virtual machines are provisioned. For example:
- Use Azure VM extensions to run the script.
- Include the script in your AVD host pool setup process.
- Add the script to your deployment process so it runs after the virtual machines are provisioned. For example:
Option 3: Configure via Group Policy (GPO)
If you are managing AVD with Active Directory or Azure AD, you can use Group Policy to enforce the paging file configuration.
- Create a GPO:
- Open the Group Policy Management Console (GPMC).
- Create a new GPO and link it to the appropriate Organizational Unit (OU) containing your AVD machines.
- Configure the Paging File Setting:
- Navigate to:
- CopyComputer Configuration > Administrative Templates > System > Memory Management
- Enable the policy "Configure paging file size" and specify the desired size.
- Apply the GPO:
- Ensure the GPO is applied to your AVD machines. The paging file configuration will be enforced after the machines boot up.
Why This Happens
- Sysprep resets system configurations, including the paging file settings, to ensure a clean state for deployment.
- The paging file configuration is stored in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management. Sysprep does not retain these settings by default.
Best Practices
- Test your solution in a non-production environment before deploying it to your AVD pool.
- Use the unattend.xml method if you want the paging file configuration to be applied during the initial setup.
- Use a post-deployment script or GPO if you need more flexibility or want to manage the configuration dynamically.
By following one of these methods, you can ensure that the paging file configuration persists after sysprep and is applied to your AVD machines.
- AxelGlzs31Feb 04, 2025Copper Contributor
Thank you, but ChatGPT gave me the answers as well. I would have preferred someone with real hands-on experience.