共用方式為


How to: Add SWAP to Linux VM's on Azure

Every virtual machine (VM) on Azure has what we call a temporary (ephemeral) disk which is recommended to be used ONLY as temporary storage and that includes SWAP files or data that does not need to be available upon a reboot or saved , the data stored in this drive will be lost.

To create a swap file in the directory that's defined by the ResourceDisk.MountPoint parameter, you can update the /etc/waagent.conf file by setting the following three parameters:

ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=xx

Where the size is in MB, so for instance, to create a SWAP file of 4GB you could use these lines:

ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=4096

Before creating a SWAP file using the WAAgent, we also recommend looking at how much space you have available for the temporary disk by checking this link where on each category of VM we display the local SSD or local HDD storage available.

References:

How to add a swap file in Linux Azure virtual machines Optimizing your Linux VM on Azure

Comments

  • Anonymous
    January 07, 2018
    I want to add swap configuration in my powershell script that I use to create VM using AzureRMvM modules. Any hints ?
    • Anonymous
      February 20, 2018
      Hi Faizan,I would use Custom Script after the VM is deployed to add the configuration using the /etc/waagent.conf file or you can also create a base image with everything you need and deploy from that.https://support.microsoft.com/en-us/help/4010058/how-to-add-a-swap-file-in-linux-azure-virtual-machineshttps://docs.microsoft.com/en-us/azure/virtual-machines/linux/extensions-customscriptThank you,-Marco