Configuring Hibernate for Azure Virtual Desktop (AVD) | Step-by-Step Guide
Tags: avd, microsoft, azure
Published: 2024-06-08 06:20:49

This blog post discusses how to configure the hibernate feature for Azure Virtual Desktop (AVD) desktops.Many companies use autoscaling features to reduce cloud spending. However, personal AVD users may experience wait times while VMs transition from a deallocated state to a ready state.The hibernate option allows users to resume their work or restore the AVD's current state when they return the next day.It allows users to faster access to their desktops and preserve application states. Hibernation also benefits companies by saving cloud costs and reducing energy consumption, aligning with sustainability initiatives.

Let's now explore how to configure hibernation for AVD desktops... 
Hibernate feature is supported only in specific Azure VM families like DsV5 series and Esv5 series. 

## Enabling Hibernate feature during AVD Session Host creation
For those new to AVD, a session host is a virtual machine that provides desktops to users. To enable hibernation, follow these steps:

1. Initiate the session host creation wizard within AVD.

1. During the VM creation workflow, locate the option labeled "Hibernate" and tick the checkbox. This action will activate the hibernate feature for the virtual machine (as illustrated in the available screenshot).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfha3njo7w1yl5c23130.png)

Proceed with the session host creation. Once the session hosts are created, the next step is to configure hibernate via auto scaling.

## Configure the Hibernate via auto scaling.
For those new to AVD auto-scaling, you can refer to your earlier blog... (https://amalcloud.wordpress.com/2023/07/22/770/)  .
In the auto scaling settings, change the disconnect and log off settings to Hibernate the VM rather than shutting it down(as illustrated in the available screenshot). Perform the same for weekend and weekday schedules.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7dqhwaxilfehtyvln02.png)

## VM going to Hibernate
We have configured the auto scaling feature to hibernate the VM after X minutes of disconnection, logoff as per the configuration. I configured 1 minute to hibernate my VM after disconnection. In the Azure console the VM state has changed to "hibernated(deallocated)"(as illustrated in the available screenshot).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxvz7odirk2z6m54vsjh.png)
One interesting fact is; my VM took 1 minute 47 seconds to restore completely and become accessible (or to be able to see) my desktop. This includes entering the credentials to AVD as well.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhb47to1yg0oww993q61.png)

However my VDI state has been preserved and the user satisfaction increased.
I haven't observed any other issues with Hibernate feature, please comment if you are seeing any abnormalities after enabling autoscaling feature.
#enable Hibernate option in existing VMs
While hibernation can be enabled for existing VMs using various methods like PowerShell, CLI, ARM, SDKs, and APIs, let's explore how to achieve this using PowerShell.
For this demo, I took a VM where hibernate feature is disabled as shown in the below screenshot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pgvyoq8gkx5x6ut4fdyz.png)
Execute the script located in my github to enable hibernate feature
(https://github.com/amalkabraham001/AVD/blob/c1a60c159253eb628aff589004cd3ec3f11bdcaf/Session%20Host/hibernate/enablehibernate.ps1).
The script will first deallocate the VM and then enable hibernation support in the OS disk. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9blsp5kn5gnk54t888t7.png)
Once the disk level hibernation support is enabled, the script will enable hibernate feature in the VM as shown in the below screenshots.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ituwg01f8vyujev5wubo.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9x8mghbz99f2hw1imq4.png)

Hope this blog is informative. Please feel free to share this blog.