6

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?

Bob
  • 393
  • 3
  • 8

3 Answers3

8

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.

Bruno Faria
  • 3,804
  • 1
  • 11
  • 18
  • I believe one's supposed to somehow `restart` the walinuxagent after these changes (or at least `reload`)? – Hassan Baig Mar 09 '17 at 16:22
  • yes. need to restart the service. – Bruno Faria Mar 09 '17 at 16:32
  • Oh okay. In case one doesn't want to reboot the VM, any other way to restart the service? e.g. `sudo service walinuxagent restart` gives `stop: Unknown instance:` and consequently doesn't work. – Hassan Baig Mar 09 '17 at 16:33
  • seems to be related to another problem. http://askubuntu.com/questions/429698/stop-unknown-instance-networking-stop-waiting-ubuntu-server-12-04-3 – Bruno Faria Mar 09 '17 at 16:36
  • Added the question here, in case you want to glance at it: http://serverfault.com/questions/837306/restarting-process-gives-start-rejected-send-message-error – Hassan Baig Mar 09 '17 at 16:46
6

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.

Massimo
  • 68,714
  • 56
  • 196
  • 319
2

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