Create SWAP partition – Azure Linux VM
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,
# Create and use swapfile on resource disk. ResourceDisk.EnableSwap=n # Size of the swapfile. ResourceDisk.SwapSizeMB=0
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)
# Create and use swapfile on resource disk. ResourceDisk.EnableSwap=y # Size of the swapfile. ResourceDisk.SwapSizeMB=10240
After the change is made, please unmount /mnt and restart the waagent service.
To unmount /mnt, please execute the below command,
umount /mnt
Once the /mnt is unmounted, please execute the below command to restart the WAAGENT service.
For Ubuntu,please execute the below command,
sudo service walinuxagent restart
For CoreOS, please execute the command,
sudo systemctl restart waagent
For other linux distributions, please execute the command,
sudo service waagent restart
https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-agent-user-guide