Hand pointing to a computer

Last Updated on June 19, 2024 by Arnav Sharma

Hibernation is an effective cost management feature available for Azure virtual machines (VMs), allowing you to pause VMs that are not in use, thereby saving on compute costs. Whether you are using Linux or Windows VMs, Azure provides a straightforward process to hibernate and resume these machines, ensuring that your applications can quickly pick up right where they left off. This blog post will explore the details of hibernating Azure VMs, the supported configurations, and the specific steps for both Windows and Linux environments.

Why Hibernate Your VMs?

Hibernation is particularly beneficial for:

  • Virtual desktops, dev/test servers, and other scenarios where VMs don’t need to run 24/7.
  • Systems with long boot times due to memory-intensive applications. These applications can be initialized on VMs and hibernated. Prewarmed VMs can then be quickly started with applications already running in the desired state.

How Hibernation Works

When you hibernate a VM, Azure signals the VM’s operating system to perform a suspend-to-disk action. The memory contents of the VM are stored in the OS disk, and the VM is then deallocated. When you start the VM again, the memory contents are transferred from the OS disk back into memory, allowing applications and processes to resume from their previous state.

Once a VM is in a hibernated state, you aren’t billed for the VM usage. Instead, you’re only billed for the storage (OS disk, data disks) and networking resources (IPs, etc.) attached to the VM.

Supported Configurations

Hibernation support is limited to certain VM sizes and OS versions. Here are the key configurations:

Supported Operating Systems

Windows

  • Windows Server 2022
  • Windows Server 2019
  • Windows 11 Pro, Enterprise, Enterprise multi-session
  • Windows 10 Pro, Enterprise, Enterprise multi-session

Linux

  • Ubuntu 22.04 LTS, 20.04 LTS, 18.04 LTS
  • Debian 11, 10 (with backports kernel)
  • RHEL 9.0+ (with minimum kernel version 5.14.0-70), RHEL 8.3+ (with minimum kernel version 4.18.0.240)

Supported VM Sizes

VM sizes with up to 64-GB RAM from the following General Purpose VM series support hibernation:

  • Dasv5-series
  • Dadsv5-series
  • Dsv5-series
  • Ddsv5-series
  • Easv5-series
  • Eadsv5-series
  • Esv5-series
  • Edsv5-series

VM sizes with up to 112-GB RAM from the following GPU VM series support hibernation:

  • NVv4-series (in preview)
  • NVadsA10v5-series (in preview)

Configure Hibernation

Windows VMs

  1. Enable Hibernation During VM Creation: In the Azure portal, check the ‘Enable hibernation’ box during VM creation. This can also be done via CLI, PowerShell, ARM templates, and API.
  2. Enable Hibernation on an Existing VM:
    • Deallocate your VM using az vm deallocate.
    • Update the OS disk to set supportsHibernation to true.
    • Update the VM to enable hibernation.
    • Start the VM and configure the guest OS for hibernation.
  3. Configuring the Guest OS: The ‘Microsoft.CPlat.Core.WindowsHibernateExtension’ VM extension is automatically installed. Ensure the page file is on the C: drive.
  4. Hibernate and Resume: Use the Azure portal, CLI, PowerShell, or REST API to hibernate and resume the VM.
Hybernate a vm

Linux VMs

  1. Enable Hibernation During VM Creation: Check the ‘Enable hibernation’ box in the Azure portal during VM creation. This can also be done via CLI, PowerShell, ARM templates, and API.
  2. Enable Hibernation on an Existing VM:
    • Deallocate your VM using az vm deallocate.
    • Update the OS disk to set supportsHibernation to true.
    • Update the VM to enable hibernation.
    • Start the VM and configure the guest OS for hibernation.
  3. Configuring the Guest OS: Use either the LinuxHibernateExtension or the hibernation-setup-tool. Ensure there is sufficient space available to create the swap file, especially for RHEL.
  4. Hibernate and Resume: Use the Azure portal, CLI, PowerShell, or REST API to hibernate and resume the VM.
