Hibernating virtual machines

Applies to: ✔️ Linux VMs ✔️ Windows VMs

Important

Azure Virtual Machines - Hibernation is currently in PREVIEW. See the Supplemental Terms of Use for Microsoft Azure Previews for legal terms that apply to Azure features that are in beta, preview, or otherwise not yet released into general availability.

Hibernation allows you to pause VMs that aren't being used and save on compute costs. It's an effective cost management feature for scenarios such as:

  • Virtual desktops, dev/test, and other scenarios where the 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. These “prewarmed” VMs can then be quickly started when needed, with the applications already up and 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. Azure stores the memory contents of the VM in the OS disk, then deallocates the VM. When the VM is started again, the memory contents are transferred from the OS disk back into memory. Applications and processes that were previously running in your VM resume from the state prior to hibernation.

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

When hibernating a VM:

  • Hibernation is triggered on a VM using the Azure portal, CLI, PowerShell, SDKs, or APIs. Azure then signals the guest operating system to perform suspend-to-disk (S4).
  • The VM's memory contents are stored on the OS disk. The VM is then deallocated, releases the lease on the underlying hardware, and is powered off. Refer to VM states and billing for more details on the VM deallocated state.
  • Data in the temporary disk isn't persisted.
  • The OS disk, data disks, and NICs remain attached to your VM. Any static IPs remain unchanged.
  • You aren't billed for the VM usage for a hibernated VM.
  • You continue to be billed for the storage and networking resources associated with the hibernated VM.

Supported configurations

Hibernation support is limited to certain VM sizes and OS versions. Make sure you have a supported configuration before using hibernation.

Supported VM sizes

VM sizes with up to 32-GB RAM from the following VM series support hibernation.

Operating system support and limitations

Supported Linux versions

The following Linux operating systems support hibernation:

  • Ubuntu 22.04 LTS
  • Ubuntu 20.04 LTS
  • Ubuntu 18.04 LTS
  • Debian 11
  • Debian 10 (with backports kernel)
Linux Limitations
  • 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.

Azure feature limitations

  • Ephemeral OS disks
  • Shared disks
  • Availability Sets
  • Virtual Machine Scale Sets Uniform
  • Spot VMs
  • Managed images
  • Azure Backup
  • Capacity reservations

Prerequisites to use hibernation

  • A persistent OS disk large enough to store the contents of the RAM, OS and other applications running on the VM is connected.
  • The VM size supports hibernation.
  • The VM OS supports hibernation.
  • The Azure VM Agent is installed if you're using the Windows or Linux Hibernate Extensions.
  • Hibernation is enabled on your VM when creating the VM.
  • If a VM is being created from an OS disk or a Compute Gallery image, then the OS disk or Gallery Image definition supports hibernation.

Getting started with hibernation

To hibernate a VM, you must first enable the feature while creating the VM. You can only enable hibernation for a VM on initial creation. You can't enable this feature after the VM is created.

To enable hibernation during VM creation, you can use the Azure portal, CLI, PowerShell, ARM templates and API.

To enable hibernation in the Azure portal, check the 'Enable hibernation' box during VM creation.

Screenshot of the checkbox in the Azure portal to enable hibernation when creating a new VM.

Once you've created a VM with hibernation enabled, you need to configure the guest OS to successfully hibernate your VM.

Guest configuration for hibernation

Configuring hibernation on Linux

There are many ways you can configure the guest OS for hibernation in Linux VMs.

Option 1: LinuxHibernateExtension

When you create a Hibernation-enabled VM via the Azure portal, the LinuxHibernationExtension is automatically installed on the VM.

If the extension is missing, you can manually install the LinuxHibernateExtension on your Linux VM to configure the guest OS for hibernation.

Note

Azure extensions are currently disabled by default for Debian images. To re-enable extensions, check the hibernation troubleshooting guide.

To install LinuxHibernateExtension with the Azure CLI, run the following command:

az vm extension set -n LinuxHibernateExtension --publisher Microsoft.CPlat.Core --version 1.0 \    --vm-name MyVm --resource-group MyResourceGroup --enable-auto-upgrade true

Option 2: hibernation-setup-tool

You can install the hibernation-setup-tool package on your Linux VM from Microsoft’s Linux software repository at packages.microsoft.com.

To use the Linux software repository, follow the instructions at Linux package repository for Microsoft software.

To use the repository in Ubuntu 18.04, open git bash and run this command:

curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

sudo apt-add-repository https://packages.microsoft.com/ubuntu/18.04/prod

sudo apt-get update

To install the package, run this command in git bash:

sudo apt-get install hibernation-setup-tool

Once the package installs successfully, your Linux guest OS has been configured for hibernation. You can also create a new Azure Compute Gallery Image from this VM and use the image to create VMs. VMs created with this image have the hibernation package preinstalled, thereby simplifying your VM creation experience.

Configuring hibernation on Windows

