How to add a swap space in Linux Azure virtual machines

How to add a swap space in Linux Azure virtual machines

I have started to work on azure for Linux machines and I found swap space 0 MB on Ubuntu 16.04 or Linux distro in Azure. In this article, we will see how to use azure temporary disk for swap memory.

Microsoft azure provide temporary drive with each VM. The disk /dev/sdb1 mounted to /mnt in Linux distro which we can use for swap space.

Temporary disk :
Each VM contains a temporary disk. The temporary disk provides short-term storage for applications and processes and is intended to only store data such as page or swap files. Data on the temporary disk may be lost during a maintenance event or when you redeploy a VM.

In any linux distro on Windows Azure, the sdb1 will be the temporary drive to be mounted. The mount point and directory mounted might be different between linux distros.

You can also use this drive only to store temporary data, which you can afford to lose at any time.

Lets start how to add swap space in Linux Azure Virtual Machines.

Open the file “/etc/waagent.conf” and make changes in file

# vi /etc/waagent.conf

Below are default setting in waagent.conf file

ResourceDisk.Format=n
ResourceDisk.EnableSwap=n
ResourceDisk.SwapSizeMB=0

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

ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=16384
# free -m
total used free shared buff/cache available
Mem:  28137 389 26645 8 1102 27274
Swap:  0 0 0
# systemctl restart walinuxagent
# free -m
total used free shared buff/cache available
Mem: 28137 390 26645 8 1101 27274
Swap: 16383 0 16383

Hopefully this will helps your understanding 😊

Tagged , , , , , , , , , . Bookmark the permalink.

7 Responses to How to add a swap space in Linux Azure virtual machines

  1. Pingback: ciprofloxacin 500mg antibiotics

  2. Pingback: 100mg viagra overnight delivery to me

  3. Pingback: hydroxychloroquine tablet price

  4. Pingback: sildenafil 100mg price comparison walgreens

  5. Pingback: Google

  6. Pingback: Herbal potpourri

  7. Pingback: consultant seo