Configuring Hibernation for AVD Personal Host Pools and Setting Up Autoscaling and GPO Policies to Optimize Its Use:

 1. What is Hibernation?

When you hibernate a session host VM, it turns off but saves your work so you can continue later. You don’t pay for running the machine while it’s hibernated, just for the storage and networking. When you start the VM again, you can quickly pick up right where you left off. Hibernation can be enabled for session host VMs deployed in personal host pools.

 2. Use Case:

If a customer wants a Personal Host Pool, we should enable Hibernation and set up a scaling plan. This way, when a user logs off, the VM will go into Hibernation instead of shutting down. The next time the user logs in, the startup will be faster, and they can continue right where they left off.

 3. Supported VM Size:

1. On the Azure Portal, while creating the Image VM, under the Size tab, click on See all sizes.

2. Click on Add Filter, in the dropdown select Hibernation and click on OK.

3. You will see the list of all the VM sizes that support Hibernation.

4. Limitation:

1. Virtual Machine with Windows 11 Enterprise multi-session + Microsoft 365 Apps, version 23H2 - x64, is currently not supported.


2. The Availability options should be selected as Availability Zone, No Infrastructure Redundancy required or Virtual Machine Scale Set. If you select Availability Set the Enable Hibernation option would be greyed out as shown:


5. Creating a Windows VM with hibernation enabled

1. When creating a Virtual Machine for image creation, you can enable hibernation directly through the Azure Portal during the setup process.
2. To confirm if the Hibernation is enabled, go to the Image VM in the Azure Portal, under Extensions+applications, the AzureHibernateExtension would be installed.

6. Enabling hibernation on an existing Windows VM:

If you forgot to check the "Enable Hibernation" option during the VM creation process, you can follow the instructions below to enable it afterward. Login to the Image VM:
1. Make sure the Page File is enabled:
  • Go to Run and type sysdm.cpl and hit Enter.
  • Click on Advanced Tab.
  • Under Performance click Settings

  • Click on Advanced. Click on Change.

  • Select System Managed Size and click on Set. Click on Okay and Apply. The system would be restarted.

  • Once the system restarts, check that the page file is set up correctly. After confirming this, you can log off from the Image VM.

2. Once the Page File is enabled, run the commands in the Azure CLI:

Problem before you start: While running the command in Azure CLI you may come across the below Resource Group not found error.

Solution:
This error occurs because the user ID that is being used for running any command in Azure CLI has access to multiple subscriptions. Run the below command to set the subscription in which the resources are lying that you want to use.
Set-AzContext <subscription_id>

Once the Subscription is set, please run the below commands:
  • To enable hibernation on an Image VM, first stop the VM
  • Stop-AzVM -ResourceGroupName 'myResourceGroup' -Name 'myVM'

  • Once the VM is stopped, update the OS disk to set SupportsHibernation to true.
  • $disk = Get-AzDisk -ResourceGroupName "myResourceGroup" -DiskName "myOSDisk"
  • $disk.SupportsHibernation = $True
  • Update-AzDisk -ResourceGroupName ‘myResourceGroup' -DiskName 'myOSDisk' -Disk $disk
  • Enable hibernation on the VM.
  • $vm= Get-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
  • Update-AzVM -ResourceGroupName "myResourceGroup" -VM $vm -HibernationEnabled


  • Start the VM
  • Start-AzVM -ResourceGroupName 'myResourceGroup' -Name 'myVM'

3. Go to the Image VM in the Azure Portal, under Extensions+applications, the AzureHibernateExtension would be installed.

4. To verify everything is working, go to Run command option under the Image VM, click on RunPowershellScript and run the command powercfg /a. You would see Hibernate and Fast Startup as sleep states available on the system.

4After completing all customizations, run the system preparation tool (sysprep). This will automatically shut down the VM. Then, proceed with the Capture process to create an image.
5. During the image capturing process, the "Hibernation Supported" option will be automatically checked.

6. Once the Azure Compute Gallery definitions are created, the next step is to create a Host Pool. During the Host Pool creation, make sure to check the Hibernate option

7. Create and assign an Autoscale scaling plan for Personal Hos Pool:

Note:
  • FSLogix and app attach currently don't support hibernate. Don't enable hibernate if you're using FSLogix or app attach for your personal host pools.
  • Scaling plan configuration data must be stored in the same region as the host pool configuration.
  • For the disconnected and logoff timings consult with the customer to understand their usage patterns and requirements, then configure these timings accordingly to balance user experience and resource management.
1. In the search bar, type Azure Virtual Desktop and select the matching service entry. Select Scaling Plans, then select Create.
3. In the Basics tab, look under Project details and select the name of the subscription you'll assign the scaling plan to.
4. If you want to make a new resource group, select Create new. If you want to use an existing resource group, select its name from the drop-down menu.
5. Enter a name for the scaling plan into the Name field.
6. For Region, select a region for your scaling plan.

7. Optionally, you can also add a "friendly" name that will be displayed to your users and a description for your plan.
8. For Time zone, select the time zone you'll use with your plan.
9. For Host pool type, select the type of host pool that you want your scaling plan to apply to.
10. Select Next, which should take you to the Schedules tab. Schedules let you define when autoscale turns VMs on and off throughout the day.

11. In the Schedules tab, select Add schedule.
12. Enter a name for your schedule into the Schedule name field.
13. In the Repeat on field, select which days your schedule will repeat on.
14. Click Next.

15. For Start time, select the time you want the ramp-up phase to start from the drop-down menu.
16. For Start VM on Connect, select Yes.
17. For VMs to start, select Don't turn VMs on at start time.
18. For When disconnected for, specify the number of minutes a user session has to be disconnected before performing Hibernate. This number can be anywhere between 0 and 360.
19. For Perform, specify Hibernate.

20. For When logged off for, specify the number of minutes a user session has to be logged off before performing Hibernate. This number can be anywhere between 0 and 360.
21. For Perform, specify Hibernate.
22. Click Next.
23. For Peak hours, specify the same settings as Previous.

24. For Ramp down specify the same settings.

25. For Off peak hours specify the same settings. Click on Add.

26.Click Next Host Pool Assignments.

27. Select the Personal Host Pool you have already created.

28. Click Next: Tags. Review +Create.

8. GPO Policies for the effective use of Scaling Plan and Hibernation:

1. Enable the 2 policies: 
"Set time limit for disconnected sessions" and "Set time limit for active but idle Remote Desktop Services sessions". 
  • This can be achieved by going to the following path:
Computer Configuration>Policies>Administrative Templates>Windows Components>Remote Desktop Services>Remote Desktop Session Host>Session Time Limits

2.  We also need to remove the user access to shutdown, restart, sign out the Session Hosts. Only the Disconnect option should be made available.



  • To achieve this enable the 2 policies: 
Remove and prevent access to Shutdown, Restart, Sleep, and Hibernate commands
Remove Logoff on the Start Menu

  • This can be achieved by going to the following path:
User Configuration>Policies>Administrative Templates>Start Menu and Task Bar.

  • Once the settings are applied, the desktop would look like this: