Is it possible to give some swap space to virtual machine?

I just realized that VM instances don’t have any swap that could come handy with limited RAM. Is there any way to give them some swap space?

You may create a swap file using cloud-init, you have an example here : https://cloudinit.readthedocs.io/en/latest/reference/modules.html#mounts

1 Like

Is the swap file the only option? It’s a shame that it seems we cannot provide vm with a block device that could be used as a swap partition.

Thanks for the suggestion, though! I looked into cloud-init documentation and swap file can be created in the following way:

          user.vendor-data: |
            #cloud-config
            swap:
              filename: /swapfile
              size: "auto"
              maxsize: 3G
1 Like

You could create a custom block volume and attach it to the instance for use as swap drive.

https://linuxcontainers.org/lxd/docs/latest/howto/storage_volumes/