Enabling hibernation while creating a Windows VM automatically installs the 'Microsoft.CPlat.Core.WindowsHibernateExtension' VM extension. This extension configures the guest OS for hibernation. This extension doesn't need to be manually installed or updated, as this extension is managed by the Azure platform.

Note

When you create a VM with hibernation enabled, Azure automatically places the page file on the C: drive. If you're using a specialized image, then you'll need to follow additional steps to ensure that the pagefile is located on the C: drive.

Note

Using the WindowsHibernateExtension requires the Azure VM Agent to be installed on the VM. If you choose to opt-out of the Azure VM Agent, then you can configure the OS for hibernation by running powercfg /h /type full inside the guest. You can then verify if hibernation is enabled inside guest using the powercfg /a command.

Hibernating a VM

Once a VM with hibernation enabled has been created and the guest OS is configured for hibernation, you can hibernate the VM through the Azure portal, the Azure CLI, PowerShell, or REST API.

To hibernate a VM in the Azure portal, click the 'Hibernate' button on the VM Overview page.

Screenshot of the button to hibernate a VM in the Azure portal.

View state of hibernated VM

To view the state of a VM in the portal, check the 'Status' on the overview page. It should report as "Hibernated (deallocated)"

Screenshot of the Hibernated VM's status in the Azure portal listing as 'Hibernated (deallocated)'.

Start hibernated VMs

You can start hibernated VMs just like how you would start a stopped VM.

To start a hibernated VM using the Azure portal, click the 'Start' button on the VM Overview page.

Screenshot of the Azure portal button to start a hibernated VM with an underlined status listed as 'Hibernated (deallocated)'.

VMs created from Compute Gallery images can also be enabled for hibernation. Ensure that the OS version associated with your Gallery image supports hibernation on Azure. Refer to the list of supported OS versions.

To create VMs with hibernation enabled using Gallery images, you'll first need to create a new image definition with the hibernation property enabled. Once this feature property is enabled on the Gallery Image definition, you can create an image version and use that image version to create hibernation enabled VMs.

Note

For specialized Windows images, the page file location must be set to C: drive in order for Azure to successfully configure your guest OS for hibernation. If you're creating an Image version from an existing VM, you should first move the page file to the OS disk and then use the VM as the source for the Image version.

To create an image definition with the hibernation property enabled, select the checkmark for 'Enable hibernation'.

Screenshot of the option to enable hibernation in the Azure portal while creating a VM image definition.

Deploy hibernation enabled VMs from an OS disk

VMs created from OS disks can also be enabled for hibernation. Ensure that the OS version associated with your OS disk supports hibernation on Azure. Refer to the list of supported OS versions.

To create VMs with hibernation enabled using OS disks, ensure that the OS disk has the hibernation property enabled. Refer to API example to enable this property on OS disks. Once the hibernation property is enabled on the OS disk, you can create hibernation enabled VMs using that OS disk.

PATCH https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk?api-version=2021-12-01

{
  "properties": {
    "supportsHibernation": true
  }
}

Troubleshooting

Refer to the Hibernate troubleshooting guide for more information

FAQs

  • What are the charges for using this feature?

    • Once a VM is placed in a hibernated state, you aren't charged for the VM, just like how you aren't charged for VMs in a stop (deallocated) state. You're only charged for the OS disk, data disks and any static IPs associated with the VM.
  • Can I enable hibernation on existing VMs?

    • No, you can't enable hibernation on existing VMs. You can only enable hibernation at the time of creating a VM.
  • Can I resize a VM with hibernation enabled?

    • No. Once you enable hibernation on a VM, you can't resize the VM.
  • Can I modify a VM once it is in a hibernated state?

    • No, once a VM is in a hibernated state, you can't perform actions like resizing the VM and modifying the disks. Additionally, you can't detach any disks or networking resources that are currently attached to the VM or attach new resources to the VM. You can however stop(deallocate) or delete the VM if you want to detach these resources.
  • What is the difference between stop(deallocating) and hibernating a VM?

    • When you stop(deallocate) a VM, the VM shuts down without persisting the memory contents. You can resize stop(deallocated) VMs and detach/attach disks to the VM.

    • When you hibernate a VM, the memory contents are first persisted in the OS disk, then the VM hibernates. You can't resize VMs in a hibernated state, nor detach/attach disks and networking resources to the VM.

  • Can you disable hibernation?

    • No, you can't disable hibernation on a VM.
  • Can I initiate hibernation from within the VM?

    • To hibernate a VM you should use the Azure portal, CLI, PowerShell commands, SDKs and APIs. Triggering hibernation from inside the VM still results in your VM being billed for the compute resources.
  • When a VM is hibernated, is there a capacity assurance at the time of starting the VM?

    • No, there's no capacity assurance for starting hibernated VMs. In rare scenarios if you encounter a capacity issue, then you can try starting the VM at a later time.

Next Steps: