If you use on-premises hypervisor (such as Hyper-V or VMWare) you know you can hibernate (save state) virtual machines.
This was something missing for Azure virtual machines.
Well, good news as you can now enable hibernation for Azure virtual machines (currently in preview).
This new capability will help you saving cost by hibernating unused/under used virtual machines (such as for dev/test) while keeping their current state alive and getting the virtual machine in deallocated state.
This can also be quite useful for virtual machines with long boot times due to memory intensive applications.
To enable hibernation, you first need to enable the hibernation feature on the subscription(s) you want to enable it.
You can do it either from the Azure portal (https://portal.azure.com/) or PowerShell or Azure CLI
- Using Azure portal
Access the Preview features blade on the subscription and search for hibernation
- Using PowerShell
Register-AzProviderFeature -FeatureName “VMHibernationPreview” -ProviderNamespace “Microsoft.Compute”
- Using Azure CLI
az feature register –name VMHibernationPreview –namespace Microsoft.Compute
Before you start looking to enable hibernation on virtual machines, you need to know the following limitations:
- Available for virtual machines with up to 32 Gb memory using any of the below SKU’s
- Dasv5-series
- Dadsv5-series
- Dsv5-series
- Ddsv5-series
- Supported operating systems
- Window
- Windows Server 2022
- Windows Server 2019
- Windows 11 Pro
- Windows 11 Enterprise
- Windows 11 Enterprise multi-session
- Windows 10 Pro
- Windows 10 Enterprise
- Windows 10 Enterprise multi-session
- Linux
- Ubuntu 22.04 LTS
- Ubuntu 20.04 LTS
- Ubuntu 18.04 LTS
- Debian 11
- Debian 10 (with backports kernel)
- Limitations
- Windows
- The page file can’t be on the temp disk
- Applications such as Device Guard and Credential Guard that require virtualization-based security (VBS) work with hibernation when you enable Trusted Launch on the VM and Nested Virtualization in the guest OS
- Hibernation is only supported with Nested Virtualization when Trusted Launch is enabled on the VM
- Linux
- Hibernation isn’t supported with Trusted Launch for Linux VMs
- General limitations
- You can’t enable hibernation on existing VMs
- You can’t resize a VM if it has hibernation enabled
- When a VM is hibernated, you can’t attach, detach, or modify any disks or NICs associated with the VM. The VM must instead be moved to a Stop-Deallocated state
- When a VM is hibernated, there’s no capacity guarantee to ensure that there’s sufficient capacity to start the VM later. In the rare case that you encounter capacity issues, you can try starting the VM at a later time. Capacity reservations don’t guarantee capacity for hibernated VMs
- You can only hibernate a VM using the Azure portal, CLI, PowerShell, SDKs and API. Hibernating the VM using guest OS operations don’t result in the VM moving to a hibernated state and the VM continues to be billed
- You can’t disable hibernation on a VM once enabled
Now, you can enable the hibernation when creating the virtual machine.
Then to hibernate a virtual machine, either use the portal, Azure CLI or PowerShell
- Portal
Search for the virtual machine you want to hibernate and click on the Hibernate button
- PowerShell
Stop-AzVM -ResourceGroupName “TestRG” -Name “TestVM” -Hibernate
- Azure CLI
az vm deallocate –resource-group TestRG –name TestVM –hibernate true