hibernated vm

Troubleshooting

Windows VMs

  • Ensure the page file is on the C: drive.
  • Use the powercfg commands to verify and enable hibernation.

Linux VMs

  • Install the LinuxHibernateExtension or hibernation-setup-tool.
  • Ensure sufficient space for the swap file.

FAQ: 

Q: How can I hibernate a VM in Azure?

To hibernate a VM in Azure, you need to ensure that the VM is configured for hibernation. Microsoft Azure provides the capability to hibernate VMs, allowing you to preserve the VM’s state and quickly restart it when needed. Follow these steps to hibernate a VM using Azure:

  1. Prerequisites: Ensure your VM meets the prerequisites for hibernation. The VM’s OS disk or compute gallery image must support hibernation. The VM should also be a Windows virtual machine with hibernation enabled.
  2. Enable Hibernation: You can configure the OS for hibernation by enabling the hibernation feature in the guest operating system.
  3. Using PowerShell: You can use PowerShell commands to create and manage VMs with hibernation enabled. For instance, use the command to hibernate an Azure VM: az vm create --resource-group myrg --name myvm --image myimage --enable-hibernation
  4. Check Hibernation Status: Verify if hibernation is enabled on your virtual machine. You can check the hibernation property associated with the VM.
  5. Trigger Hibernation: You can hibernate the VM by triggering hibernation from inside the guest OS or using Azure tools.

Q: What are the prerequisites to use hibernation in Azure VMs?

To use hibernation in Azure VMs, the following prerequisites must be met:

  • Supported OS Disk: The VM’s OS disk or compute gallery image must support hibernation.
  • Windows Virtual Machine: Hibernation is available for Windows virtual machines.
  • Hibernation Feature: The hibernation feature must be enabled in the guest operating system.
  • Memory and Storage: The VM must have enough memory and storage to support hibernation. The storage must be large enough to store the VM state.

Q: How do I enable hibernation on an existing virtual machine in Azure?

To enable hibernation on an existing virtual machine in Azure, follow these steps:

  1. Check Compatibility: Ensure the existing machine’s OS and disk support hibernation.
  2. Update Configuration: Configure the OS for hibernation by enabling the hibernation feature in the guest OS, as explained in the Azure VM documentation.
  3. Verify Hibernation: Check if hibernation is enabled on the virtual machine since the OS disk or compute gallery image supports it. Refer to the hibernation overview for more details.
  4. Restart VM: Restart the VM to apply the hibernation settings.

Q: How does the hibernation feature work in Microsoft Azure?

The hibernation feature in Microsoft Azure allows a virtual machine to save its state to disk, deallocate the VM, and quickly restart it when needed. Here’s how it works:

  1. State Preservation: When hibernation is triggered, Azure persists the VM’s state, including the processes that were previously running.
  2. Deallocation: The VM is deallocated, resulting in the VM’s compute resources being freed and you being billed only for the storage used.
  3. Quick Start: The VM can be quickly started when needed, restoring the previous state and resuming operations.

Q: How can I create a VM with hibernation enabled using Azure?

To create a VM with hibernation enabled in Azure, use the following PowerShell command:

az vm create --resource-group myrg --name myvm --image myimage --enable-hibernation 

This command will create a new virtual machine with the hibernation capability enabled, allowing you to use the hibernation feature as needed.

Q: What is a Hibernated VM in Azure?

A Hibernated VM in Azure is a virtual machine that has been put into a hibernation state, preserving its memory and state for faster startup. This process is known as hibernation in the guest.

Q: How does Hibernation in the Guest work?

Hibernation in the guest works by saving the current state and memory of the VM to disk, allowing the VM to resume exactly where it left off. This feature can be particularly useful for quickly starting VMs that have been hibernated.

Q: What are Hibernation Enabled VMs?

Hibernation enabled VMs are virtual machines that have the capability to enter a hibernation state. This means they can save their state and memory to disk and be resumed later, reducing the need for a full reboot.

vm hibernation in hibernated vm

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.