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
- 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.
- 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.
- Deallocate your VM using
- Configuring the Guest OS: The ‘Microsoft.CPlat.Core.WindowsHibernateExtension’ VM extension is automatically installed. Ensure the page file is on the C: drive.
- Hibernate and Resume: Use the Azure portal, CLI, PowerShell, or REST API to hibernate and resume the VM.
Linux VMs
- 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.
- 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.
- Deallocate your VM using
- Configuring the Guest OS: Use either the
LinuxHibernateExtension
or thehibernation-setup-tool
. Ensure there is sufficient space available to create the swap file, especially for RHEL. - Hibernate and Resume: Use the Azure portal, CLI, PowerShell, or REST API to hibernate and resume the 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
orhibernation-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:
- 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.
- Enable Hibernation: You can configure the OS for hibernation by enabling the hibernation feature in the guest operating system.
- 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
- Check Hibernation Status: Verify if hibernation is enabled on your virtual machine. You can check the hibernation property associated with the VM.
- 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:
- Check Compatibility: Ensure the existing machine’s OS and disk support hibernation.
- Update Configuration: Configure the OS for hibernation by enabling the hibernation feature in the guest OS, as explained in the Azure VM documentation.
- 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.
- 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:
- State Preservation: When hibernation is triggered, Azure persists the VM’s state, including the processes that were previously running.
- Deallocation: The VM is deallocated, resulting in the VM’s compute resources being freed and you being billed only for the storage used.
- 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