Tuesday, August 19, 2014

Add swap space to Azure Ubuntu IaaS VM

Tuesday, August 19, 2014 Posted by Andre Broers , , ,
By default Azure doesn't add swap space to it's Linux Virtual Machines. I don't know why but luckily it's easy to turn it on.

Follow these steps to enable swap:

edit the file /etc/waagent.conf

Toggle the option ResourceDisk.Format from 'n' to 'y'
Toggle the option ResourceDisk.EnableSwap from 'n' to 'y'
Add the swapspace size to the option ResourceDisk.SwapSizeMB. In my case 1000 for 1000MB.

# Format if unformatted. If 'n', resource disk will not be mounted.

# File system on the resource disk
# Typically ext3 or ext4. FreeBSD images should use 'ufs2' here.

# Mount point for the resource disk

# Create and use swapfile on resource disk.

# Size of the swapfile.

Also edit the file /etc/fstab and remove the line:

/dev/sdb1 /mnt auto defaults,nobootwait,comment=cloudconfig 0 2

Now after a reboot the waagent starts creating a swap file and after a while it is enabled:

swapon -s
Filename Type Size Used Priority
/mnt/swapfile                           file 1023996 0 -1