How to Create a Swap File on Google Compute Engine Virtual Machines

These are the procedures I followed for Ubuntu 14.04 LTS but should work with other Debian distros.

Once you’ve done this you could make this permanent by editing the /etc/fstab file:

If you’re using CentOS 7, Patrick in comments points out:

  1. The fallocate failed if you did not use ‘sudo’.
  2. the ‘swapon’ command failed on the root xfs, moved swap to ext works fine.

4 thoughts on “How to Create a Swap File on Google Compute Engine Virtual Machines

  1. Patrick O'Leary

    Thank you for this very helpful posting.

    On a GC CentOS 7 VM:
    1) The fallocate failed if you did not use ‘sudo’.
    2) the ‘swapon’ command failed on the root xfs, moved swap to ext works fine.

    It would be an interesting experiment to add two separate disks for swap, a small 2G SSD and a regular disk with remaining swap size requirement with SSD-swap of higher priority.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *