Breyta

Deila með


Hibernating Linux virtual machines

Applies to: ✔️ Linux VMs

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 servers, 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

To learn how hibernation works, check out the hibernation overview.

Supported configurations

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

For a list of hibernation compatible VM sizes, check out the supported VM sizes section in the hibernation overview.

Supported Linux distros

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)
  • RHEL 9.0 and higher (with minimum kernel version 5.14.0-70)
  • RHEL 8.3 and higher (with minimum kernel version 4.18.0.240)

Prerequisites and configuration limitations

  • Hibernation isn't supported with Trusted Launch for Linux VMs

For general limitations, Azure feature limitations supported VM sizes, and feature prerequisites check out the "Supported configurations" section in the hibernation overview.

Creating a Linux VM with hibernation enabled

To hibernate a VM, you must first enable the feature on the VM.

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 while creating a new Linux VM.

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

Enabling hibernation on an existing Linux VM

To enable hibernation on an existing VM, you can use Azure CLI, PowerShell, or REST API. Before proceeding, ensure that the guest OS version supports hibernation on Azure. For more information, see supported OS versions.

To enable hibernation on an existing VM using Azure CLI, first deallocate your VM with az vm deallocate. Once the VM is deallocated, update the OS disk and VM.

  1. Update the OS disk to set supportsHibernation to true. If supportsHibernation is already set to true, you can skip this step and proceed to the next step.

       az disk update --resource-group myResourceGroup \
       --name MyOSDisk \   
       --set supportsHibernation=true 
    
  2. Update the VM to enable hibernation.

       az vm update --resource-group myResourceGroup \
       --name myVM \
       --enable-hibernation true 
    
  3. Start the VM and then proceed to configuring hibernation in the guest OS.

       az vm start --resource-group myResourceGroup \
       --name myVM \      
    

Configuring hibernation in the guest OS

After ensuring that your VM configuration is supported, you can enable hibernation on your Linux VM using one of two options:

Option 1: LinuxHibernateExtension

Option 2: hibernation-setup-tool

LinuxHibernateExtension

Note

If you've already installed the hibernation-setup-tool you do not need to install the LinuxHibernateExtension. These are redundant methods to enable hibernation on a Linux VM.

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 Linux hibernation troubleshooting guide.

Note

For RHEL LVM you will need to expand the root volume and ensure there is sufficient space available to create the swap file. To expand the volume, check the disk expansion 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

Hibernation-setup-tool

Note

If you've already installed the LinuxHibernateExtension you do not need to install the hibernation-setup-tool. These are redundant methods to enable hibernation on a Linux VM.

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 hibernation-setup-tool in Debian and Ubuntu versions, open git bash and run this command:

curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee etc/apt/trusted.gpg.d/microsoft.asc

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

sudo apt-get update

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

sudo apt-get install hibernation-setup-tool

Note

For RHEL LVM you will need to expand the root volume and ensure there is sufficient space available to create the swap file. To expand the volume, check the disk expansion guide.

Once the package installs successfully, your Linux guest OS is 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, simplifying your VM creation experience.

Hibernate 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. This can be done through the Azure portal, the Azure CLI, PowerShell, or REST API.

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 and the Linux VM hibernation troubleshooting guide for more information.

FAQs

Refer to the Hibernate FAQs for more information.

Next steps