Is it safe to store a swap-file on the Temporary Disk on Azure?

I've got a virtual Linux server running on Microsoft Azure. The machine has a disk /dev/sdb1 mounted to /mnt. This folder contains a file DATALOSS_WARNING_README.txt with the following content:

WARNING: THIS IS A TEMPORARY DISK.

Any data stored on this drive is SUBJECT TO LOSS and THERE IS NO WAY TO RECOVER IT.

Please do not use this disk for storing any personal or application data.

For additional details to please refer to the MSDN documentation at: http://msdn.microsoft.com/en-us/library/windowsazure/jj672979.aspx

I was wondering if it was safe to store the swap file for my Linux server on this disk? Or might this lead to problems?


On Windows virtual machines, this is done by default.

On Linux VMs this should be safe too, unless the system expects the swap file to already exist at boot time: then it could complain about not finding it and thus being unable to mount it.

In this case, some scripting would be needed to check at boot time if the swap file is actually there and create it if it isn't; all of this of course before mounting it.

Azure probably provides some means to automatically manage this.


No problem to have swap file on this disk but make sure to use the Linux agent to create it. It will automatically create and manage it in the resource disk.

Here's how to enable:

  • Edit the "/etc/waagent.conf"

Add or uncomment these lines:

ResourceDisk.Format=y
ResourceDisk.Filesystem=ext4
ResourceDisk.MountPoint=/mnt/resource 
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=2048

Usually only EnableSwap and SwapSizeMB will not come configured by default. Save and restart the agent to apply.


It's actually recommended to add a swap space especially for VMs with low RAM

Decent read on this and other recommended optimizations for Linux VMs

In addition to the other answers mentioned if you're using CoreOS the waagent.conf that you use to manage the swap space (and other options) is located at

/usr/share/oem/waagent.conf

and not

/etc/waagent.conf

The other steps remain the same. i.e. modify these options in the file

# Create and use swapfile on resource disk.
ResourceDisk.EnableSwap=y

# Size of the swapfile.
ResourceDisk.SwapSizeMB=4096

And restart the agent using

sudo systemctl restart waagent 

If you're using any other Linux distros you might want to check out the additional readme docs on the waagent repo