Setting up a swap file on the 13-inch MaxBook Air / by Brian Lambert

When I built the MaxBook Air, I decided not to go for the more complex swap partition approach that some people espouse. I tried this in my previous installation and I felt that it made performing the partitioning in Mac OS X far more difficult for no real benefit.

Instead, I opted to build and use a swap file.

Here's how I did it.

First, you can check out your current swap situation using the free -m command. After installing Ubuntu GNOME 13.10 on my MaxBook Air, this is what it looked like (edited for clarity):

➜~ free -m
Swap: total: 0 used: 0 free: 0

As can be seen, swap is all zeros. Let's fix that.

First, we need to decide how much swap to use. This will depend on your needs, but generally, swap space equal in size to the physical RAM installed in the machine is a good rule of thumb. Since the MaxBook Air has 8 GB of physical RAM, that's the size of the swap file I will make.

First, allocate space for the swap file (8g is 8 GB).

sudo fallocate -l 8g /swapfile

Next, change the permissions on the swap file so it cannot be read by other users. (For my world this isn't strictly necessary - there are no other users - but it's best practice to do so.)

sudo chmod 600 /swapfile

Next, set-up the Linux swap area in the swap file:

sudo mkswap /swapfile

Next, add the swap file to the running system:

sudo swapon /swapfile

At this point, let's run free -m again to check on what we've done (edited for clarity):

➜~ free -m
Swap: total: 8191 used: 0 free: 8191

So, we now have a swap file!

We can also check on this using the System Monitor.

 8,0 GB Swap

If we stop here, the next time we boot the system it won't know about the swap file. We need to configure the OS to use this swap file. To do this, we must edit the /etc/fstab file as root.

I use Sublime Text so I used the following command:

sudo subl /etc/fstab

*Use your favorite editor here. gedit also works.

And add this line to the bottom of the file:

/swapfile none swap sw 0 0

Reboot your machine and use free -m and / or System Monitor to verify that your edit worked.

// EOF