Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The default Ubuntu AMI does not have swap enabled, but it is not suitable for production use as the machine just crash when it is Out Of Memory.

Are there existing images with swap enabled so I can use without create a custom image?


share|improve this question

You do not need to create a custom AMI in order to gain swap storage on an Amazon EC2 instance. Rather you can simply add a swap file as outlined in How do I add more swap?:

Swap is generally associated with a swap partition, perhaps because the user is prompted to create a swap partition at the time of installation. In fact, any file can be used as a swapping device, be it a partition or a conventional file. Swap can be added by increasing the size of the swap partition or by adding a swap file. [...] [emphasis mine]

Section Four-step Process to Add Swap File outlines the required steps, which boils down to e.g. (replace /mnt with an appropriate directory of your choice):

sudo fallocate -l 512m /mnt/512MiB.swap
sudo chmod 600 /mnt/512MiB.swap
sudo mkswap /mnt/512MiB.swap
sudo swapon /mnt/512MiB.swap

This won't survive a reboot yet, thus requires you to edit /etc/fstab, e.g.:

sudo nano /etc/fstab

Then add this line at the end of the file:

/mnt/512MiB.swap  none  swap  sw  0 0

Please refer to the linked page for more details and an example session, if need be.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.