September 6, 2015 · Ghost Ubuntu

Adding a swap partition to Ubuntu 14.04 LTS

After trying to upgrade Ghost to the latest version I found NPM (the package manager for node) kept crashing and simply said killed. After much head scratching and a lot of googleing on node in general I narrowed the issue down to not having a swap partition. I have to admit I always assumed that there was a swap partition there. A good guide on how swap partitions work can be found here.

Setting up your swap partition

The first thing to do is to see if you have a swap partition

sudo swapon -s

If you don't see anything other than the headers in the list it means swap is not on your machine.

To create the swap file there are a couple of different ways I prefer the modern way as its far quicker. To begin create a 1GB swap file, I only had 512MB Ram if you have more you may wish to create a bigger swap file (double the RAM is a good guide):

sudo fallocate -l 1G /swapfile

You can check it worked with the following command:

ls -lh /swapfile

You will see the output similar to below:

-rw-r--r-- 1 root root 1.0G Sep 5 21:52 /swapfile

Next we need to ensure only root can write and read the swap file. Without doing this it's a massive security risk. To fix the problem we simply change the permissions from -rw-r--r-- to -rw-------by using the command below:

sudo chmod 600 /swapfile

Running ls -lh /swapfile again shoud with the exception of the date show the below:

-rw------- 1 root root 1.0G Sep 5 21:52 /swapfile

Now security is taken care of we can tell the system to make the actual swap space using the file:

sudo mkswap /swapfile

We can now turn the swap file on

sudo swapon -s

Finally we can make it permanent so it happens on every boot. To do this you need to edit a special partition file known as fstab:

sudo nano /etc/fstab

Insert the following at the bottom of the file on a new line

/swapfile none swap sw 0 0

Done! You can now install Ghost fresh or upgrade as usual and it should run fine. Remember to take a backup before you begin though.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus