Skip to content

Latest commit

 

History

History
289 lines (199 loc) · 10.4 KB

hibernate-resume-linux.md

File metadata and controls

289 lines (199 loc) · 10.4 KB
title description author ms.service ms.topic ms.date ms.author ms.reviewer ms.custom
Learn about hibernating your Linux virtual machine
Learn how to hibernate a Linux virtual machine.
mattmcinnes
virtual-machines
how-to
05/20/2024
jainan
mattmcinnes
devx-track-azurecli, devx-track-azurepowershell, linux-related-content

Hibernating Linux virtual machines

Applies to: ✔️ Linux VMs

[!INCLUDE hibernate-resume-intro]

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.

To enable hibernation in the Azure CLI, create a VM by running the following az vm create command with --enable-hibernation set to true.

 az vm create --resource-group myRG \
   --name myVM \
   --image Ubuntu2204 \
   --public-ip-sku Standard \
   --size Standard_D2s_v5 \
   --enable-hibernation true 

To enable hibernation when creating a VM with PowerShell, run the following command:

New-AzVm ` 
 -ResourceGroupName 'myRG' ` 
 -Name 'myVM' ` 
 -Location 'East US' ` 
 -VirtualNetworkName 'myVnet' ` 
 -SubnetName 'mySubnet' ` 
 -SecurityGroupName 'myNetworkSecurityGroup' ` 
 -PublicIpAddressName 'myPublicIpAddress' ` 
 -Size Standard_D2s_v5 ` 
 -Image 'imageName' ` 
 -HibernationEnabled ` 
 -OpenPorts 80,3389 

To create a VM with hibernation enabled, set hibernationEnabled to true.

PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/{vm-name}?api-version=2021-11-01


{
  "location": "eastus",
  "properties": {
    "hardwareProfile": {
      "vmSize": "Standard_D2s_v5"
    },
    "additionalCapabilities": {
      "hibernationEnabled": true
    }
  }
}

To learn more about REST, check out an API example


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 \      
    
  1. To enable hibernation on an existing VM using Azure PowerShell, first stop your VM with Stop-Az vm deallocate. Once the VM is deallocated, update the OS disk and VM.

    Stop-AzVM `
     -ResourceGroupName 'myResourceGroup' ` 
     -Name 'myVM'
  2. Once the VM is stopped, 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.

    $disk = Get-AzDisk `
       -ResourceGroupName "myResourceGroup" `
       -DiskName "myOSDisk"
    $disk.SupportsHibernation = $True
    Update-AzDisk `
      -ResourceGroupName myResourceGroup' `
      -DiskName 'myOSDisk' `
      -Disk $disk
  3. Enable hibernation on the VM.

    $vm= Get-AzVM `
      -ResourceGroupName "myResourceGroup" `
      -Name "myVM"
    Update-AzVM `
      -ResourceGroupName "myResourceGroup" `
      -VM $vm `
      -HibernationEnabled
  4. Start the VM and then proceed to configuring hibernation in the guest OS.

    Start-AzVM `
     -ResourceGroupName '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

To install LinuxHibernateExtension with PowerShell, run the following command:

Set-AzVMExtension -Publisher Microsoft.CPlat.Core -ExtensionType LinuxHibernateExtension -VMName <VMName> -ResourceGroupName <RGNAME> -Name "LinuxHibernateExtension" -Location <Location> -TypeHandlerVersion 1.0

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

To use the hibernation-setup-tool in RHEL versions, run this command:

curl -sSL -O https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm

sudo rpm -i packages-microsoft-prod.rpm

rm packages-microsoft-prod.rpm

sudo dnf update

sudo dnf 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.

[!INCLUDE hibernate-resume-platform-instructions]

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