05 Feb

Create SWAP partition – Azure Linux Virtual Machine

Create SWAP partition – Azure Linux Virtual Machine

The swap partition created using the standard methods may not persist after a machine reboot, for a linux virtual machine hosted in Microsoft Azure environment. The Microsoft Azure provide the option to create SWAP partition – Azure Linux Virtual Machine,  using the /dev/sdb partition and WAAGENT service.  The  WAAGENT service is an Azure Linux agent for Microsoft Azure environment and will be present in Azure Linux virtual machines by default on each VM. The /dev/sdb partition is a volatile partition(similar to RAM). The data stored in this partition will be lost after each machine reboot. So we can make use of this partition as our swap partition.

To enable the swap in Azure linux VM, you need to do edit the file, that is located at /etc/waagent.conf. Look for the below two lines,

Change the ResourceDisk.EnableSwap=y and ResourceDisk.SwapSizeMB=10240, the value 10240 = 10GB. This will create a /swapfile in the resource disk and persistent system swap space will be created. By default the resource disk in an Azure Virtual Machine will be /mnt/resource(/dev/sdb)

After the change is made, please unmount /mnt and restart the waagent service.

To unmount /mnt, please execute the below command,

Once the /mnt is unmounted, please execute the below command to restart the WAAGENT service.

For Ubuntu,please execute the below command,

For CoreOS, please execute the command,

For other linux distributions, please execute the command,

https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-agent-user-guide

 

Leave a Reply

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

16 − fourteen =